Search in sources :

Example 11 with LogicalCalc

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalCalc 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)

Aggregations

LogicalCalc (org.apache.calcite.rel.logical.LogicalCalc)10 RexProgram (org.apache.calcite.rex.RexProgram)9 RelNode (org.apache.calcite.rel.RelNode)6 RexProgramBuilder (org.apache.calcite.rex.RexProgramBuilder)5 RexBuilder (org.apache.calcite.rex.RexBuilder)4 RexNode (org.apache.calcite.rex.RexNode)4 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RexLocalRef (org.apache.calcite.rex.RexLocalRef)3 ArrayList (java.util.ArrayList)2 RelOptCluster (org.apache.calcite.plan.RelOptCluster)2 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)2 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)1 LogicalCalc (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalCalc)1 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)1 RexOver (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexOver)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1 RexLiteral (org.apache.calcite.rex.RexLiteral)1 RexShuttle (org.apache.calcite.rex.RexShuttle)1