org.apache.calcite.linq4j.tree.Expression Java Examples

The following examples show how to use org.apache.calcite.linq4j.tree.Expression. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OptimizerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testConditionalIfBoolTrueElse() {
  // if (bool) {return 1} else if (true) {return 2} else {return 3}
  Expression bool = Expressions.parameter(boolean.class, "bool");
  assertEquals(
      "{\n"
          + "  if (bool) {\n"
          + "    return 1;\n"
          + "  } else {\n"
          + "    return 2;\n"
          + "  }\n"
          + "}\n",
      optimize(
          Expressions.ifThenElse(bool,
              Expressions.return_(null, ONE),
              TRUE,
              Expressions.return_(null, TWO),
              Expressions.return_(null, THREE))));
}
 
Example #2
Source File: RexImpTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Expression implementResult(AggContext info,
    AggResultContext result) {
  WinAggResultContext winResult = (WinAggResultContext) result;

  List<RexNode> rexArgs = winResult.rexArguments();

  Expression tiles =
      winResult.rowTranslator(winResult.index()).translate(
          rexArgs.get(0), int.class);

  Expression ntile =
      Expressions.add(Expressions.constant(1),
          Expressions.divide(
              Expressions.multiply(
                  tiles,
                  Expressions.subtract(
                      winResult.index(), winResult.startIndex())),
              winResult.getPartitionRowCount()));

  return ntile;
}
 
Example #3
Source File: EnumUtils.java    From calcite with Apache License 2.0 6 votes vote down vote up
static List<Expression> fromInternal(Class<?>[] targetTypes,
    List<Expression> expressions) {
  final List<Expression> list = new ArrayList<>();
  if (targetTypes.length == expressions.size()) {
    for (int i = 0; i < expressions.size(); i++) {
      list.add(fromInternal(expressions.get(i), targetTypes[i]));
    }
  } else {
    int j = 0;
    for (int i = 0; i < expressions.size(); i++) {
      Class<?> type;
      if (!targetTypes[j].isArray()) {
        type = targetTypes[j];
        j++;
      } else {
        type = targetTypes[j].getComponentType();
      }
      list.add(fromInternal(expressions.get(i), type));
    }
  }
  return list;
}
 
Example #4
Source File: EnumerableTableScan.java    From calcite with Apache License 2.0 6 votes vote down vote up
private Expression toRows(PhysType physType, Expression expression) {
  if (physType.getFormat() == JavaRowFormat.SCALAR
      && Object[].class.isAssignableFrom(elementType)
      && getRowType().getFieldCount() == 1
      && (table.unwrap(ScannableTable.class) != null
          || table.unwrap(FilterableTable.class) != null
          || table.unwrap(ProjectableFilterableTable.class) != null)) {
    return Expressions.call(BuiltInMethod.SLICE0.method, expression);
  }
  JavaRowFormat oldFormat = format();
  if (physType.getFormat() == oldFormat && !hasCollectionField(rowType)) {
    return expression;
  }
  final ParameterExpression row_ =
      Expressions.parameter(elementType, "row");
  final int fieldCount = table.getRowType().getFieldCount();
  List<Expression> expressionList = new ArrayList<>(fieldCount);
  for (int i = 0; i < fieldCount; i++) {
    expressionList.add(fieldExpression(row_, i, physType, oldFormat));
  }
  return Expressions.call(expression,
      BuiltInMethod.SELECT.method,
      Expressions.lambda(Function1.class, physType.record(expressionList),
          row_));
}
 
Example #5
Source File: OptimizerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testConditionalIfBoolFalseTrue() {
  // if (bool) {1} else if (false) {2} if (true) {4} else {5}
  Expression bool = Expressions.parameter(boolean.class, "bool");
  assertEquals(
      "{\n"
          + "  if (bool) {\n"
          + "    return 1;\n"
          + "  } else {\n"
          + "    return 4;\n"
          + "  }\n"
          + "}\n",
      optimize(
          Expressions.ifThenElse(bool,
              Expressions.return_(null, ONE),
              FALSE,
              Expressions.return_(null, TWO),
              TRUE,
              Expressions.return_(null, FOUR),
              Expressions.return_(null, Expressions.constant(5)))));
}
 
