use of org.apache.flink.table.connector.source.abilities.SupportsPartitionPushDown in project flink by apache.
the class PushPartitionIntoTableSourceScanRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
Filter filter = call.rel(0);
if (filter.getCondition() == null) {
return false;
}
TableSourceTable tableSourceTable = call.rel(1).getTable().unwrap(TableSourceTable.class);
if (tableSourceTable == null) {
return false;
}
DynamicTableSource dynamicTableSource = tableSourceTable.tableSource();
if (!(dynamicTableSource instanceof SupportsPartitionPushDown)) {
return false;
}
CatalogTable catalogTable = tableSourceTable.contextResolvedTable().getTable();
if (!catalogTable.isPartitioned() || catalogTable.getPartitionKeys().isEmpty()) {
return false;
}
return Arrays.stream(tableSourceTable.abilitySpecs()).noneMatch(spec -> spec instanceof PartitionPushDownSpec);
}
use of org.apache.flink.table.connector.source.abilities.SupportsPartitionPushDown in project flink by apache.
the class PushPartitionIntoTableSourceScanRule method readPartitionsAndPrune.
private List<Map<String, String>> readPartitionsAndPrune(RexBuilder rexBuilder, FlinkContext context, TableSourceTable tableSourceTable, Function<List<Map<String, String>>, List<Map<String, String>>> pruner, Seq<RexNode> partitionPredicate, List<String> inputFieldNames) {
// get partitions from table/catalog and prune
Optional<Catalog> catalogOptional = tableSourceTable.contextResolvedTable().getCatalog();
DynamicTableSource dynamicTableSource = tableSourceTable.tableSource();
Optional<List<Map<String, String>>> optionalPartitions = ((SupportsPartitionPushDown) dynamicTableSource).listPartitions();
if (optionalPartitions.isPresent()) {
return pruner.apply(optionalPartitions.get());
} else {
// we will read partitions from catalog if table doesn't support listPartitions.
if (!catalogOptional.isPresent()) {
throw new TableException(String.format("Table '%s' connector doesn't provide partitions, and it cannot be loaded from the catalog", tableSourceTable.contextResolvedTable().getIdentifier().asSummaryString()));
}
try {
return readPartitionFromCatalogAndPrune(rexBuilder, context, catalogOptional.get(), tableSourceTable.contextResolvedTable().getIdentifier(), inputFieldNames, partitionPredicate, pruner);
} catch (TableNotExistException tableNotExistException) {
throw new TableException(String.format("Table %s is not found in catalog.", tableSourceTable.contextResolvedTable().getIdentifier().asSummaryString()));
} catch (TableNotPartitionedException tableNotPartitionedException) {
throw new TableException(String.format("Table %s is not a partitionable source. Validator should have checked it.", tableSourceTable.contextResolvedTable().getIdentifier().asSummaryString()), tableNotPartitionedException);
}
}
}
Aggregations