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

   ## What is the purpose of the change
   
   This pull request excludes the VARIANT data type from constant folding 
VARIANT expressions. This previously resulted in a `ClassCastException` when 
running a query such as the following, where a constant expression followed a 
VARIANT expression in the projection. 
   ```sql
   SELECT PARSE_JSON('{}'), JSON_STRING(PARSE_JSON('{}'));
   ```
   
   The `ExpressionReducer.scala` in `flink-table-planner` evaluates constant 
sub-expressions, so they get computed during compile-time and not during query 
run-time. It runs in two passes that must agree on which types get a slot in 
the intermediate (compile-time) result:
   
   - **Phase 1** excludes unsupported "object literal" types 
(ROW/ARRAY/MAP/MULTISET/...) from compile-time evaluation. **VARIANT** was 
previously missing from this list and was therefore evaluated at compile-time 
and added to the intermediate result list.
   - **Phase 2** has an specific case for VARIANT and treats VARIANT as 
excluded from compile-time evaluation. So a VARIANT constant gets evaluated and 
occupies a real slot in phase 1, but phase 2 doesn't know that and never 
advances its slot index. Then the next reduced expression reads the stale slot 
containing the VARIANT data and crashes on the bad cast.
   
   
   ## Brief change log
   
     - Adds **VARIANT** to the exclude list of data types that use constant 
folding
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added test in `JsonFunctionsITCase.java` for VARIANT, where constant 
folding is enabled
    
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: (yes / **no**)
     - The serializers: (yes / **no** / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / **no** 
/ don't know)
     - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / **no** / don't 
know)
     - The S3 file system connector: (yes / **no** / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / **no**)
     - If yes, how is the feature documented? (**not applicable** / docs / 
JavaDocs / not documented)
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change the checkbox below to `[X]` and replace the placeholder in the 
"Generated-by"
   line with the tool name and version. Otherwise remove the "Generated-by" 
line.
   See the ASF Generative Tooling Guidance for details:
   https://www.apache.org/legal/generative-tooling.html
   
   You are responsible for the quality and correctness of every change in this 
PR
   regardless of the tooling used. Low-effort AI-generated PRs will be closed. 
See
   AGENTS.md for the full guidance.
   -->
   
   - [x] Yes (please specify the tool below)
   
   Generated-by: Claude Sonnet 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