Search in sources :

Example 11 with BatchPhysicalTableSourceScan

use of org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan in project flink by apache.

the class PushLocalSortAggWithSortAndCalcIntoScanRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    BatchPhysicalGroupAggregateBase localAggregate = call.rel(1);
    BatchPhysicalCalc calc = call.rel(3);
    BatchPhysicalTableSourceScan tableSourceScan = call.rel(4);
    return isInputRefOnly(calc) && isProjectionNotPushedDown(tableSourceScan) && canPushDown(call, localAggregate, tableSourceScan);
}
Also used : BatchPhysicalGroupAggregateBase(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalGroupAggregateBase) BatchPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalCalc) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan)

Example 12 with BatchPhysicalTableSourceScan

use of org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan in project flink by apache.

the class PushLocalAggIntoScanRuleBase method canPushDown.

protected boolean canPushDown(RelOptRuleCall call, BatchPhysicalGroupAggregateBase aggregate, BatchPhysicalTableSourceScan tableSourceScan) {
    TableConfig tableConfig = ShortcutUtils.unwrapContext(call.getPlanner()).getTableConfig();
    if (!tableConfig.getConfiguration().getBoolean(OptimizerConfigOptions.TABLE_OPTIMIZER_SOURCE_AGGREGATE_PUSHDOWN_ENABLED)) {
        return false;
    }
    if (aggregate.isFinal() || aggregate.getAggCallList().isEmpty()) {
        return false;
    }
    List<AggregateCall> aggCallList = JavaScalaConversionUtil.toJava(aggregate.getAggCallList());
    for (AggregateCall aggCall : aggCallList) {
        if (aggCall.isDistinct() || aggCall.isApproximate() || aggCall.getArgList().size() > 1 || aggCall.hasFilter() || !aggCall.getCollation().getFieldCollations().isEmpty()) {
            return false;
        }
    }
    TableSourceTable tableSourceTable = tableSourceScan.tableSourceTable();
    // we can not push aggregates twice
    return tableSourceTable != null && tableSourceTable.tableSource() instanceof SupportsAggregatePushDown && Arrays.stream(tableSourceTable.abilitySpecs()).noneMatch(spec -> spec instanceof AggregatePushDownSpec);
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) SupportsAggregatePushDown(org.apache.flink.table.connector.source.abilities.SupportsAggregatePushDown) Arrays(java.util.Arrays) RexProgram(org.apache.calcite.rex.RexProgram) AggregatePushDownSpec(org.apache.flink.table.planner.plan.abilities.source.AggregatePushDownSpec) SourceAbilityContext(org.apache.flink.table.planner.plan.abilities.source.SourceAbilityContext) RexNodeExtractor(org.apache.flink.table.planner.plan.utils.RexNodeExtractor) ShortcutUtils(org.apache.flink.table.planner.utils.ShortcutUtils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) ArrayList(java.util.ArrayList) OptimizerConfigOptions(org.apache.flink.table.api.config.OptimizerConfigOptions) BatchPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalCalc) RelOptRuleOperand(org.apache.calcite.plan.RelOptRuleOperand) RexNode(org.apache.calcite.rex.RexNode) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) TableConfig(org.apache.flink.table.api.TableConfig) ProjectPushDownSpec(org.apache.flink.table.planner.plan.abilities.source.ProjectPushDownSpec) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan) BatchPhysicalGroupAggregateBase(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalGroupAggregateBase) Collectors(java.util.stream.Collectors) 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) RexInputRef(org.apache.calcite.rex.RexInputRef) RelOptRule(org.apache.calcite.plan.RelOptRule) List(java.util.List) BatchPhysicalExchange(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalExchange) FlinkStatistic(org.apache.flink.table.planner.plan.stats.FlinkStatistic) JavaScalaConversionUtil(org.apache.flink.table.planner.utils.JavaScalaConversionUtil) AggregateCall(org.apache.calcite.rel.core.AggregateCall) Collections(java.util.Collections) AggregatePushDownSpec(org.apache.flink.table.planner.plan.abilities.source.AggregatePushDownSpec) TableConfig(org.apache.flink.table.api.TableConfig) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) SupportsAggregatePushDown(org.apache.flink.table.connector.source.abilities.SupportsAggregatePushDown)

Example 13 with BatchPhysicalTableSourceScan

use of org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan in project flink by apache.

the class PushLocalSortAggWithSortIntoScanRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    BatchPhysicalGroupAggregateBase localSortAgg = call.rel(1);
    BatchPhysicalTableSourceScan oldScan = call.rel(3);
    pushLocalAggregateIntoScan(call, localSortAgg, oldScan);
}
Also used : BatchPhysicalGroupAggregateBase(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalGroupAggregateBase) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan)

Example 14 with BatchPhysicalTableSourceScan

use of org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan in project flink by apache.

the class PushLocalSortAggWithSortIntoScanRule method matches.

@Override
public boolean matches(RelOptRuleCall call) {
    BatchPhysicalGroupAggregateBase localAggregate = call.rel(1);
    BatchPhysicalTableSourceScan tableSourceScan = call.rel(3);
    return canPushDown(call, localAggregate, tableSourceScan);
}
Also used : BatchPhysicalGroupAggregateBase(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalGroupAggregateBase) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan)

Aggregations

BatchPhysicalTableSourceScan (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan)14 BatchPhysicalCalc (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalCalc)7 BatchPhysicalGroupAggregateBase (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalGroupAggregateBase)5 BatchPhysicalLocalHashAggregate (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalLocalHashAggregate)4 BatchPhysicalLocalSortAggregate (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalLocalSortAggregate)4 AggregateCall (org.apache.calcite.rel.core.AggregateCall)2 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)2 AggregatePushDownSpec (org.apache.flink.table.planner.plan.abilities.source.AggregatePushDownSpec)2 SourceAbilitySpec (org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec)2 BatchPhysicalExchange (org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalExchange)2 TableSourceTable (org.apache.flink.table.planner.plan.schema.TableSourceTable)2 RowType (org.apache.flink.table.types.logical.RowType)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RelOptRule (org.apache.calcite.plan.RelOptRule)1 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)1 RelOptRuleOperand (org.apache.calcite.plan.RelOptRuleOperand)1