Search in sources :

Example 16 with HepRelVertex

use of org.apache.calcite.plan.hep.HepRelVertex in project flink by apache.

the class PythonCorrelateSplitRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    FlinkLogicalCorrelate correlate = call.rel(0);
    RexBuilder rexBuilder = call.builder().getRexBuilder();
    RelNode left = ((HepRelVertex) correlate.getLeft()).getCurrentRel();
    RelNode right = ((HepRelVertex) correlate.getRight()).getCurrentRel();
    int primitiveLeftFieldCount = left.getRowType().getFieldCount();
    ArrayBuffer<RexNode> extractedRexNodes = new ArrayBuffer<>();
    RelNode rightNewInput;
    if (right instanceof FlinkLogicalTableFunctionScan) {
        FlinkLogicalTableFunctionScan scan = (FlinkLogicalTableFunctionScan) right;
        rightNewInput = createNewScan(scan, createScalarFunctionSplitter(null, rexBuilder, primitiveLeftFieldCount, extractedRexNodes, scan.getCall()));
    } else {
        FlinkLogicalCalc calc = (FlinkLogicalCalc) right;
        FlinkLogicalTableFunctionScan scan = StreamPhysicalCorrelateRule.getTableScan(calc);
        FlinkLogicalCalc mergedCalc = StreamPhysicalCorrelateRule.getMergedCalc(calc);
        FlinkLogicalTableFunctionScan newScan = createNewScan(scan, createScalarFunctionSplitter(null, rexBuilder, primitiveLeftFieldCount, extractedRexNodes, scan.getCall()));
        rightNewInput = mergedCalc.copy(mergedCalc.getTraitSet(), newScan, mergedCalc.getProgram());
    }
    FlinkLogicalCorrelate newCorrelate;
    if (extractedRexNodes.size() > 0) {
        FlinkLogicalCalc leftCalc = createNewLeftCalc(left, rexBuilder, extractedRexNodes, correlate);
        newCorrelate = new FlinkLogicalCorrelate(correlate.getCluster(), correlate.getTraitSet(), leftCalc, rightNewInput, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType());
    } else {
        newCorrelate = new FlinkLogicalCorrelate(correlate.getCluster(), correlate.getTraitSet(), left, rightNewInput, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType());
    }
    FlinkLogicalCalc newTopCalc = createTopCalc(primitiveLeftFieldCount, rexBuilder, extractedRexNodes, correlate.getRowType(), newCorrelate);
    call.transformTo(newTopCalc);
}
Also used : FlinkLogicalCorrelate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate) HepRelVertex(org.apache.calcite.plan.hep.HepRelVertex) RelNode(org.apache.calcite.rel.RelNode) FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) RexBuilder(org.apache.calcite.rex.RexBuilder) FlinkLogicalTableFunctionScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableFunctionScan) ArrayBuffer(scala.collection.mutable.ArrayBuffer) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

HepRelVertex (org.apache.calcite.plan.hep.HepRelVertex)16 RelNode (org.apache.calcite.rel.RelNode)8 RexNode (org.apache.calcite.rex.RexNode)7 Join (org.apache.calcite.rel.core.Join)4 RexBuilder (org.apache.calcite.rex.RexBuilder)4 ArrayList (java.util.ArrayList)3 JoinInfo (org.apache.calcite.rel.core.JoinInfo)3 Project (org.apache.calcite.rel.core.Project)3 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)3 RelOptCluster (org.apache.calcite.plan.RelOptCluster)2 RelSubset (org.apache.calcite.plan.volcano.RelSubset)2 Aggregate (org.apache.calcite.rel.core.Aggregate)2 Sort (org.apache.calcite.rel.core.Sort)2 TableScan (org.apache.calcite.rel.core.TableScan)2 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)2 HashMap (java.util.HashMap)1 RelOptPredicateList (org.apache.calcite.plan.RelOptPredicateList)1 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1 Calc (org.apache.calcite.rel.core.Calc)1 Collect (org.apache.calcite.rel.core.Collect)1