Search in sources :

Example 16 with FlinkLogicalCalc

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc in project flink by apache.

the class RedundantRankNumberColumnRemoveRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    FlinkLogicalCalc calc = call.rel(0);
    ImmutableBitSet usedFields = getUsedFields(calc.getProgram());
    FlinkLogicalRank rank = call.rel(1);
    return rank.outputRankNumber() && !usedFields.get(rank.getRowType().getFieldCount() - 1);
}
Also used : FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) FlinkLogicalRank(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalRank)

Example 17 with FlinkLogicalCalc

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc in project flink by apache.

the class RedundantRankNumberColumnRemoveRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    FlinkLogicalCalc calc = call.rel(0);
    FlinkLogicalRank rank = call.rel(1);
    FlinkLogicalRank newRank = new FlinkLogicalRank(rank.getCluster(), rank.getTraitSet(), rank.getInput(), rank.partitionKey(), rank.orderKey(), rank.rankType(), rank.rankRange(), rank.rankNumberType(), false);
    RexProgram oldProgram = calc.getProgram();
    Pair<List<RexNode>, RexNode> projectsAndCondition = getProjectsAndCondition(oldProgram);
    RexProgram newProgram = RexProgram.create(newRank.getRowType(), projectsAndCondition.left, projectsAndCondition.right, oldProgram.getOutputRowType(), rank.getCluster().getRexBuilder());
    FlinkLogicalCalc newCalc = FlinkLogicalCalc.create(newRank, newProgram);
    call.transformTo(newCalc);
}
Also used : FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) FlinkLogicalRank(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalRank) RexProgram(org.apache.calcite.rex.RexProgram) List(java.util.List) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

FlinkLogicalCalc (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc)17 RexNode (org.apache.calcite.rex.RexNode)11 RexProgram (org.apache.calcite.rex.RexProgram)9 FlinkLogicalCorrelate (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate)8 FlinkLogicalTableFunctionScan (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableFunctionScan)8 RelNode (org.apache.calcite.rel.RelNode)6 RexBuilder (org.apache.calcite.rex.RexBuilder)6 RexProgramBuilder (org.apache.calcite.rex.RexProgramBuilder)6 List (java.util.List)5 RexCall (org.apache.calcite.rex.RexCall)5 Collectors (java.util.stream.Collectors)4 RexInputRef (org.apache.calcite.rex.RexInputRef)4 FlinkLogicalTableSourceScan (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan)4 RelOptRule (org.apache.calcite.plan.RelOptRule)3 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)3 HepRelVertex (org.apache.calcite.plan.hep.HepRelVertex)3 RelDataType (org.apache.calcite.rel.type.RelDataType)3 TableSourceTable (org.apache.flink.table.planner.plan.schema.TableSourceTable)3 PythonUtil (org.apache.flink.table.planner.plan.utils.PythonUtil)3 Collections (java.util.Collections)2