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

   ## What is the purpose of the change                                         
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
   `CREATE TABLE AS SELECT` and `REPLACE TABLE AS SELECT` over a set-semantic 
process table function (a table argument with `PARTITION BY`) failed during 
planning with `IllegalStateException: must call validate first`. The AS-query 
was validated twice, and a set-semantics input table only sets up its namespace 
on the first validation. This change validates the AS-query exactly once, so 
CTAS/RTAS over such a PTF plans correctly.                                      
                                                                                
                                                                                
                 
                                                                                
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
   ## Brief change log                                                          
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
     - `SqlCreateTableAsConverter`: removed the redundant pre-validation of the 
AS-query (RTAS never had it), so the query is validated only once.              
                                                                                
                                                                                
    
     - `MergeTableAsUtil.maybeRewriteQuery`: reconcile the query's columns with 
the sink as a relational projection on top of the already-converted plan 
(reorder existing columns, fill missing ones with `NULL`), instead of 
rebuilding the query as SQL and re-validating it. Returns the query unchanged 
when no reshaping is needed.                                                    
                                                                                
                                                                                
                                                                                
                      
     - Side effect: an explicit reordered column list over a set-semantic PTF 
now works too.                                                                  
                                                                                
                                                                                
      
                                                                                
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
   ## Verifying this change                                                     
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
   This change added tests and can be verified as follows:                      
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
     - Conversion tests in `SqlCTASNodeToOperationTest` / 
`SqlRTASNodeToOperationConverterTest` (set-semantic PTF, basic and 
reordered-column cases).                                                        
                                                                                
                                       
     - Plan tests in `TableSinkTest` (CTAS/RTAS over a set-semantic PTF, a CTE 
over the PTF, and metadata/computed/virtual columns in the CREATE part, plus a 
NOT NULL negative case).                                                        
                                                                                
      
     - Runtime IT cases in `TableSinkITCase` (CTAS) and `RTASITCase` (plain 
REPLACE) asserting the reconciled rows and derived schema.                      
                                                                                
                                                                                
        
     - Added a `SqlMaterializedTableNodeToOperationConverterTest` case 
confirming `CREATE MATERIALIZED TABLE AS` over the same PTF is unaffected.      
                                                                                
                                                                                
             
                                                                                
                                                                                
                                                                                
                                                                                
    
                                                                                
                                                                                
                                                                                
                                                                                
    
   ## 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 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