Example #6
Source File: RexImpTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Multiplies an expression by a constant and divides by another constant,
 * optimizing appropriately.
 *
 * <p>For example, {@code multiplyDivide(e, 10, 1000)} returns
 * {@code e / 100}. */
public static Expression multiplyDivide(Expression e, BigDecimal multiplier,
    BigDecimal divider) {
  if (multiplier.equals(BigDecimal.ONE)) {
    if (divider.equals(BigDecimal.ONE)) {
      return e;
    }
    return Expressions.divide(e,
        Expressions.constant(divider.intValueExact()));
  }
  final BigDecimal x =
      multiplier.divide(divider, RoundingMode.UNNECESSARY);
  switch (x.compareTo(BigDecimal.ONE)) {
  case 0:
    return e;
  case 1:
    return Expressions.multiply(e, Expressions.constant(x.intValueExact()));
  case -1:
    return multiplyDivide(e, BigDecimal.ONE, x);
  default:
    throw new AssertionError();
  }
}
 
Example #7
Source File: RexImpTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
private Expression unboxExpression(final Expression argValue) {
  Primitive fromBox = Primitive.ofBox(argValue.getType());
  if (fromBox == null || fromBox == Primitive.VOID) {
    return argValue;
  }
  // Optimization: for "long x";
  // "Long.valueOf(x)" generates "x"
  if (argValue instanceof MethodCallExpression) {
    MethodCallExpression mce = (MethodCallExpression) argValue;
    if (mce.method.getName().equals("valueOf") && mce.expressions.size() == 1) {
      Expression originArg = mce.expressions.get(0);
      if (Primitive.of(originArg.type) == fromBox) {
        return originArg;
      }
    }
  }
  return NullAs.NOT_POSSIBLE.handle(argValue);
}
 
Example #8
Source File: EnumerableMatch.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public Expression field(BlockBuilder list, int index,
    Type storageType) {
  if (this.index == null) {
    return generator.apply(this.row).field(list, index, storageType);
  }

  return Expressions.condition(
      Expressions.greaterThanOrEqual(this.index, Expressions.constant(0)),
      generator.apply(
          EnumUtils.convert(
              Expressions.call(this.passedRows,
                  BuiltInMethod.LIST_GET.method, this.index),
              physType.getJavaRowType()))
          .field(list, index, storageType),
      Expressions.constant(null));
}
 
Example #9
Source File: Schemas.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Returns the expression for a sub-schema. */
public static Expression subSchemaExpression(SchemaPlus schema, String name,
    Class type) {
  // (Type) schemaExpression.getSubSchema("name")
  final Expression schemaExpression = expression(schema);
  Expression call =
      Expressions.call(
          schemaExpression,
          BuiltInMethod.SCHEMA_GET_SUB_SCHEMA.method,
          Expressions.constant(name));
  //CHECKSTYLE: IGNORE 2
  //noinspection unchecked
  if (false && type != null && !type.isAssignableFrom(Schema.class)) {
    return unwrap(call, type);
  }
  return call;
}
 
Example #10
Source File: RexImpTable.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public Expression implement(RexToLixTranslator translator,
    Expression inputEnumerable, RexCall call, PhysType inputPhysType, PhysType outputPhysType) {
  RexCall timestampDescriptor = (RexCall) call.getOperands().get(0);
  RexCall keyDescriptor = (RexCall) call.getOperands().get(1);
  Expression gapInterval = translator.translate(call.getOperands().get(2));

  List<Expression> translatedOperands = new ArrayList<>();
  Expression wmColIndexExpr =
      Expressions.constant(((RexInputRef) timestampDescriptor.getOperands().get(0)).getIndex());
  Expression keyColIndexExpr =
      Expressions.constant(((RexInputRef) keyDescriptor.getOperands().get(0)).getIndex());
  translatedOperands.add(wmColIndexExpr);
  translatedOperands.add(keyColIndexExpr);
  translatedOperands.add(gapInterval);

  return Expressions.call(BuiltInMethod.SESSIONIZATION.method,
      Expressions.list(
          Expressions.call(inputEnumerable, BuiltInMethod.ENUMERABLE_ENUMERATOR.method),
          translatedOperands.get(0),
          translatedOperands.get(1),
          translatedOperands.get(2)));
}
 
