use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project beam by apache.
the class CalcRelSplitter method traceLevelExpressions.
/**
* Traces the given array of level expression lists at the finer level.
*
* @param exprs Array expressions
* @param exprLevels For each expression, the ordinal of its level
* @param levelTypeOrdinals For each level, the ordinal of its type in the {@link #relTypes} array
* @param levelCount The number of levels
*/
private void traceLevelExpressions(RexNode[] exprs, int[] exprLevels, int[] levelTypeOrdinals, int levelCount) {
StringWriter traceMsg = new StringWriter();
PrintWriter traceWriter = new PrintWriter(traceMsg);
traceWriter.println("FarragoAutoCalcRule result expressions for: ");
traceWriter.println(program.toString());
for (int level = 0; level < levelCount; level++) {
traceWriter.println("Rel Level " + level + ", type " + relTypes[levelTypeOrdinals[level]]);
for (int i = 0; i < exprs.length; i++) {
RexNode expr = exprs[i];
assert (exprLevels[i] >= -1) && (exprLevels[i] < levelCount) : "expression's level is out of range";
if (exprLevels[i] == level) {
traceWriter.println("\t" + i + ": " + expr);
}
}
traceWriter.println();
}
String msg = traceMsg.toString();
RULE_LOGGER.trace(msg);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.linq4j.tree.Expression in project samza by apache.
the class SamzaSqlScalarFunctionImpl method getImplementor.
@Override
public CallImplementor getImplementor() {
return RexImpTable.createImplementor((translator, call, translatedOperands) -> {
final Expression sqlContext = Expressions.parameter(SamzaSqlExecutionContext.class, "sqlContext");
final Expression samzaContext = Expressions.parameter(SamzaSqlExecutionContext.class, "context");
final Expression getUdfInstance = Expressions.call(ScalarUdf.class, sqlContext, getUdfMethod, Expressions.constant(udfMethod.getDeclaringClass().getName()), Expressions.constant(udfName), samzaContext);
List<Expression> convertedOperands = new ArrayList<>();
// We explicitly Convert the untyped arguments to type that the UDf expects.
for (int index = 0; index < translatedOperands.size(); index++) {
if (!udfMetadata.isDisableArgCheck() && translatedOperands.get(index).type == Object.class && udfMethod.getParameters()[index].getType() != Object.class) {
convertedOperands.add(Expressions.convert_(translatedOperands.get(index), udfMethod.getParameters()[index].getType()));
} else {
convertedOperands.add(translatedOperands.get(index));
}
}
final Expression callExpression = Expressions.call(Expressions.convert_(getUdfInstance, udfMethod.getDeclaringClass()), udfMethod, convertedOperands);
return callExpression;
}, NullPolicy.NONE, false);
}
use of org.apache.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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);
}
Aggregations