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

   ## What is the purpose of the change
   
   In the Table API, a `CAST` to a target written with `.notNull()` was planned 
as `NOT NULL` even when the input may be null. The `CAST` type strategy already 
derives a nullable result, but `CastConverter` built the RexNode from the 
literal target type. The optimizer trusted the wrong `NOT NULL` and could fold 
null checks away. For example, `$("i").cast(BIGINT().notNull())` over a 
nullable `i` followed by `.filter($("c").isNull())` returned no rows instead of 
the null row.
   
   FLINK-40672 fixed this only for a top-level `VARIANT` input. Nested inputs 
such as `ARRAY<VARIANT>` and plain nullable scalars were still affected. SQL is 
not affected: a SQL `CAST` cannot declare `NOT NULL` on the target, and 
`SqlCastFunction.deriveType` takes the nullability from the input.
   
   ## Brief change log
   
     - `CastConverter` uses the resolved output type of the call instead of the 
literal target type, which aligns the Table API with SQL for all casts.
     - The `cast()` Javadoc states that the top-level nullability of the target 
type is ignored.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added cases to `ExpressionConverterTest` for a nullable input cast to a 
`NOT NULL` target, a nested `VARIANT` input, and a `NOT NULL` input cast to a 
nullable target. All three fail without the fix.
     - Existing planner plan, expression, cast and runtime Table API tests pass 
unchanged.
   
   ## 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. Only the Javadoc of `cast()` changes.
     - 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: 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