Example #11
Source File: InlinerTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testAssignInConditionMultipleUsage() {
  // int t;
  // return (t = 1) != a ? t : c
  final BlockBuilder builder = new BlockBuilder(true);
  final ParameterExpression t = Expressions.parameter(int.class, "t");

  builder.add(Expressions.declare(0, t, null));

  Expression v = builder.append("v",
      Expressions.makeTernary(ExpressionType.Conditional,
          Expressions.makeBinary(ExpressionType.NotEqual,
              Expressions.assign(t, Expressions.constant(1)),
              Expressions.parameter(int.class, "a")),
          t,
          Expressions.parameter(int.class, "c")));
  builder.add(Expressions.return_(null, v));
  assertEquals(
      "{\n"
          + "  int t;\n"
          + "  return (t = 1) != a ? t : c;\n"
          + "}\n",
      Expressions.toString(builder.toBlock()));
}
 
Example #12
Source File: EnumUtils.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static List<? extends Expression> matchMethodParameterTypes(boolean varArgs,
    Class[] parameterTypes, List<? extends Expression> arguments) {
  if ((varArgs  && arguments.size() < parameterTypes.length - 1)
      || (!varArgs && arguments.size() != parameterTypes.length)) {
    return null;
  }
  final List<Expression> typeMatchedArguments = new ArrayList<>();
  for (int i = 0; i < arguments.size(); i++) {
    Class parameterType =
        !varArgs || i < parameterTypes.length - 1
            ? parameterTypes[i]
            : Object.class;
    final Expression typeMatchedArgument =
        matchMethodParameterType(arguments.get(i), parameterType);
    if (typeMatchedArgument == null) {
      return null;
    }
    typeMatchedArguments.add(typeMatchedArgument);
  }
  return typeMatchedArguments;
}
 
Example #13
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override Expression implementSafe(RexToLixTranslator translator,
    RexCall call, List<Expression> argValueList) {
  final Expression expression;
  Class clazz = method.getDeclaringClass();
  if (Modifier.isStatic(method.getModifiers())) {
    expression = EnumUtils.call(clazz, method.getName(), argValueList);
  } else {
    expression = EnumUtils.call(clazz, method.getName(),
        Util.skip(argValueList, 1), argValueList.get(0));
  }
  return expression;
}
 
Example #14
Source File: RelDataTypeHolder.java    From marble with Apache License 2.0 5 votes vote down vote up
public static Expression generateExpressionWithConstantValue(RelDataType relDataType,
    Expression valueExpression) {
  return Expressions.new_(RelDataTypeHolder.class,
      new ConstantExpression(SqlTypeName.class,
          relDataType.getSqlTypeName()),
      new ConstantExpression(boolean.class, true),
      valueExpression);
}
 
Example #15
Source File: DeterministicTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private boolean isAtomic(Expression e) {
  /** Subclass to make a protected method public. */
  class MyDeterministicCodeOptimizer extends DeterministicCodeOptimizer {
    MyDeterministicCodeOptimizer() {
      super(ClassDeclarationFinder.create());
    }

    @Override public boolean isConstant(Expression expression) {
      return super.isConstant(expression);
    }
  }
  return new MyDeterministicCodeOptimizer().isConstant(e);
}
 
