Search in sources :

Example 31 with RexProgramBuilder

use of org.apache.calcite.rex.RexProgramBuilder in project calcite by apache.

the class RelStructuredTypeFlattener method rewriteRel.

public void rewriteRel(LogicalCalc rel) {
    // Translate the child.
    final RelNode newInput = getNewForOldRel(rel.getInput());
    final RelOptCluster cluster = rel.getCluster();
    RexProgramBuilder programBuilder = new RexProgramBuilder(newInput.getRowType(), cluster.getRexBuilder());
    // Convert the common expressions.
    final RexProgram program = rel.getProgram();
    final RewriteRexShuttle shuttle = new RewriteRexShuttle();
    for (RexNode expr : program.getExprList()) {
        programBuilder.registerInput(expr.accept(shuttle));
    }
    // Convert the projections.
    final List<Pair<RexNode, String>> flattenedExpList = Lists.newArrayList();
    List<String> fieldNames = rel.getRowType().getFieldNames();
    flattenProjections(new RewriteRexShuttle(), program.getProjectList(), fieldNames, "", flattenedExpList);
    // Register each of the new projections.
    for (Pair<RexNode, String> flattenedExp : flattenedExpList) {
        programBuilder.addProject(flattenedExp.left, flattenedExp.right);
    }
    // Translate the condition.
    final RexLocalRef conditionRef = program.getCondition();
    if (conditionRef != null) {
        programBuilder.addCondition(new RexLocalRef(getNewForOldInput(conditionRef.getIndex()), conditionRef.getType()));
    }
    RexProgram newProgram = programBuilder.getProgram();
    // Create a new calc relational expression.
    LogicalCalc newRel = LogicalCalc.create(newInput, newProgram);
    setNewForOldRel(rel, newRel);
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) RexProgram(org.apache.calcite.rex.RexProgram) RelNode(org.apache.calcite.rel.RelNode) RexLocalRef(org.apache.calcite.rex.RexLocalRef) LogicalCalc(org.apache.calcite.rel.logical.LogicalCalc) RexProgramBuilder(org.apache.calcite.rex.RexProgramBuilder) RexNode(org.apache.calcite.rex.RexNode) Pair(org.apache.calcite.util.Pair)

Example 32 with RexProgramBuilder

use of org.apache.calcite.rex.RexProgramBuilder in project drill by apache.

the class DrillMergeFilterRule method createProgram.

/**
 * Creates a RexProgram corresponding to a LogicalFilter
 *
 * @param filterRel the LogicalFilter
 * @return created RexProgram
 */
private RexProgram createProgram(Filter filterRel) {
    RexProgramBuilder programBuilder = new RexProgramBuilder(filterRel.getRowType(), filterRel.getCluster().getRexBuilder());
    programBuilder.addIdentity();
    programBuilder.addCondition(filterRel.getCondition());
    return programBuilder.getProgram();
}
Also used : RexProgramBuilder(org.apache.calcite.rex.RexProgramBuilder)

Aggregations

RexProgramBuilder (org.apache.calcite.rex.RexProgramBuilder)32 RexProgram (org.apache.calcite.rex.RexProgram)23 RexNode (org.apache.calcite.rex.RexNode)17 RexBuilder (org.apache.calcite.rex.RexBuilder)13 RelNode (org.apache.calcite.rel.RelNode)11 RelDataType (org.apache.calcite.rel.type.RelDataType)11 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)7 RexLocalRef (org.apache.calcite.rex.RexLocalRef)6 ByteString (org.apache.calcite.avatica.util.ByteString)5 LogicalCalc (org.apache.calcite.rel.logical.LogicalCalc)5 DateString (org.apache.calcite.util.DateString)5 NlsString (org.apache.calcite.util.NlsString)5 TimeString (org.apache.calcite.util.TimeString)5 TimestampString (org.apache.calcite.util.TimestampString)5 TimestampWithTimeZoneString (org.apache.calcite.util.TimestampWithTimeZoneString)5 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)4 RexInputRef (org.apache.calcite.rex.RexInputRef)4 FlinkLogicalCalc (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3