jnh5y commented on code in PR #28556:
URL: https://github.com/apache/flink/pull/28556#discussion_r4317897900
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/PushFilterIntoSourceScanRuleBase.java:
##########
@@ -137,72 +208,43 @@ protected boolean
canPushdownMetadataFilter(TableSourceTable tableSourceTable) {
.noneMatch(spec -> spec instanceof MetadataFilterPushDownSpec);
}
- /**
- * True if predicate references metadata columns exclusively (no physical
columns).
- *
- * <p>A predicate like {@code OR(physical_pred, metadata_pred)} returns
false because it
- * references both physical and metadata columns. Mixed predicates remain
as runtime filters.
- */
- protected boolean referencesOnlyMetadataColumns(RexNode predicate, int
physicalColumnCount) {
- boolean[] saw = new boolean[2]; // [0] = sawPhysical, [1] = sawMetadata
- predicate.accept(
- new RexVisitorImpl<Void>(true) {
- @Override
- public Void visitInputRef(RexInputRef inputRef) {
- if (inputRef.getIndex() >= physicalColumnCount) {
- saw[1] = true;
- } else {
- saw[0] = true;
- }
- return null;
- }
- });
- return saw[1] && !saw[0];
+ private enum FilterColumnKind {
+ PHYSICAL_ONLY,
+ METADATA_ONLY,
+ MIXED
}
- /** Number of physical columns in the scan's schema. */
- protected int getPhysicalColumnCount(TableSourceTable tableSourceTable) {
- ResolvedSchema schema =
tableSourceTable.contextResolvedTable().getResolvedSchema();
- return (int)
schema.getColumns().stream().filter(Column::isPhysical).count();
- }
-
- /** Maps SQL column names to metadata keys for metadata columns. */
- protected Map<String, String> buildColumnToMetadataKeyMap(TableSourceTable
tableSourceTable) {
- ResolvedSchema schema =
tableSourceTable.contextResolvedTable().getResolvedSchema();
- Map<String, String> mapping = new HashMap<>();
- for (Column col : schema.getColumns()) {
- if (col instanceof Column.MetadataColumn) {
- Column.MetadataColumn metaCol = (Column.MetadataColumn) col;
- String sqlName = metaCol.getName();
- String metadataKey = metaCol.getMetadataKey().orElse(sqlName);
- mapping.put(sqlName, metadataKey);
- }
+ private static FilterColumnKind classifyColumns(RexNode predicate, int
firstMetadataIndex) {
+ ImmutableBitSet columns = RelOptUtil.InputFinder.bits(predicate);
+ boolean referencesMetadata = columns.nextSetBit(firstMetadataIndex) >=
0;
+ boolean referencesPhysical = !columns.get(0,
firstMetadataIndex).isEmpty();
+ if (referencesMetadata && referencesPhysical) {
+ return FilterColumnKind.MIXED;
}
- return mapping;
+ return referencesMetadata ? FilterColumnKind.METADATA_ONLY :
FilterColumnKind.PHYSICAL_ONLY;
}
- /** Outcome of metadata filter push-down: updated table and runtime-Calc
predicates. */
- protected static final class MetadataPushDownOutcome {
- final TableSourceTable newTableSourceTable;
- final List<RexNode> remainingInputRexNodes;
-
- MetadataPushDownOutcome(
- TableSourceTable newTableSourceTable, List<RexNode>
remainingInputRexNodes) {
- this.newTableSourceTable = newTableSourceTable;
- this.remainingInputRexNodes = remainingInputRexNodes;
- }
+ /** Keys of the {@link ReadingMetadataSpec}, in the order of the scan's
trailing fields. */
+ private static List<String> getReadMetadataKeys(TableSourceTable
tableSourceTable) {
+ ReadingMetadataSpec spec =
+ ScanReuserUtils.getAbilitySpec(
+ tableSourceTable.abilitySpecs(),
ReadingMetadataSpec.class);
+ return spec == null ? Collections.emptyList() : spec.getMetadataKeys();
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]