Search in sources :

Example 6 with FlinkLogicalTableSourceScan

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);
}
Also used : FlinkLogicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan) Sort(org.apache.calcite.rel.core.Sort) FlinkLogicalSort(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable)

Example 7 with FlinkLogicalTableSourceScan

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);
}
Also used : FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) FlinkLogicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable)

Example 8 with FlinkLogicalTableSourceScan

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);
}
Also used : FlinkLogicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan) Sort(org.apache.calcite.rel.core.Sort) FlinkLogicalSort(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable)

Example 9 with FlinkLogicalTableSourceScan

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);
    }
}
Also used : RelBuilder(org.apache.calcite.tools.RelBuilder) FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) RexProgram(org.apache.calcite.rex.RexProgram) FlinkLogicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan) SupportsFilterPushDown(org.apache.flink.table.connector.source.abilities.SupportsFilterPushDown) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) RexProgramBuilder(org.apache.calcite.rex.RexProgramBuilder) RexNode(org.apache.calcite.rex.RexNode)

Example 10 with FlinkLogicalTableSourceScan

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);
}
Also used : FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) FlinkLogicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable)

Aggregations

FlinkLogicalTableSourceScan (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan)18 FlinkLogicalCalc (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc)12 TableSourceTable (org.apache.flink.table.planner.plan.schema.TableSourceTable)12 RexProgram (org.apache.calcite.rex.RexProgram)9 RexNode (org.apache.calcite.rex.RexNode)6 RexProgramBuilder (org.apache.calcite.rex.RexProgramBuilder)6 FlinkLogicalWatermarkAssigner (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWatermarkAssigner)6 Sort (org.apache.calcite.rel.core.Sort)3 RexBuilder (org.apache.calcite.rex.RexBuilder)3 RexInputRef (org.apache.calcite.rex.RexInputRef)3 RexShuttle (org.apache.calcite.rex.RexShuttle)3 RelBuilder (org.apache.calcite.tools.RelBuilder)3 SupportsFilterPushDown (org.apache.flink.table.connector.source.abilities.SupportsFilterPushDown)3 FlinkTypeFactory (org.apache.flink.table.planner.calcite.FlinkTypeFactory)3 FlinkLogicalSort (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort)3