snuyanzin commented on code in PR #28556:
URL: https://github.com/apache/flink/pull/28556#discussion_r4296025963
##########
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();
Review Comment:
such `get` make extra allocation
can we replace it with something like
```java
int firstPhysical = columns.nextSetBit(0);
boolean referencesPhysical = firstPhysical >= 0 && firstPhysical <
firstMetadataIndex;
```
##########
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();
Review Comment:
nit:
such `get` make extra allocation
can we replace it with something like
```java
int firstPhysical = columns.nextSetBit(0);
boolean referencesPhysical = firstPhysical >= 0 && firstPhysical <
firstMetadataIndex;
```
--
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]