Search in sources :

Example 6 with StreamPhysicalCalc

use of org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalCalc in project flink by apache.

the class PushFilterPastChangelogNormalizeRule method transformWithRemainingPredicates.

/**
 * Transforms the {@link RelOptRuleCall} to use {@param changelogNormalize} as the new input to
 * a {@link StreamPhysicalCalc} which uses {@param predicates} for the condition.
 */
private void transformWithRemainingPredicates(RelOptRuleCall call, StreamPhysicalChangelogNormalize changelogNormalize, List<RexNode> predicates) {
    final StreamPhysicalCalc calc = call.rel(0);
    final RelBuilder relBuilder = call.builder();
    final StreamPhysicalCalc newCalc = projectIdentityWithConditions(relBuilder, changelogNormalize, predicates);
    final StreamPhysicalCalc newProjectedCalc = projectWith(relBuilder, calc, newCalc);
    if (newProjectedCalc.getProgram().isTrivial()) {
        call.transformTo(changelogNormalize);
    } else {
        call.transformTo(newProjectedCalc);
    }
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) StreamPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalCalc)

Example 7 with StreamPhysicalCalc

use of org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalCalc in project flink by apache.

the class PushFilterPastChangelogNormalizeRule method projectWith.

/**
 * Returns a {@link StreamPhysicalCalc} which is a copy of {@param calc}, but with the
 * projections applied from {@param projectFromCalc}.
 */
private StreamPhysicalCalc projectWith(RelBuilder relBuilder, StreamPhysicalCalc projectFromCalc, StreamPhysicalCalc calc) {
    final RexProgramBuilder programBuilder = new RexProgramBuilder(calc.getRowType(), relBuilder.getRexBuilder());
    if (calc.getProgram().getCondition() != null) {
        programBuilder.addCondition(calc.getProgram().expandLocalRef(calc.getProgram().getCondition()));
    }
    for (Pair<RexLocalRef, String> projectRef : projectFromCalc.getProgram().getNamedProjects()) {
        final RexNode project = projectFromCalc.getProgram().expandLocalRef(projectRef.left);
        programBuilder.addProject(project, projectRef.right);
    }
    final RexProgram newProgram = programBuilder.getProgram();
    return (StreamPhysicalCalc) calc.copy(calc.getTraitSet(), calc.getInput(), newProgram);
}
Also used : RexProgram(org.apache.calcite.rex.RexProgram) StreamPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalCalc) RexLocalRef(org.apache.calcite.rex.RexLocalRef) RexProgramBuilder(org.apache.calcite.rex.RexProgramBuilder) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

StreamPhysicalCalc (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalCalc)7 RexNode (org.apache.calcite.rex.RexNode)4 RexProgram (org.apache.calcite.rex.RexProgram)4 StreamPhysicalChangelogNormalize (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalChangelogNormalize)4 RexProgramBuilder (org.apache.calcite.rex.RexProgramBuilder)3 StreamPhysicalExchange (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalExchange)3 ArrayList (java.util.ArrayList)2 RelDistribution (org.apache.calcite.rel.RelDistribution)2 RelNode (org.apache.calcite.rel.RelNode)2 RexLocalRef (org.apache.calcite.rex.RexLocalRef)2 Mappings (org.apache.calcite.util.mapping.Mappings)2 StreamPhysicalWatermarkAssigner (org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalWatermarkAssigner)2 FlinkRelDistribution (org.apache.flink.table.planner.plan.trait.FlinkRelDistribution)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1