fhueske opened a new pull request, #30097:
URL: https://github.com/apache/flink/pull/30097

   ## What is the purpose of the change
   
   When a query reads only a few fields of a ROW column, the join carries, 
shuffles, and stores the whole ROW, because the existing project/join transpose 
rules only work on top-level columns:
   
   ```
   SELECT o.id, o.customer.name FROM Orders o JOIN Shipments s ON o.id = 
s.order_id
   ```
   
   This PR adds `ProjectNestedFieldJoinTransposeRule`. It extracts the accessed 
nested fields into flat columns in a projection below each join input, and 
rewrites the join condition and the project above the join to read these 
columns. The join then carries only the accessed fields, which reduces join 
state and shuffle volume. Because the fields now sit directly above the scans, 
the existing nested projection push-down can move them into the source.
   
   The new rule only touches columns with nested field accesses. Unused 
top-level columns are not pruned; they pass through, and 
`FlinkProjectJoinTransposeRule` prunes them as before.
   
   ## Brief change log
   
     - Add `ProjectNestedFieldJoinTransposeRule` and register it in the 
streaming `PROJECT_RULES`.
     - Add `NestedProjectionUtil.rewriteForJoin`, which splits the accessed 
fields per join input and rewrites the condition and the project separately, 
with the nullability of outer joins taken into account.
     - The rule fires only if a ROW column has an unused field, so it does not 
match its own output. SEMI and ANTI joins are skipped (FLINK-41648).
     - `SimplifyCoalesceWithEquiJoinConditionRuleTest`: the plan of 
`testCoalesceOnNestedRowScalarField` changes. Its PRIMARY KEY is on a ROW 
column that is no longer carried into the join, so the join input uses 
`NoUniqueKey` instead of `HasUniqueKey`.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - `NestedProjectionUtilJoinTest`: unit tests for `rewriteForJoin` and 
`hasPrunableNestedLeaf` (nested depth, NOT NULL and nullable structs, outer 
joins, field names that differ only in case, accesses inside expressions).
     - `ProjectNestedFieldJoinTransposeRuleTest`: plan tests for the rule alone 
(inner, outer, three-way, nested depth, NOT NULL leaves).
     - `NestedProjectionJoinKindsTest`: plan tests with the full optimizer for 
temporal, interval, and lateral snapshot joins, and for a join input that 
nothing references.
     - `NestedFieldJoinProjectionITCase`: results with NULL structs, outer 
joins, self joins, nested depth > 1, nested accesses inside expressions, and a 
three-way join with a right join. Each test also asserts that no struct column 
is in the join.
     - The full `flink-table-planner` test suite passes locally.
     - For upsert sources and sinks (`values` connector with `I,UA,D`), I 
compared the plans with and without the change on eight join queries (inner, 
left, full, three-way, foreign-key, nested condition). The number of 
`ChangelogNormalize` operators, `upsertMaterialize`, the join input specs, and 
the changelog modes are identical. Only the projected columns differ.
   
   ## 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. Plans that are 
re-planned from SQL get a different state layout for joins over nested fields. 
Already compiled plans are not affected.
     - 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
   
   ## Known limitations
   
     - SEMI and ANTI joins are not handled yet (FLINK-41648).
     - A field that is both a join key and selected can appear twice in a join 
input, because Calcite already projects the join key below the join. The data 
was already carried before; it is just more visible now.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Sonnet 5.5)


-- 
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]

Reply via email to