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

   ## What is the purpose of the change
   
   Backport of #30220 (FLINK-41766) to `release-2.4`.
   
   When a source supports nested projection push-down, a `NOT NULL` field of a 
nullable `ROW` column was pushed into the scan with its declared `NOT NULL` 
type, although it is nullable when read through the nullable `ROW`. This made 
planning fail with `type mismatch: INTEGER NOT NULL vs INTEGER` (e.g. `SELECT 
ns.v, ns.w FROM T`), or, if the field only appeared inside an expression, 
produced wrong results because null checks were optimized away (e.g. `ns.v IS 
NULL` returned `false` for a NULL `ns`).
   
   A projected nested field is now nullable if any `ROW` on its access path is 
nullable.
   
   ## Brief change log
   
   This is a cherry-pick of the merged commit (`git cherry-pick -x 7494dd0`) 
with one addition:
   
     - `NestedProjectionUtil`: the typed `rewrite(..., leafTypes)` overload and 
the `leafTypes` hook in `NestedSchemaRewriter` do not exist on `release-2.4` 
(they came with other nested projection work on master), so they are added 
here, identical to master. Without them the cherry-picked 
`PushProjectIntoTableSourceScanRule` change does not compile.
   
   Everything else is as in #30220:
   
     - `Projection#project`: the type of a projected nested field is made 
nullable if any `ROW` above it is nullable.
     - `PushProjectIntoTableSourceScanRule`: rewrite the project with the typed 
`NestedProjectionUtil.rewrite` overload.
     - `TestValuesTableFactory`: nested projection no longer fails with an NPE 
when a parent `ROW` is NULL.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows. Run on this branch: 
`ProjectionTest` (9 tests), `PushProjectIntoTableSourceScanRuleTest`, 
`ScanReuseTest`, and stream and batch `TableSourceITCase` (117 planner tests), 
all passing.
   
     - `ProjectionTest`: nested fields below nullable and NOT NULL `ROW`s.
     - `JsonFormatFactoryTest`: the JSON decoder gets a nullable type for a 
pushed NOT NULL field of a nullable `ROW` and decodes NULL parents.
     - `PushProjectIntoTableSourceScanRuleTest`, `ScanReuseTest`: plan tests 
for a `NOT NULL` field of a nullable `ROW` and one below a nullable `ROW`.
     - `TableSourceITCase` (stream and batch): NULL `ROW` values with `ns.v`, 
`ns.v + 1` and `ns.v IS NULL` / `COALESCE(ns.v, -1)`.
   
   ## 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 (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