Search in sources :

Example 61 with Expression

use of 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 62 with Expression

use of 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 63 with Expression

use of 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 64 with Expression

use of 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)

Example 65 with Expression

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

the class CassandraToEnumerableConverter method implement.

public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
    // Generates a call to "query" with the appropriate fields and predicates
    final BlockBuilder list = new BlockBuilder();
    final CassandraRel.Implementor cassandraImplementor = new CassandraRel.Implementor();
    cassandraImplementor.visitChild(0, getInput());
    final RelDataType rowType = getRowType();
    final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), rowType, pref.prefer(JavaRowFormat.ARRAY));
    final Expression fields = list.append("fields", constantArrayList(Pair.zip(CassandraRules.cassandraFieldNames(rowType), new AbstractList<Class>() {

        @Override
        public Class get(int index) {
            return physType.fieldClass(index);
        }

        @Override
        public int size() {
            return rowType.getFieldCount();
        }
    }), Pair.class));
    List<Map.Entry<String, String>> selectList = new ArrayList<Map.Entry<String, String>>();
    for (Map.Entry<String, String> entry : Pair.zip(cassandraImplementor.selectFields.keySet(), cassandraImplementor.selectFields.values())) {
        selectList.add(entry);
    }
    final Expression selectFields = list.append("selectFields", constantArrayList(selectList, Pair.class));
    final Expression table = list.append("table", cassandraImplementor.table.getExpression(CassandraTable.CassandraQueryable.class));
    final Expression predicates = list.append("predicates", constantArrayList(cassandraImplementor.whereClause, String.class));
    final Expression order = list.append("order", constantArrayList(cassandraImplementor.order, String.class));
    final Expression offset = list.append("offset", Expressions.constant(cassandraImplementor.offset));
    final Expression fetch = list.append("fetch", Expressions.constant(cassandraImplementor.fetch));
    Expression enumerable = list.append("enumerable", Expressions.call(table, CassandraMethod.CASSANDRA_QUERYABLE_QUERY.method, fields, selectFields, predicates, order, offset, fetch));
    if (CalcitePrepareImpl.DEBUG) {
        System.out.println("Cassandra: " + predicates);
    }
    Hook.QUERY_PLAN.run(predicates);
    list.add(Expressions.return_(null, enumerable));
    return implementor.result(physType, list.toBlock());
}
Also used : EnumerableRelImplementor(org.apache.calcite.adapter.enumerable.EnumerableRelImplementor) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) PhysType(org.apache.calcite.adapter.enumerable.PhysType) Expression(org.apache.calcite.linq4j.tree.Expression) MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) Map(java.util.Map) BlockBuilder(org.apache.calcite.linq4j.tree.BlockBuilder) Pair(org.apache.calcite.util.Pair)

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)22 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 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 List (java.util.List)5