use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan in project flink by apache.
the class PushLimitIntoTableSourceScanRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
Sort sort = call.rel(0);
FlinkLogicalTableSourceScan scan = call.rel(1);
int offset = sort.offset == null ? 0 : RexLiteral.intValue(sort.offset);
int limit = offset + RexLiteral.intValue(sort.fetch);
TableSourceTable newTableSourceTable = applyLimit(limit, scan);
FlinkLogicalTableSourceScan newScan = FlinkLogicalTableSourceScan.create(scan.getCluster(), scan.getHints(), newTableSourceTable);
Sort newSort = sort.copy(sort.getTraitSet(), Collections.singletonList(newScan));
call.transformTo(newSort);
}
use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan in project flink-mirror by flink-ci.
the class PushFilterInCalcIntoTableSourceScanRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
FlinkLogicalCalc calc = call.rel(0);
FlinkLogicalTableSourceScan scan = call.rel(1);
TableSourceTable table = scan.getTable().unwrap(TableSourceTable.class);
pushFilterIntoScan(call, calc, scan, table);
}
use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan in project flink-mirror by flink-ci.
the class PushLimitIntoTableSourceScanRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
Sort sort = call.rel(0);
FlinkLogicalTableSourceScan scan = call.rel(1);
int offset = sort.offset == null ? 0 : RexLiteral.intValue(sort.offset);
int limit = offset + RexLiteral.intValue(sort.fetch);
TableSourceTable newTableSourceTable = applyLimit(limit, scan);
FlinkLogicalTableSourceScan newScan = FlinkLogicalTableSourceScan.create(scan.getCluster(), scan.getHints(), newTableSourceTable);
Sort newSort = sort.copy(sort.getTraitSet(), Collections.singletonList(newScan));
call.transformTo(newSort);
}
use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan in project flink by splunk.
the class PushFilterInCalcIntoTableSourceScanRule method pushFilterIntoScan.
private void pushFilterIntoScan(RelOptRuleCall call, Calc calc, FlinkLogicalTableSourceScan scan, FlinkPreparingTableBase relOptTable) {
RexProgram originProgram = calc.getProgram();
RelBuilder relBuilder = call.builder();
Tuple2<RexNode[], RexNode[]> extractedPredicates = extractPredicates(originProgram.getInputRowType().getFieldNames().toArray(new String[0]), originProgram.expandLocalRef(originProgram.getCondition()), scan, relBuilder.getRexBuilder());
RexNode[] convertiblePredicates = extractedPredicates._1;
RexNode[] unconvertedPredicates = extractedPredicates._2;
if (convertiblePredicates.length == 0) {
// no condition can be translated to expression
return;
}
Tuple2<SupportsFilterPushDown.Result, TableSourceTable> pushdownResultWithScan = resolveFiltersAndCreateTableSourceTable(convertiblePredicates, relOptTable.unwrap(TableSourceTable.class), scan, relBuilder);
SupportsFilterPushDown.Result result = pushdownResultWithScan._1;
TableSourceTable tableSourceTable = pushdownResultWithScan._2;
FlinkLogicalTableSourceScan newScan = FlinkLogicalTableSourceScan.create(scan.getCluster(), scan.getHints(), tableSourceTable);
// build new calc program
RexProgramBuilder programBuilder = RexProgramBuilder.forProgram(originProgram, call.builder().getRexBuilder(), true);
programBuilder.clearCondition();
if (!result.getRemainingFilters().isEmpty() || unconvertedPredicates.length != 0) {
RexNode remainingCondition = createRemainingCondition(relBuilder, result.getRemainingFilters(), unconvertedPredicates);
RexNode simplifiedRemainingCondition = FlinkRexUtil.simplify(relBuilder.getRexBuilder(), remainingCondition, calc.getCluster().getPlanner().getExecutor());
programBuilder.addCondition(simplifiedRemainingCondition);
}
RexProgram program = programBuilder.getProgram();
if (program.isTrivial()) {
call.transformTo(newScan);
} else {
FlinkLogicalCalc newCalc = FlinkLogicalCalc.create(newScan, program);
call.transformTo(newCalc);
}
}
use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan in project flink by splunk.
the class PushFilterInCalcIntoTableSourceScanRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
FlinkLogicalCalc calc = call.rel(0);
FlinkLogicalTableSourceScan scan = call.rel(1);
TableSourceTable table = scan.getTable().unwrap(TableSourceTable.class);
pushFilterIntoScan(call, calc, scan, table);
}
Aggregations