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