Search in sources :

Example 71 with Expression

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project calcite by apache.

the class EnumerableRelImplementor method implementRoot.

public ClassDeclaration implementRoot(EnumerableRel rootRel, EnumerableRel.Prefer prefer) {
    EnumerableRel.Result result = rootRel.implement(this, prefer);
    switch(prefer) {
        case ARRAY:
            if (result.physType.getFormat() == JavaRowFormat.ARRAY && rootRel.getRowType().getFieldCount() == 1) {
                BlockBuilder bb = new BlockBuilder();
                Expression e = null;
                for (Statement statement : result.block.statements) {
                    if (statement instanceof GotoStatement) {
                        e = bb.append("v", ((GotoStatement) statement).expression);
                    } else {
                        bb.add(statement);
                    }
                }
                if (e != null) {
                    bb.add(Expressions.return_(null, Expressions.call(null, BuiltInMethod.SLICE0.method, e)));
                }
                result = new EnumerableRel.Result(bb.toBlock(), result.physType, JavaRowFormat.SCALAR);
            }
    }
    final List<MemberDeclaration> memberDeclarations = new ArrayList<>();
    new TypeRegistrar(memberDeclarations).go(result);
    // The following is a workaround to
    // http://jira.codehaus.org/browse/JANINO-169. Otherwise we'd remove the
    // member variable, rename the "root0" parameter as "root", and reference it
    // directly from inner classes.
    final ParameterExpression root0_ = Expressions.parameter(Modifier.FINAL, DataContext.class, "root0");
    // This creates the following code
    // final Integer v1stashed = (Integer) root.get("v1stashed")
    // It is convenient for passing non-literal "compile-time" constants
    final Collection<Statement> stashed = Collections2.transform(stashedParameters.values(), new Function<ParameterExpression, Statement>() {

        public Statement apply(ParameterExpression input) {
            return Expressions.declare(Modifier.FINAL, input, Expressions.convert_(Expressions.call(DataContext.ROOT, BuiltInMethod.DATA_CONTEXT_GET.method, Expressions.constant(input.name)), input.type));
        }
    });
    final BlockStatement block = Expressions.block(Iterables.concat(ImmutableList.of(Expressions.statement(Expressions.assign(DataContext.ROOT, root0_))), stashed, result.block.statements));
    memberDeclarations.add(Expressions.fieldDecl(0, DataContext.ROOT, null));
    memberDeclarations.add(Expressions.methodDecl(Modifier.PUBLIC, Enumerable.class, BuiltInMethod.BINDABLE_BIND.method.getName(), Expressions.list(root0_), block));
    memberDeclarations.add(Expressions.methodDecl(Modifier.PUBLIC, Class.class, BuiltInMethod.TYPED_GET_ELEMENT_TYPE.method.getName(), Collections.<ParameterExpression>emptyList(), Blocks.toFunctionBlock(Expressions.return_(null, Expressions.constant(result.physType.getJavaRowType())))));
    return Expressions.classDecl(Modifier.PUBLIC, "Baz", null, Collections.<Type>singletonList(Bindable.class), memberDeclarations);
}
Also used : GotoStatement(org.apache.calcite.linq4j.tree.GotoStatement) Statement(org.apache.calcite.linq4j.tree.Statement) BlockStatement(org.apache.calcite.linq4j.tree.BlockStatement) ConditionalStatement(org.apache.calcite.linq4j.tree.ConditionalStatement) MemberDeclaration(org.apache.calcite.linq4j.tree.MemberDeclaration) ArrayList(java.util.ArrayList) Bindable(org.apache.calcite.runtime.Bindable) BlockStatement(org.apache.calcite.linq4j.tree.BlockStatement) GotoStatement(org.apache.calcite.linq4j.tree.GotoStatement) NewArrayExpression(org.apache.calcite.linq4j.tree.NewArrayExpression) Expression(org.apache.calcite.linq4j.tree.Expression) NewExpression(org.apache.calcite.linq4j.tree.NewExpression) MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) ConstantExpression(org.apache.calcite.linq4j.tree.ConstantExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) Enumerable(org.apache.calcite.linq4j.Enumerable) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 72 with Expression

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project calcite by apache.

