Search in sources :

Example 1 with MethodDeclaration

use of org.apache.calcite.linq4j.tree.MethodDeclaration in project calcite by apache.

the class RexExecutorImpl method compile.

private 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 List<Expression> expressions = RexToLixTranslator.translateProjects(programBuilder.getProgram(), javaTypeFactory, 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 (CalcitePrepareImpl.DEBUG) {
        Util.debugCode(System.out, code);
    }
    return code;
}
Also used : MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) IndexExpression(org.apache.calcite.linq4j.tree.IndexExpression) Expression(org.apache.calcite.linq4j.tree.Expression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) MethodDeclaration(org.apache.calcite.linq4j.tree.MethodDeclaration) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Aggregations

JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)1 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)1 Expression (org.apache.calcite.linq4j.tree.Expression)1 IndexExpression (org.apache.calcite.linq4j.tree.IndexExpression)1 MethodCallExpression (org.apache.calcite.linq4j.tree.MethodCallExpression)1 MethodDeclaration (org.apache.calcite.linq4j.tree.MethodDeclaration)1 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)1