Example #16
Source File: RexExecutorImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static String compile(RexBuilder rexBuilder, List<RexNode> constExps,
    RexToLixTranslator.InputGetter getter, RelDataType rowType) {
  final RexProgramBuilder programBuilder =
      new RexProgramBuilder(rowType, rexBuilder);
  for (RexNode node : constExps) {
    programBuilder.addProject(
        node, "c" + programBuilder.getProjectList().size());
  }
  final JavaTypeFactoryImpl javaTypeFactory =
      new JavaTypeFactoryImpl(rexBuilder.getTypeFactory().getTypeSystem());
  final BlockBuilder blockBuilder = new BlockBuilder();
  final ParameterExpression root0_ =
      Expressions.parameter(Object.class, "root0");
  final ParameterExpression root_ = DataContext.ROOT;
  blockBuilder.add(
      Expressions.declare(
          Modifier.FINAL, root_,
          Expressions.convert_(root0_, DataContext.class)));
  final SqlConformance conformance = SqlConformanceEnum.DEFAULT;
  final RexProgram program = programBuilder.getProgram();
  final List<Expression> expressions =
      RexToLixTranslator.translateProjects(program, javaTypeFactory,
          conformance, blockBuilder, null, root_, getter, null);
  blockBuilder.add(
      Expressions.return_(null,
          Expressions.newArrayInit(Object[].class, expressions)));
  final MethodDeclaration methodDecl =
      Expressions.methodDecl(Modifier.PUBLIC, Object[].class,
          BuiltInMethod.FUNCTION1_APPLY.method.getName(),
          ImmutableList.of(root0_), blockBuilder.toBlock());
  String code = Expressions.toString(methodDecl);
  if (CalciteSystemProperty.DEBUG.value()) {
    Util.debugCode(System.out, code);
  }
  return code;
}
 
Example #17
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Figures out conditional expression according to NullPolicy. */
Expression getCondition(final List<Expression> argIsNullList) {
  if (argIsNullList.size() == 0
      || nullPolicy == null
      || nullPolicy == NullPolicy.NONE) {
    return FALSE_EXPR;
  }
  if (nullPolicy == NullPolicy.ARG0) {
    return argIsNullList.get(0);
  }
  return Expressions.foldOr(argIsNullList);
}
 
Example #18
Source File: DataSourceSchema.java    From quark with Apache License 2.0 5 votes vote down vote up
@Override
public Expression getExpression(SchemaPlus parentSchema,
                                String name) {
  return Expressions.call(
      DataContext.ROOT,
      BuiltInMethod.DATA_CONTEXT_GET_ROOT_SCHEMA.method);
}
 
Example #19
Source File: KylinEnumerableUnion.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    Expression unionExp = null;
    for (Ord<RelNode> ord : Ord.zip(inputs)) {
        EnumerableRel input = (EnumerableRel) ord.e;
        final Result result = implementor.visitChild(this, ord.i, input, pref);
        Expression childExp =
                builder.append(
                        "child" + ord.i,
                        result.block);

        if (unionExp == null) {
            unionExp = childExp;
        } else {
            unionExp = createUnionExpression(unionExp, childExp, result.format == JavaRowFormat.ARRAY);
        }
    }

    builder.add(unionExp);
    final PhysType physType =
            PhysTypeImpl.of(
                    implementor.getTypeFactory(),
                    getRowType(),
                    pref.prefer(JavaRowFormat.CUSTOM));
    return implementor.result(physType, builder.toBlock());
}
 
Example #20
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static RexCallImplementor wrapAsRexCallImplementor(
    final CallImplementor implementor) {
  return new AbstractRexCallImplementor(NullPolicy.NONE, false) {
    @Override String getVariableName() {
      return "udf";
    }

    @Override Expression implementSafe(RexToLixTranslator translator,
        RexCall call, List<Expression> argValueList) {
      return implementor.implement(translator, call, RexImpTable.NullAs.NULL);
    }
  };
}
 
