Search in sources :

Example 1 with SupportsLimitPushDown

use of org.apache.flink.table.connector.source.abilities.SupportsLimitPushDown in project flink by apache.

the class PushLimitIntoTableSourceScanRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    Sort sort = call.rel(0);
    TableSourceTable tableSourceTable = call.rel(1).getTable().unwrap(TableSourceTable.class);
    // a limit can be pushed down only if it satisfies the two conditions: 1) do not have order
    // by keys, 2) have limit.
    boolean onlyLimit = sort.getCollation().getFieldCollations().isEmpty() && sort.fetch != null;
    return onlyLimit && tableSourceTable != null && tableSourceTable.tableSource() instanceof SupportsLimitPushDown && Arrays.stream(tableSourceTable.abilitySpecs()).noneMatch(spec -> spec instanceof LimitPushDownSpec);
}
Also used : Arrays(java.util.Arrays) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) SupportsLimitPushDown(org.apache.flink.table.connector.source.abilities.SupportsLimitPushDown) SourceAbilityContext(org.apache.flink.table.planner.plan.abilities.source.SourceAbilityContext) RexLiteral(org.apache.calcite.rex.RexLiteral) LimitPushDownSpec(org.apache.flink.table.planner.plan.abilities.source.LimitPushDownSpec) FlinkLogicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan) SourceAbilitySpec(org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) RelOptRule(org.apache.calcite.plan.RelOptRule) FlinkStatistic(org.apache.flink.table.planner.plan.stats.FlinkStatistic) Sort(org.apache.calcite.rel.core.Sort) TableStats(org.apache.flink.table.plan.stats.TableStats) FlinkLogicalSort(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort) Collections(java.util.Collections) LimitPushDownSpec(org.apache.flink.table.planner.plan.abilities.source.LimitPushDownSpec) Sort(org.apache.calcite.rel.core.Sort) FlinkLogicalSort(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort) SupportsLimitPushDown(org.apache.flink.table.connector.source.abilities.SupportsLimitPushDown) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable)

Aggregations

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1 Sort (org.apache.calcite.rel.core.Sort)1 RexLiteral (org.apache.calcite.rex.RexLiteral)1 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)1 SupportsLimitPushDown (org.apache.flink.table.connector.source.abilities.SupportsLimitPushDown)1 TableStats (org.apache.flink.table.plan.stats.TableStats)1 LimitPushDownSpec (org.apache.flink.table.planner.plan.abilities.source.LimitPushDownSpec)1 SourceAbilityContext (org.apache.flink.table.planner.plan.abilities.source.SourceAbilityContext)1 SourceAbilitySpec (org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec)1 FlinkLogicalSort (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort)1 FlinkLogicalTableSourceScan (org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableSourceScan)1 TableSourceTable (org.apache.flink.table.planner.plan.schema.TableSourceTable)1 FlinkStatistic (org.apache.flink.table.planner.plan.stats.FlinkStatistic)1