Search in sources :

Example 1 with BatchPhysicalTableSourceScan

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

the class PushLocalAggIntoScanRuleBase method pushLocalAggregateIntoScan.

protected void pushLocalAggregateIntoScan(RelOptRuleCall call, BatchPhysicalGroupAggregateBase localAgg, BatchPhysicalTableSourceScan oldScan, int[] calcRefFields) {
    RowType inputType = FlinkTypeFactory.toLogicalRowType(oldScan.getRowType());
    List<int[]> groupingSets = Collections.singletonList(ArrayUtils.addAll(localAgg.grouping(), localAgg.auxGrouping()));
    List<AggregateCall> aggCallList = JavaScalaConversionUtil.toJava(localAgg.getAggCallList());
    // map arg index in aggregate to field index in scan through referred fields by calc.
    if (calcRefFields != null) {
        groupingSets = translateGroupingArgIndex(groupingSets, calcRefFields);
        aggCallList = translateAggCallArgIndex(aggCallList, calcRefFields);
    }
    RowType producedType = FlinkTypeFactory.toLogicalRowType(localAgg.getRowType());
    TableSourceTable oldTableSourceTable = oldScan.tableSourceTable();
    DynamicTableSource newTableSource = oldScan.tableSource().copy();
    boolean isPushDownSuccess = AggregatePushDownSpec.apply(inputType, groupingSets, aggCallList, producedType, newTableSource, SourceAbilityContext.from(oldScan));
    if (!isPushDownSuccess) {
        // aggregate push down failed, just return without changing any nodes.
        return;
    }
    // create new source table with new spec and statistic.
    AggregatePushDownSpec aggregatePushDownSpec = new AggregatePushDownSpec(inputType, groupingSets, aggCallList, producedType);
    TableSourceTable newTableSourceTable = oldTableSourceTable.copy(newTableSource, localAgg.getRowType(), new SourceAbilitySpec[] { aggregatePushDownSpec }).copy(FlinkStatistic.UNKNOWN());
    // transform to new nodes.
    BatchPhysicalTableSourceScan newScan = oldScan.copy(oldScan.getTraitSet(), newTableSourceTable);
    BatchPhysicalExchange oldExchange = call.rel(0);
    BatchPhysicalExchange newExchange = oldExchange.copy(oldExchange.getTraitSet(), newScan, oldExchange.getDistribution());
    call.transformTo(newExchange);
}
Also used : AggregateCall(org.apache.calcite.rel.core.AggregateCall) SourceAbilitySpec(org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec) AggregatePushDownSpec(org.apache.flink.table.planner.plan.abilities.source.AggregatePushDownSpec) RowType(org.apache.flink.table.types.logical.RowType) TableSourceTable(org.apache.flink.table.planner.plan.schema.TableSourceTable) BatchPhysicalExchange(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalExchange) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan)

Example 2 with BatchPhysicalTableSourceScan

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

the class PushLocalHashAggWithCalcIntoScanRule method matches.

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

Example 3 with BatchPhysicalTableSourceScan

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

the class PushLocalHashAggWithCalcIntoScanRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    BatchPhysicalLocalHashAggregate localHashAgg = call.rel(1);
    BatchPhysicalCalc calc = call.rel(2);
    BatchPhysicalTableSourceScan oldScan = call.rel(3);
    int[] calcRefFields = getRefFiledIndex(calc);
    pushLocalAggregateIntoScan(call, localHashAgg, oldScan, calcRefFields);
}
Also used : BatchPhysicalLocalHashAggregate(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalLocalHashAggregate) BatchPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalCalc) BatchPhysicalTableSourceScan(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalTableSourceScan)

Example 4 with BatchPhysicalTableSourceScan

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

the class PushLocalSortAggWithCalcIntoScanRule method matches.

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

Example 5 with BatchPhysicalTableSourceScan

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

the class PushLocalSortAggWithCalcIntoScanRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    BatchPhysicalLocalSortAggregate localHashAgg = call.rel(1);
    BatchPhysicalCalc calc = call.rel(2);
    BatchPhysicalTableSourceScan oldScan = call.rel(3);
    int[] calcRefFields = getRefFiledIndex(calc);
    pushLocalAggregateIntoScan(call, localHashAgg, oldScan, calcRefFields);
}
Also used : BatchPhysicalLocalSortAggregate(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalLocalSortAggregate) BatchPhysicalCalc(org.apache.flink.table.planner.plan.nodes.physical.batch.BatchPhysicalCalc) 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