Example #21
Source File: EnumUtilsTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testDateTypeToInnerTypeConvert() {
  // java.sql.Date x;
  final ParameterExpression date =
      Expressions.parameter(0, java.sql.Date.class, "x");
  final Expression dateToInt =
      EnumUtils.convert(date, int.class);
  final Expression dateToInteger =
      EnumUtils.convert(date, Integer.class);
  assertThat(Expressions.toString(dateToInt),
      is("org.apache.calcite.runtime.SqlFunctions.toInt(x)"));
  assertThat(Expressions.toString(dateToInteger),
      is("org.apache.calcite.runtime.SqlFunctions.toIntOptional(x)"));

  // java.sql.Time x;
  final ParameterExpression time =
      Expressions.parameter(0, java.sql.Time.class, "x");
  final Expression timeToInt =
      EnumUtils.convert(time, int.class);
  final Expression timeToInteger =
      EnumUtils.convert(time, Integer.class);
  assertThat(Expressions.toString(timeToInt),
      is("org.apache.calcite.runtime.SqlFunctions.toInt(x)"));
  assertThat(Expressions.toString(timeToInteger),
      is("org.apache.calcite.runtime.SqlFunctions.toIntOptional(x)"));

  // java.sql.TimeStamp x;
  final ParameterExpression timestamp =
      Expressions.parameter(0, java.sql.Timestamp.class, "x");
  final Expression timeStampToLongPrimitive =
      EnumUtils.convert(timestamp, long.class);
  final Expression timeStampToLong =
      EnumUtils.convert(timestamp, Long.class);
  assertThat(Expressions.toString(timeStampToLongPrimitive),
      is("org.apache.calcite.runtime.SqlFunctions.toLong(x)"));
  assertThat(Expressions.toString(timeStampToLong),
      is("org.apache.calcite.runtime.SqlFunctions.toLongOptional(x)"));
}
 
Example #22
Source File: RexToLixTranslator.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Visit {@code RexLiteral}. If it has never been visited before,
 * {@code RexToLixTranslator} will generate two lines of code. For example,
 * when visiting a primitive int (10), the generated code snippet is:
 * {@code
 *   final int literal_value = 10;
 *   final boolean literal_isNull = false;
 * }
 */
@Override public Result visitLiteral(RexLiteral literal) {
  // If the RexLiteral has been visited already, just return the result
  if (rexResultMap.containsKey(literal)) {
    return rexResultMap.get(literal);
  }
  // Generate one line of code for the value of RexLiteral, e.g.,
  // "final int literal_value = 10;"
  final Expression valueExpression = literal.isNull()
      // Note: even for null literal, we can't loss its type information
      ? getTypedNullLiteral(literal)
      : translateLiteral(literal, literal.getType(),
          typeFactory, RexImpTable.NullAs.NOT_POSSIBLE);
  final ParameterExpression valueVariable =
      Expressions.parameter(valueExpression.getType(),
          list.newName("literal_value"));
  list.add(Expressions.declare(Modifier.FINAL, valueVariable, valueExpression));

  // Generate one line of code to check whether RexLiteral is null, e.g.,
  // "final boolean literal_isNull = false;"
  final Expression isNullExpression =
      literal.isNull() ? RexImpTable.TRUE_EXPR : RexImpTable.FALSE_EXPR;
  final ParameterExpression isNullVariable = Expressions.parameter(
      Boolean.TYPE, list.newName("literal_isNull"));
  list.add(Expressions.declare(Modifier.FINAL, isNullVariable, isNullExpression));

  // Maintain the map from valueVariable (ParameterExpression) to real Expression
  literalMap.put(valueVariable, valueExpression);
  final Result result = new Result(isNullVariable, valueVariable);
  // Cache RexLiteral's result
  rexResultMap.put(literal, result);
  return result;
}
 
Example #23
Source File: EnumerableTableFunctionScan.java    From calcite with Apache License 2.0 5 votes vote down vote up
private Result tvfImplementorBasedImplement(
    EnumerableRelImplementor implementor, Prefer pref) {
  final JavaTypeFactory typeFactory = implementor.getTypeFactory();
  final BlockBuilder builder = new BlockBuilder();
  final EnumerableRel child = (EnumerableRel) getInputs().get(0);
  final Result result =
      implementor.visitChild(this, 0, child, pref);
  final PhysType physType = PhysTypeImpl.of(
      typeFactory, getRowType(), pref.prefer(result.format));
  final Expression inputEnumerable = builder.append(
      "_input", result.block, false);
  final SqlConformance conformance =
      (SqlConformance) implementor.map.getOrDefault("_conformance",
          SqlConformanceEnum.DEFAULT);

  builder.add(
      RexToLixTranslator.translateTableFunction(
          typeFactory,
          conformance,
          builder,
          DataContext.ROOT,
          (RexCall) getCall(),
          inputEnumerable,
          result.physType,
          physType
      )
  );

  return implementor.result(physType, builder.toBlock());
}
 