the class EnumerableSemiJoin method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    BlockBuilder builder = new BlockBuilder();
    final Result leftResult = implementor.visitChild(this, 0, (EnumerableRel) left, pref);
    Expression leftExpression = builder.append("left", leftResult.block);
    final Result rightResult = implementor.visitChild(this, 1, (EnumerableRel) right, pref);
    Expression rightExpression = builder.append("right", rightResult.block);
    final PhysType physType = leftResult.physType;
    return implementor.result(physType, builder.append(Expressions.call(BuiltInMethod.SEMI_JOIN.method, Expressions.list(leftExpression, rightExpression, leftResult.physType.generateAccessor(leftKeys), rightResult.physType.generateAccessor(rightKeys)))).toBlock());
}
Also used : Expression(org.apache.calcite.linq4j.tree.Expression) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 73 with Expression

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project calcite by apache.

the class EnumerableInterpreter method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final JavaTypeFactory typeFactory = implementor.getTypeFactory();
    final BlockBuilder builder = new BlockBuilder();
    final PhysType physType = PhysTypeImpl.of(typeFactory, getRowType(), JavaRowFormat.ARRAY);
    final Expression interpreter_ = builder.append("interpreter", Expressions.new_(Interpreter.class, implementor.getRootExpression(), implementor.stash(getInput(), RelNode.class)));
    final Expression sliced_ = getRowType().getFieldCount() == 1 ? Expressions.call(BuiltInMethod.SLICE0.method, interpreter_) : interpreter_;
    builder.add(sliced_);
    return implementor.result(physType, builder.toBlock());
}
Also used : Interpreter(org.apache.calcite.interpreter.Interpreter) Expression(org.apache.calcite.linq4j.tree.Expression) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 74 with Expression

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project calcite by apache.

the class EnumerableIntersect method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    Expression intersectExp = 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 (intersectExp == null) {
            intersectExp = childExp;
        } else {
            intersectExp = Expressions.call(intersectExp, BuiltInMethod.INTERSECT.method, Expressions.list(childExp).appendIfNotNull(result.physType.comparer()));
        }
        // Once the first input has chosen its format, ask for the same for
        // other inputs.
        pref = pref.of(result.format);
    }
    builder.add(intersectExp);
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.prefer(JavaRowFormat.CUSTOM));
    return implementor.result(physType, builder.toBlock());
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Expression(org.apache.calcite.linq4j.tree.Expression) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Example 75 with Expression

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project calcite by apache.

the class EnumerableMinus method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    final BlockBuilder builder = new BlockBuilder();
    Expression minusExp = 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 (minusExp == null) {
            minusExp = childExp;
        } else {
            minusExp = Expressions.call(minusExp, BuiltInMethod.EXCEPT.method, Expressions.list(childExp).appendIfNotNull(result.physType.comparer()));
        }
        // Once the first input has chosen its format, ask for the same for
        // other inputs.
        pref = pref.of(result.format);
    }
    builder.add(minusExp);
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.prefer(JavaRowFormat.CUSTOM));
    return implementor.result(physType, builder.toBlock());
}
Also used : RelNode(org.apache.calcite.rel.RelNode) Expression(org.apache.calcite.linq4j.tree.Expression) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder)

Aggregations

Expression (org.apache.calcite.linq4j.tree.Expression)91 ParameterExpression (org.apache.calcite.linq4j.tree.ParameterExpression)64 BlockBuilder (org.apache.calcite.linq4j.tree.BlockBuilder)56 ArrayList (java.util.ArrayList)26 MethodCallExpression (org.apache.calcite.linq4j.tree.MethodCallExpression)19 RelDataType (org.apache.calcite.rel.type.RelDataType)19 ConstantExpression (org.apache.calcite.linq4j.tree.ConstantExpression)16 Test (org.junit.Test)16 Type (java.lang.reflect.Type)11 PhysType (org.apache.calcite.adapter.enumerable.PhysType)11 UnaryExpression (org.apache.calcite.linq4j.tree.UnaryExpression)11 RexNode (org.apache.calcite.rex.RexNode)10 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)9 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)9 BinaryExpression (org.apache.calcite.linq4j.tree.BinaryExpression)8 BlockStatement (org.apache.calcite.linq4j.tree.BlockStatement)8 NewExpression (org.apache.calcite.linq4j.tree.NewExpression)8 FunctionExpression (org.apache.calcite.linq4j.tree.FunctionExpression)7 MemberDeclaration (org.apache.calcite.linq4j.tree.MemberDeclaration)7 ImmutableList (com.google.common.collect.ImmutableList)5