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

   ## What is the purpose of the change
   
   `ProjectWatermarkAssignerTransposeRule` moves a pruning projection below the 
`WatermarkAssigner`, so that the projection can be pushed into the source 
afterwards. Until now, the rule forwarded every used ROW column as a whole. If 
a table defines a watermark, a source that supports nested projection therefore 
still reads all sub-fields of a ROW column even if the query only accesses some 
of them:
   
   ```sql
   CREATE TABLE NestedTable (
     a INT,
     b BIGINT,
     c ROW<name STRING, d ROW<e STRING, f TIMESTAMP(3)>>,
     g AS c.d.f,
     WATERMARK FOR g AS g - INTERVAL '5' SECOND
   ) WITH ('connector' = 'values', 'nested-projection-supported' = 'true', ...);
   
   SELECT c.e, c.d FROM NestedTable
   ```
   
   Before this change, the source reads `project=[c]`. Now it reads 
`project=[c_d]`, i.e., `c.name` is pruned, and the watermark is still pushed 
into the source.
   
   ## Brief change log
   
     - `ProjectWatermarkAssignerTransposeRule` forwards only the used nested 
fields to the transposed projection, as field accesses such as `d_d1=[$3.d1]`.
     - The rule also fires if all top-level columns are used but a ROW column 
is only partially accessed.
     - The rowtime column is always added to the used fields, so it no longer 
needs special handling.
     - The watermark expression and the projection above the assigner are 
rewritten with `NestedProjectionUtil#rewrite`. A new overload takes the types 
of the new input fields, because the declared type of a nested field doesn't 
account for the nullability of the enclosing row or for the rowtime indicator. 
This overload is the same as the private one added in #30097, except that it is 
public here.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - `ProjectWatermarkAssignerTransposeRuleTest`: new plan tests for a ROW 
column that is only partially accessed while all top-level columns are used, 
nesting depth > 1, a ROW field that is accessed both whole and partially, a NOT 
NULL field nested in a nullable row, a field name collision, and a watermark 
that doesn't reference its rowtime column. The plans of the existing nested 
cases are updated.
     - `SourceWatermarkTest#testWatermarkOnNestedRowWithNestedProjection`: the 
source now reads `project=[c_d]` instead of `project=[c]`.
     - `ScanReuseTest`: the streaming plans of the three nested-projection 
cases change. In `testProjectNested1/2`, the reused scan reads only the 
accessed sub-fields of `nested`. In `testProjectNestedWithWholeField`, the 
reused scan reads both `nested` and its sub-fields `nested_i`, `nested_s`. This 
is a known limitation of `ScanReuser`, which merges the projections of the 
reused scans without removing paths that are covered by a shorter path. The 
batch plan of the same test already shows it (`project=[a, nested, nested_i]`). 
I'll address it in a separate issue.
     - `SourceWatermarkITCase` and `TableSourceITCase` (stream and batch) pass.
   
   ## 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)
   


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