Example #24
Source File: BlockBuilderTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
private BlockBuilder appendBlockWithSameVariable(
    Expression initializer1, Expression initializer2) {
  BlockBuilder outer = new BlockBuilder();
  ParameterExpression outerX = Expressions.parameter(int.class, "x");
  outer.add(Expressions.declare(0, outerX, initializer1));
  outer.add(Expressions.statement(Expressions.assign(outerX, Expressions.constant(1))));

  BlockBuilder inner = new BlockBuilder();
  ParameterExpression innerX = Expressions.parameter(int.class, "x");
  inner.add(Expressions.declare(0, innerX, initializer2));
  inner.add(Expressions.statement(Expressions.assign(innerX, Expressions.constant(42))));
  inner.add(Expressions.return_(null, innerX));
  outer.append("x", inner.toBlock());
  return outer;
}
 
Example #25
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static Expression mod(Expression operand, long factor) {
  if (factor == 1L) {
    return operand;
  } else {
    return Expressions.call(BuiltInMethod.FLOOR_MOD.method,
        operand, Expressions.constant(factor));
  }
}
 
Example #26
Source File: PhysTypeImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Expression convertTo(Expression exp, JavaRowFormat targetFormat) {
  if (format == targetFormat) {
    return exp;
  }
  final ParameterExpression o_ =
      Expressions.parameter(javaRowClass, "o");
  final int fieldCount = rowType.getFieldCount();
  // The conversion must be strict so optimizations of the targetFormat should not be performed
  // by the code that follows. If necessary the target format can be optimized before calling
  // this method.
  PhysType targetPhysType = PhysTypeImpl.of(typeFactory, rowType, targetFormat, false);
  final Expression selector = Expressions.lambda(Function1.class,
      targetPhysType.record(fieldReferences(o_, Util.range(fieldCount))), o_);
  return Expressions.call(exp, BuiltInMethod.SELECT.method, selector);
}
 
Example #27
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Expression implementResult(AggContext info,
    AggResultContext result) {
  final List<Integer> keys;
  switch (info.aggregation().kind) {
  case GROUPING: // "GROUPING(e, ...)", also "GROUPING_ID(e, ...)"
    keys = result.call().getArgList();
    break;
  default:
    throw new AssertionError();
  }
  Expression e = null;
  if (info.groupSets().size() > 1) {
    final List<Integer> keyOrdinals = info.keyOrdinals();
    long x = 1L << (keys.size() - 1);
    for (int k : keys) {
      final int i = keyOrdinals.indexOf(k);
      assert i >= 0;
      final Expression e2 =
          Expressions.condition(result.keyField(keyOrdinals.size() + i),
              Expressions.constant(x),
              Expressions.constant(0L));
      if (e == null) {
        e = e2;
      } else {
        e = Expressions.add(e, e2);
      }
      x >>= 1;
    }
  }
  return e != null ? e : Expressions.constant(0, info.returnType());
}
 
Example #28
Source File: RexImpTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Expression implementResult(AggContext info,
    AggResultContext result) {
  WinAggResultContext winResult = (WinAggResultContext) result;

  return Expressions.condition(winResult.hasRows(),
      winResult.rowTranslator(
          winResult.computeIndex(Expressions.constant(0), seekType))
          .translate(winResult.rexArguments().get(0), info.returnType()),
      getDefaultValue(info.returnType()));
}
 
Example #29
Source File: EnumUtils.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Handle decimal type specifically with explicit type conversion
 */
private static Expression convertAssignableType(
    Expression argument, Type targetType) {
  if (targetType != BigDecimal.class) {
    return argument;
  }
  return convert(argument, targetType);
}
 
Example #30
Source File: ListTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a ListTable. */
ListTable(
    Type elementType,
    RelProtoDataType protoRowType,
    Expression expression,
    List list) {
  super(elementType);
  this.protoRowType = protoRowType;
  this.expression = expression;
  this.list = list;
}