LantaoJin opened a new pull request #29201:
URL: https://github.com/apache/spark/pull/29201


   ### What changes were proposed in this pull request?
   The backport of #29062
   
   This PR is to move `Substitution` rule before `Hints` rule in `Analyzer` to 
avoid hint in CTE not working.
   
   ### Why are the changes needed?
   Below SQL in Spark3.0 will throw AnalysisException, but it works in Spark2.x
   ```sql
   WITH cte AS (SELECT /*+ REPARTITION(3) */ T.id, T.data FROM $t1 T)
   SELECT cte.id, cte.data FROM cte
   ```
   ```
   Failed to analyze query: org.apache.spark.sql.AnalysisException: cannot 
resolve '`cte.id`' given input columns: [cte.data, cte.id]; line 3 pos 7;
   'Project ['cte.id, 'cte.data]
   +- SubqueryAlias cte
      +- Project [id#21L, data#22]
         +- SubqueryAlias T
            +- SubqueryAlias testcat.ns1.ns2.tbl
               +- RelationV2[id#21L, data#22] testcat.ns1.ns2.tbl
   
   'Project ['cte.id, 'cte.data]
   +- SubqueryAlias cte
      +- Project [id#21L, data#22]
         +- SubqueryAlias T
            +- SubqueryAlias testcat.ns1.ns2.tbl
               +- RelationV2[id#21L, data#22] testcat.ns1.ns2.tbl
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   ### How was this patch tested?
   Add a unit test
   


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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to