public DeclarationStatement visit(DeclarationStatement declarationStatement, Expression initializer) { return declarationStatement.initializer == initializer ? declarationStatement : Expressions.declare( declarationStatement.modifiers, declarationStatement.parameter, initializer); }
/** * Creates an expression that declares and initializes a variable. No * type is required; it is assumed that the variable is the same type as * the initializer. You can retrieve the {@link ParameterExpression} from * the {@link DeclarationStatement#parameter} field of the result. */ public static DeclarationStatement declare(int modifiers, String name, Expression initializer) { assert initializer != null : "empty initializer for variable declaration with name '" + name + "', modifiers " + modifiers + ". Please use declare(int, ParameterExpression, initializer) instead"; return declare(modifiers, parameter(initializer.getType(), name), initializer); }
private Expression append_(String name, Expression expression, boolean optimize) { if (isSimpleExpression(expression)) { // already simple; no need to declare a variable or // even to evaluate the expression return expression; } if (optimizing && optimize) { DeclarationStatement decl = getComputedExpression(expression); if (decl != null) { return decl.parameter; } } DeclarationStatement declare = Expressions.declare(Modifier.FINAL, newName(name, optimize), expression); add(declare); return declare.parameter; }
list.add(Expressions.declare(Modifier.FINAL, unboxed, nullHandled));
list.add(Expressions.declare(Modifier.FINAL, unboxed, nullHandled));
builder.newName("sourceSorters")); builder.add( Expressions.declare(0, pe, Expressions.new_(LinkedList.class))); Expressions.declare(0, lambdaFactory, Expressions.new_( BuiltInMethod.ORDERED_AGGREGATE_LAMBDA_FACTORY.constructor, builder.newName("accumulatorAdders")); builder.add( Expressions.declare(0, pe, Expressions.new_(LinkedList.class))); Expressions.declare(0, lambdaFactory, Expressions.new_( BuiltInMethod.SEQUENCED_ADDER_AGGREGATE_LAMBDA_FACTORY.constructor,
input -> Expressions.declare(Modifier.FINAL, input, Expressions.convert_( Expressions.call(DataContext.ROOT,
input -> Expressions.declare(Modifier.FINAL, input, Expressions.convert_( Expressions.call(DataContext.ROOT,
private void declareParentAccumulator(List<Expression> initExpressions, BlockBuilder initBlock, PhysType accPhysType) { if (accPhysType.getJavaRowType() instanceof JavaTypeFactoryImpl.SyntheticRecordType) { // We have to initialize the SyntheticRecordType instance this way, to // avoid using a class constructor with too many parameters. final JavaTypeFactoryImpl.SyntheticRecordType synType = (JavaTypeFactoryImpl.SyntheticRecordType) accPhysType.getJavaRowType(); final ParameterExpression record0_ = Expressions.parameter(accPhysType.getJavaRowType(), "record0"); initBlock.add(Expressions.declare(0, record0_, null)); initBlock.add( Expressions.statement( Expressions.assign(record0_, Expressions.new_(accPhysType.getJavaRowType())))); List<Types.RecordField> fieldList = synType.getRecordFields(); for (int i = 0; i < initExpressions.size(); i++) { Expression right = initExpressions.get(i); initBlock.add( Expressions.statement( Expressions.assign( Expressions.field(record0_, fieldList.get(i)), right))); } initBlock.add(record0_); } else { initBlock.add(accPhysType.record(initExpressions)); } }
final ParameterExpression root_ = DataContext.ROOT; blockBuilder.add( Expressions.declare( Modifier.FINAL, root_, Expressions.convert_(root0_, DataContext.class)));
final ParameterExpression root_ = DataContext.ROOT; blockBuilder.add( Expressions.declare( Modifier.FINAL, root_, Expressions.convert_(root0_, DataContext.class)));
nonNull, RexImpTable.getDefaultValue(res.getType())); result.currentBlock().add(Expressions.declare(0, res, null)); result.currentBlock().add( Expressions.ifThenElse(seenNotNullRows,
: getDefaultValue(res.type); result.currentBlock().add(Expressions.declare(0, res, null)); result.currentBlock().add( Expressions.ifThenElse(rowInRange, thenBranch,
: getDefaultValue(res.type); result.currentBlock().add(Expressions.declare(0, res, null)); result.currentBlock().add( Expressions.ifThenElse(rowInRange, thenBranch,
nonNull, RexImpTable.getDefaultValue(res.getType())); result.currentBlock().add(Expressions.declare(0, res, null)); result.currentBlock().add( Expressions.ifThenElse(seenNotNullRows,
public Expression implementResult(AggContext info, AggResultContext result) { WinAggResultContext winResult = (WinAggResultContext) result; List<RexNode> rexArgs = winResult.rexArguments(); ParameterExpression res = Expressions.parameter(0, info.returnType(), result.currentBlock().newName("nth")); RexToLixTranslator currentRowTranslator = winResult.rowTranslator( winResult.computeIndex(Expressions.constant(0), SeekType.START)); Expression dstIndex = winResult.computeIndex( Expressions.subtract( currentRowTranslator.translate(rexArgs.get(1), int.class), Expressions.constant(1)), SeekType.START); Expression rowInRange = winResult.rowInPartition(dstIndex); BlockBuilder thenBlock = result.nestBlock(); Expression nthValue = winResult.rowTranslator(dstIndex) .translate(rexArgs.get(0), res.type); thenBlock.add(Expressions.statement(Expressions.assign(res, nthValue))); result.exitBlock(); BlockStatement thenBranch = thenBlock.toBlock(); Expression defaultValue = getDefaultValue(res.type); result.currentBlock().add(Expressions.declare(0, res, null)); result.currentBlock().add( Expressions.ifThenElse(rowInRange, thenBranch, Expressions.statement(Expressions.assign(res, defaultValue)))); return res; } }
public Expression implementResult(AggContext info, AggResultContext result) { WinAggResultContext winResult = (WinAggResultContext) result; List<RexNode> rexArgs = winResult.rexArguments(); ParameterExpression res = Expressions.parameter(0, info.returnType(), result.currentBlock().newName("nth")); RexToLixTranslator currentRowTranslator = winResult.rowTranslator( winResult.computeIndex(Expressions.constant(0), SeekType.START)); Expression dstIndex = winResult.computeIndex( Expressions.subtract( currentRowTranslator.translate(rexArgs.get(1), int.class), Expressions.constant(1)), SeekType.START); Expression rowInRange = winResult.rowInPartition(dstIndex); BlockBuilder thenBlock = result.nestBlock(); Expression nthValue = winResult.rowTranslator(dstIndex) .translate(rexArgs.get(0), res.type); thenBlock.add(Expressions.statement(Expressions.assign(res, nthValue))); result.exitBlock(); BlockStatement thenBranch = thenBlock.toBlock(); Expression defaultValue = getDefaultValue(res.type); result.currentBlock().add(Expressions.declare(0, res, null)); result.currentBlock().add( Expressions.ifThenElse(rowInRange, thenBranch, Expressions.statement(Expressions.assign(res, defaultValue)))); return res; } }
Expressions.parameter(int.class, "c"); final int mod = collations.size() == 1 ? Modifier.FINAL : 0; body.add(Expressions.declare(mod, parameterC, null)); for (RelFieldCollation collation : collations) { final int index = collation.getFieldIndex();