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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations