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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations