use of org.apache.calcite.linq4j.tree.Expression in project streamline by hortonworks.
the class RexNodeToJavaCodeCompiler method baz.
/**
* Given a method that implements {@link ExecutableExpression#execute(Context, Object[])},
* adds a bridge method that implements {@link ExecutableExpression#execute(Context)}, and
* compiles.
*/
static String baz(ParameterExpression context_, ParameterExpression outputValues_, BlockStatement block, String className) {
final List<MemberDeclaration> declarations = Lists.newArrayList();
// public void execute(Context, Object[] outputValues)
declarations.add(Expressions.methodDecl(Modifier.PUBLIC, void.class, StreamlineBuiltInMethod.EXPR_EXECUTE2.method.getName(), ImmutableList.of(context_, outputValues_), block));
// public Object execute(Context)
final BlockBuilder builder = new BlockBuilder();
final Expression values_ = builder.append("values", Expressions.newArrayBounds(Object.class, 1, Expressions.constant(1)));
builder.add(Expressions.statement(Expressions.call(Expressions.parameter(ExecutableExpression.class, "this"), StreamlineBuiltInMethod.EXPR_EXECUTE2.method, context_, values_)));
builder.add(Expressions.return_(null, Expressions.arrayIndex(values_, Expressions.constant(0))));
declarations.add(Expressions.methodDecl(Modifier.PUBLIC, Object.class, StreamlineBuiltInMethod.EXPR_EXECUTE1.method.getName(), ImmutableList.of(context_), builder.toBlock()));
final ClassDeclaration classDeclaration = Expressions.classDecl(Modifier.PUBLIC, className, null, ImmutableList.<Type>of(ExecutableExpression.class), declarations);
return Expressions.toString(Lists.newArrayList(classDeclaration), "\n", false);
}
use of org.apache.calcite.linq4j.tree.Expression in project calcite by apache.
the class EnumerableTableScan method implement.
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
// Note that representation is ARRAY. This assumes that the table
// returns a Object[] for each record. Actually a Table<T> can
// return any type T. And, if it is a JdbcTable, we'd like to be
// able to generate alternate accessors that return e.g. synthetic
// records {T0 f0; T1 f1; ...} and don't box every primitive value.
final PhysType physType = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), format());
final Expression expression = getExpression(physType);
return implementor.result(physType, Blocks.toBlock(expression));
}
use of org.apache.calcite.linq4j.tree.Expression in project calcite by apache.
the class EnumerableTableScan method fieldExpression.
private Expression fieldExpression(ParameterExpression row_, int i, PhysType physType, JavaRowFormat format) {
final Expression e = format.field(row_, i, null, physType.getJavaFieldType(i));
final RelDataType relFieldType = physType.getRowType().getFieldList().get(i).getType();
switch(relFieldType.getSqlTypeName()) {
case ARRAY:
case MULTISET:
// We can't represent a multiset or array as a List<Employee>, because
// the consumer does not know the element type.
// The standard element type is List.
// We need to convert to a List<List>.
final JavaTypeFactory typeFactory = (JavaTypeFactory) getCluster().getTypeFactory();
final PhysType elementPhysType = PhysTypeImpl.of(typeFactory, relFieldType.getComponentType(), JavaRowFormat.CUSTOM);
final MethodCallExpression e2 = Expressions.call(BuiltInMethod.AS_ENUMERABLE2.method, e);
final RelDataType dummyType = this.rowType;
final Expression e3 = elementPhysType.convertTo(e2, PhysTypeImpl.of(typeFactory, dummyType, JavaRowFormat.LIST));
return Expressions.call(e3, BuiltInMethod.ENUMERABLE_TO_LIST.method);
default:
return e;
}
}
use of org.apache.calcite.linq4j.tree.Expression in project calcite by apache.
the class EnumerableTableScanRule method convert.
@Override
public RelNode convert(RelNode rel) {
LogicalTableScan scan = (LogicalTableScan) rel;
final RelOptTable relOptTable = scan.getTable();
final Table table = relOptTable.unwrap(Table.class);
if (!EnumerableTableScan.canHandle(table)) {
return null;
}
final Expression expression = relOptTable.getExpression(Object.class);
if (expression == null) {
return null;
}
return EnumerableTableScan.create(scan.getCluster(), relOptTable);
}
use of org.apache.calcite.linq4j.tree.Expression in project calcite by apache.
the class EnumerableThetaJoin method implement.
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final 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 = PhysTypeImpl.of(implementor.getTypeFactory(), getRowType(), pref.preferArray());
final BlockBuilder builder2 = new BlockBuilder();
return implementor.result(physType, builder.append(Expressions.call(BuiltInMethod.THETA_JOIN.method, leftExpression, rightExpression, predicate(implementor, builder2, leftResult.physType, rightResult.physType, condition), EnumUtils.joinSelector(joinType, physType, ImmutableList.of(leftResult.physType, rightResult.physType)), Expressions.constant(joinType.generatesNullsOnLeft()), Expressions.constant(joinType.generatesNullsOnRight()))).toBlock());
}
Aggregations