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

The following examples show how to use org.apache.calcite.linq4j.tree.Expression. These examples are extracted from open source projects. 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 Project: calcite   Source File: InlinerTest.java    License: 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 2
Source Project: calcite   Source File: RexImpTable.java    License: 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 3
Source Project: calcite   Source File: EnumerableMatch.java    License: 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 4
Source Project: calcite   Source File: RexImpTable.java    License: 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 5
Source Project: calcite   Source File: OptimizerTest.java    License: 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 Project: calcite   Source File: EnumUtils.java    License: 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 7
Source Project: calcite   Source File: RexImpTable.java    License: 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 8
Source Project: calcite   Source File: EnumerableTableScan.java    License: 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 9
Source Project: calcite   Source File: RexImpTable.java    License: 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 10
Source Project: calcite   Source File: Schemas.java    License: 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 11
Source Project: calcite   Source File: EnumUtils.java    License: 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 12
Source Project: calcite   Source File: OptimizerTest.java    License: 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 13
Source Project: calcite   Source File: RexToLixTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns the value of a literal. */
Object getLiteralValue(Expression expr) {
  if (expr instanceof ParameterExpression) {
    final Expression constantExpr = literalMap.get(expr);
    return getLiteralValue(constantExpr);
  }
  if (expr instanceof ConstantExpression) {
    return ((ConstantExpression) expr).value;
  }
  return null;
}
 
Example 14
Source Project: calcite   Source File: RexToLixTranslator.java    License: Apache License 2.0 5 votes vote down vote up
public List<Expression> translateList(
    List<RexNode> operandList,
    RexImpTable.NullAs nullAs,
    List<? extends Type> storageTypes) {
  final List<Expression> list = new ArrayList<>();
  for (Pair<RexNode, ? extends Type> e : Pair.zip(operandList, storageTypes)) {
    list.add(translate(e.left, nullAs, e.right));
  }
  return list;
}
 
Example 15
Source Project: calcite   Source File: EnumUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test void testTypeConvertToString() {
  // Constant Expression: "null"
  final ConstantExpression nullLiteral1 = Expressions.constant(null);
  // Constant Expression: "(Object) null"
  final ConstantExpression nullLiteral2 = Expressions.constant(null, Object.class);
  final Expression e1 = EnumUtils.convert(nullLiteral1, String.class);
  final Expression e2 = EnumUtils.convert(nullLiteral2, String.class);
  assertThat(Expressions.toString(e1), is("(String) null"));
  assertThat(Expressions.toString(e2), is("(String) (Object) null"));
}
 
Example 16
Source Project: marble   Source File: RelDataTypeHolder.java    License: 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 17
Source Project: calcite   Source File: RexToLixTranslator.java    License: Apache License 2.0 5 votes vote down vote up
public static Expression translateTableFunction(JavaTypeFactory typeFactory,
    SqlConformance conformance, BlockBuilder blockBuilder,
    Expression root, RexCall rexCall, Expression inputEnumerable,
    PhysType inputPhysType, PhysType outputPhysType) {
  return new RexToLixTranslator(null, typeFactory, root, null,
      blockBuilder, new RexBuilder(typeFactory), conformance, null)
      .translateTableFunction(rexCall, inputEnumerable, inputPhysType, outputPhysType);
}
 
Example 18
Source Project: calcite   Source File: StrictAggImplementor.java    License: Apache License 2.0 5 votes vote down vote up
protected void implementNotNullReset(AggContext info,
    AggResetContext reset) {
  BlockBuilder block = reset.currentBlock();
  List<Expression> accumulator = reset.accumulator();
  for (int i = 0; i < getStateSize(); i++) {
    Expression exp = accumulator.get(i);
    block.add(
        Expressions.statement(
            Expressions.assign(exp,
                RexImpTable.getDefaultValue(exp.getType()))));
  }
}
 
Example 19
Source Project: kylin-on-parquet-v2   Source File: KylinEnumerableUnion.java    License: 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 Project: calcite   Source File: CalcitePrepareImpl.java    License: Apache License 2.0 5 votes vote down vote up
private List<RexNode> toRex(List<Expression> expressions) {
  final List<RexNode> list = new ArrayList<>();
  for (Expression expression : expressions) {
    list.add(toRex(expression));
  }
  return list;
}
 
Example 21
Source Project: calcite   Source File: DeterministicTest.java    License: 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 22
Source Project: quark   Source File: DataSourceSchema.java    License: 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 23
Source Project: calcite   Source File: RexExecutorImpl.java    License: 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 24
Source Project: kylin   Source File: KylinEnumerableUnion.java    License: 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 25
Source Project: calcite   Source File: RexImpTable.java    License: 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 26
Source Project: calcite   Source File: EnumUtilsTest.java    License: 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 27
Source Project: calcite   Source File: RexToLixTranslator.java    License: 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 28
Source Project: calcite   Source File: RexImpTable.java    License: 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 29
Source Project: calcite   Source File: BlockBuilderTest.java    License: 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 30
Source Project: calcite   Source File: RexImpTable.java    License: 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()));
}