use of org.apache.flink.table.planner.plan.schema.TableSourceTable 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);
}
use of org.apache.flink.table.planner.plan.schema.TableSourceTable 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);
}
use of org.apache.flink.table.planner.plan.schema.TableSourceTable in project flink by apache.
the class PushProjectIntoTableSourceScanRule method getPrimaryKeyProjections.
private List<RexNode> getPrimaryKeyProjections(LogicalTableScan scan) {
final TableSourceTable source = scan.getTable().unwrap(TableSourceTable.class);
final ResolvedSchema schema = source.contextResolvedTable().getResolvedSchema();
if (!schema.getPrimaryKey().isPresent()) {
return Collections.emptyList();
}
final FlinkTypeFactory typeFactory = unwrapTypeFactory(scan);
final UniqueConstraint primaryKey = schema.getPrimaryKey().get();
return primaryKey.getColumns().stream().map(columnName -> {
final int idx = scan.getRowType().getFieldNames().indexOf(columnName);
final Column column = schema.getColumn(idx).orElseThrow(() -> new TableException(String.format("Column at index %d not found.", idx)));
return new RexInputRef(idx, typeFactory.createFieldTypeFromLogicalType(column.getDataType().getLogicalType()));
}).collect(Collectors.toList());
}
use of org.apache.flink.table.planner.plan.schema.TableSourceTable in project flink by apache.
the class PushProjectIntoTableSourceScanRule method getProjections.
private List<RexNode> getProjections(LogicalProject project, LogicalTableScan scan) {
final TableSourceTable source = scan.getTable().unwrap(TableSourceTable.class);
final TableConfig tableConfig = unwrapContext(scan).getTableConfig();
final List<RexNode> projections = new ArrayList<>(project.getProjects());
if (supportsProjectionPushDown(source.tableSource()) && requiresPrimaryKey(source, tableConfig)) {
projections.addAll(getPrimaryKeyProjections(scan));
}
return projections;
}
use of org.apache.flink.table.planner.plan.schema.TableSourceTable in project flink by apache.
the class DynamicSourceUtils method pushTableScan.
private static void pushTableScan(boolean isBatchMode, FlinkRelBuilder relBuilder, ContextResolvedTable contextResolvedTable, FlinkStatistic statistic, List<RelHint> hints, DynamicTableSource tableSource) {
final RowType producedType = createProducedType(contextResolvedTable.getResolvedSchema(), tableSource);
final RelDataType producedRelDataType = relBuilder.getTypeFactory().buildRelNodeRowType(producedType);
final TableSourceTable tableSourceTable = new TableSourceTable(relBuilder.getRelOptSchema(), producedRelDataType, statistic, tableSource, !isBatchMode, contextResolvedTable, ShortcutUtils.unwrapContext(relBuilder), new SourceAbilitySpec[0]);
final LogicalTableScan scan = LogicalTableScan.create(relBuilder.getCluster(), tableSourceTable, hints);
relBuilder.push(scan);
}
Aggregations