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);
}
Aggregations