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

   ## What is the purpose of the change
   
   This pull request fixes the issue that the `EXPLAIN PLAN FOR INSERT` with 
static partition spec produces the wrong query schema.
   
   During the conversion phase, the query will be validated and rewritten by 
`PreValidateReWriter`, and 
`PreValidateReWriter#appendPartitionAndNullsProjects` will perform the 
following 
rewrite(https://github.com/apache/flink/blob/master/flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/calcite/PreValidateReWriter.scala#L89).
   ```sql
   -- before rewrite
   insert into A partition(a='11',
    c='22') select b from B
   
   -- after rewrite
   insert into A partition(a='11', c='22') select cast('11' as tpe1), b, 
cast('22' as tpe2) from B
   ```
   However, the `SqlRichExplain` are first validated as a whole and then got 
its statement validated again, thus the insert query is rewritten twice, which 
causes the issue.
   
   ## Brief change log
     - For `SqlRichExplain`, let`FlinkPlannerImpl` validate the insert's source 
instead of insert.
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Add `TableEnvironmentTest#testExecuteSqlWithExplainInsertStaticPartition`
     - Add it case in `table.q`
    
   
   ## 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)
   


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