private static List<Expression> simpleList(BlockExpression expression) { Expression simple = Blocks.simple(expression); if (simple instanceof NewExpression) { NewExpression newExpression = (NewExpression) simple; return newExpression.arguments; } else { return Collections.singletonList(simple); } }
@Override protected PreparedExecution implement( RelDataType rowType, RelNode rootRel, SqlKind sqlKind, ClassDeclaration decl, Argument[] args) { RelDataType resultType = rootRel.getRowType(); boolean isDml = sqlKind.belongsTo(SqlKind.DML); javaCompiler = createCompiler(); EnumerableRelImplementor relImplementor = getRelImplementor(rootRel.getCluster().getRexBuilder()); BlockExpression expr = relImplementor.implementRoot((EnumerableRel) rootRel); ParameterExpression root0 = Expressions.parameter(DataContext.class, "root0"); String s = Expressions.toString( Blocks.create( Expressions.declare( Modifier.FINAL, (ParameterExpression) schema.getExpression(), root0), expr), false); final Executable executable; try { executable = (Executable) ExpressionEvaluator.createFastScriptEvaluator( s, Executable.class, new String[] {root0.name}); } catch (Exception e) { throw Helper.INSTANCE.wrap("Error while compiling generated Java code:\n" + s, e); } if (timingTracer != null) { timingTracer.traceTime("end codegen"); } if (timingTracer != null) { timingTracer.traceTime("end compilation"); } return new PreparedExecution( null, rootRel, resultType, isDml, mapTableModOp(isDml, sqlKind), null) { public Object execute() { return executable.execute(schema); } }; }
public RexNode toRex(BlockExpression expression) { return toRex(Blocks.simple(expression)); }