use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate in project flink by apache.
the class BatchPhysicalPythonCorrelateRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
FlinkLogicalCorrelate join = call.rel(0);
RelNode right = ((RelSubset) join.getRight()).getOriginal();
if (right instanceof FlinkLogicalTableFunctionScan) {
// right node is a table function
FlinkLogicalTableFunctionScan scan = (FlinkLogicalTableFunctionScan) right;
// return true if the table function is python table function
return PythonUtil.isPythonCall(scan.getCall(), null);
} else if (right instanceof FlinkLogicalCalc) {
// a filter is pushed above the table function
FlinkLogicalCalc calc = (FlinkLogicalCalc) right;
RelNode input = ((RelSubset) calc.getInput()).getOriginal();
if (input instanceof FlinkLogicalTableFunctionScan) {
FlinkLogicalTableFunctionScan scan = (FlinkLogicalTableFunctionScan) input;
// return true if the table function is python table function
return PythonUtil.isPythonCall(scan.getCall(), null);
}
}
return false;
}
use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate 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);
}
use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate in project flink by apache.
the class RelTimeIndicatorConverter method visitCorrelate.
private RelNode visitCorrelate(FlinkLogicalCorrelate correlate) {
// visit children and update inputs
RelNode newLeft = correlate.getLeft().accept(this);
RelNode newRight = correlate.getRight().accept(this);
if (newRight instanceof FlinkLogicalTableFunctionScan) {
FlinkLogicalTableFunctionScan newScan = (FlinkLogicalTableFunctionScan) newRight;
List<RelNode> newScanInputs = newScan.getInputs().stream().map(input -> input.accept(this)).collect(Collectors.toList());
// check if input field contains time indicator type
// materialize field if no time indicator is present anymore
// if input field is already materialized, change to timestamp type
RexTimeIndicatorMaterializer materializer = new RexTimeIndicatorMaterializer(newLeft);
RexNode newScanCall = newScan.getCall().accept(materializer);
newRight = newScan.copy(newScan.getTraitSet(), newScanInputs, newScanCall, newScan.getElementType(), newScan.getRowType(), newScan.getColumnMappings());
}
return FlinkLogicalCorrelate.create(newLeft, newRight, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType());
}
Aggregations