Search in sources :

Example 26 with RexLocalRef

use of org.apache.calcite.rex.RexLocalRef 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

RexLocalRef (org.apache.calcite.rex.RexLocalRef)19 RexNode (org.apache.calcite.rex.RexNode)17 ArrayList (java.util.ArrayList)12 RexProgram (org.apache.calcite.rex.RexProgram)9 RexLocalRef (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLocalRef)7 RelDataType (org.apache.calcite.rel.type.RelDataType)7 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)5 RelNode (org.apache.calcite.rel.RelNode)5 RexProgramBuilder (org.apache.calcite.rex.RexProgramBuilder)5 RexInputRef (org.apache.calcite.rex.RexInputRef)4 RexLiteral (org.apache.calcite.rex.RexLiteral)4 RexLiteral (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexLiteral)3 LogicalCalc (org.apache.calcite.rel.logical.LogicalCalc)3 HashMap (java.util.HashMap)2 RexProgram (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexProgram)2 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 RexShuttle (org.apache.calcite.rex.RexShuttle)2 RexWindow (org.apache.calcite.rex.RexWindow)2 ExecutableExpression (org.apache.storm.sql.runtime.calcite.ExecutableExpression)2