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

   ## What is the purpose of the change
                                                            
   Add `CAST` and `TRY_CAST` from `VARIANT` to primitive scalar types 
(FLIP-521, sub-task FLINK-37925). Previously a `VARIANT` could only be read as 
another variant or rendered to a JSON string, with no way to extract a typed 
scalar out of it.
                                                                                
                             
   ## Brief change log
                                                                                
                  
     - Add `VariantToPrimitiveCastRule` (registered in `CastRuleProvider`) 
covering BOOLEAN, all integer/floating/decimal numerics,   
   BINARY/VARBINARY, DATE, TIMESTAMP and TIMESTAMP_LTZ.                         
                                                      
     - Numeric targets are lenient: any numeric variant converts following the 
regular numeric cast semantics. Non-numeric targets require the stored value to 
match the target kind.                                                          
                       
     - On a type mismatch `CAST` fails the job and `TRY_CAST` returns `NULL`.   
                                                      
     - Permit the cast at planner validation time via a `VARIANT` source branch 
in `LogicalTypeCasts` (explicit only).                
     - Out of scope: CHARACTER_STRING (already served by the JSON display rule 
and `JSON_STRING`), `TIME` (no counterpart in the variant type model), and 
constructed types ARRAY/ROW/STRUCTURED (tracked in FLINK-37926).                
                          
                                                                                
                                                      
   ## Verifying this change                                                     
                                                      
                                                                                
                                                      
   This change added tests and can be verified as follows:                      
                                                      
                                                                                
                                                      
   - `CastRulesTest`: variant → each supported scalar, covering success, type 
mismatch (`CAST` throws), and null inputs.            
   - `CastRuleProviderTest`: the rule resolves for supported targets.           
                                                    
   - `LogicalTypeCastsTest`: explicit-cast support matrix, including that 
TIME/STRING/ARRAY and all implicit casts are rejected.    
   - `CastFunctionITCase`: end-to-end `CAST`/`TRY_CAST` over `PARSE_JSON(...)`. 
                                                    
                                                                                
                                                      
   ## 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? yes                        
                                                    
   - If yes, how is the feature documented? docs (VARIANT casting section in 
`data-types.md`) and JavaDocs                          
                                                                                
                                                      
   ---                                                                          
                                                      
                                                                                
                                                      
   ##### Was generative AI tooling used to co-author this PR?                   
                                                      
                                                                                
                                                      
   - [X] Yes
   
   Opus 4.8


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