Search in sources :

Example 61 with Expression

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);
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 62 with Expression

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);
}
Also used : Expression(org.apache.calcite.linq4j.tree.Expression) ArrayList(java.util.ArrayList)

Example 63 with 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 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));
}
Also used : Expression(org.apache.calcite.linq4j.tree.Expression) MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression)

Example 64 with 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;
    }
}
Also used : MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) Expression(org.apache.calcite.linq4j.tree.Expression) MethodCallExpression(org.apache.calcite.linq4j.tree.MethodCallExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 65 with Expression

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);
}
Also used : Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) Expression(org.apache.calcite.linq4j.tree.Expression) RelOptTable(org.apache.calcite.plan.RelOptTable) LogicalTableScan(org.apache.calcite.rel.logical.LogicalTableScan)

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)26 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 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)9 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