fhueske opened a new pull request, #30222:
URL: https://github.com/apache/flink/pull/30222
## What is the purpose of the change
`ProjectFilterTransposeRule` pushes only top-level columns below a filter.
If a query reads only some fields of a ROW column, a filter therefore stops the
nested projection, and the operators below the filter process the whole ROW.
For a source that supports nested projection pushdown, a filter that cannot be
pushed into the source makes the source read whole ROW columns:
```sql
SELECT id, deepNested.nested1.name FROM T WHERE nested.`value` > 0 AND
deepNested.nested2.num > 0
```
```
before: TableSourceScan(table=[[..., T, filter=[], project=[id, deepNested,
nested]]], ...)
after: TableSourceScan(table=[[..., T, filter=[], project=[id,
deepNested_nested1_name, deepNested_nested2_num, nested_value]]], ...)
```
This pull request adds a rule that pushes the accessed nested fields below
the filter.
## Brief change log
- Add `ProjectNestedFieldFilterTransposeRule`. It extracts the nested
fields that the project and the filter condition access into flat columns of a
project below the filter, and rewrites the condition and the project above the
filter to read these columns. Only field accesses are pushed. All other
expressions stay above the filter, which still guards them. The rule only fires
if a ROW column has an unused field, so it does not match its own output.
- Add `NestedProjectionUtil.rewriteForFilter`, which reuses the helpers of
`rewriteForJoin` (FLINK-41410).
- Register the rule in `PROJECT_RULES` for streaming and, in a separate
commit, for batch.
- Hotfix: `NestedProjectionUtilJoinTest` created all row types as
`FULLY_QUALIFIED` structs, whose fields become nullable when the struct is made
nullable. Its tests for a NOT NULL field of a nullable ROW therefore never had
a NOT NULL field. The test now uses the struct kinds of the planner:
`PEEK_FIELDS_NO_EXPAND` for ROW columns, `FULLY_QUALIFIED` for join inputs.
The rule is not behind a feature flag: it only moves field accesses, which
are cheap and cannot fail (a field of a NULL row is NULL), and compiled plans
are not affected. The only existing plan that changes is
`NonDeterministicDagTest#testNestedSourceWithMultiSink`: the filtered sink no
longer makes the shared scan read the whole ROW column.
## Verifying this change
Please make sure both new and modified tests in this PR follow [the
conventions for tests defined in our code quality
guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
This change added tests and can be verified as follows:
- `ProjectNestedFieldFilterTransposeRuleTest`: plan tests for the rule. A
condition on a sibling field or on another ROW column, deep nesting, an
expression that stays above the filter, and a NOT NULL field of a nullable ROW.
The rule does not fire if a ROW is read whole or if all of its fields are read.
- `NestedProjectionUtilFilterTest`: unit tests for `rewriteForFilter`.
Column order and pruning of unused columns, deep nesting, a ROW read whole and
deeper, nullability, expressions that are not pushed, and field names that
differ only in case.
- `TableSourceTest` (streaming and batch): the nested fields reach the
source behind a filter that cannot be pushed into the source.
- `TableSourceITCase` (streaming and batch): results for a filter that
guards a division, and for `IS NULL` on a NOT NULL field of a nullable ROW. The
latter uses a source without nested projection pushdown because of FLINK-41766
(#30220), which fixes the pushdown of NOT NULL fields of nullable ROW columns
into sources.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Claude Opus 5.5)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]