wangyum commented on code in PR #41513:
URL: https://github.com/apache/spark/pull/41513#discussion_r1223820020


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala:
##########
@@ -4683,6 +4683,27 @@ class SQLQuerySuite extends QueryTest with 
SharedSparkSession with AdaptiveSpark
     ).observe("my_event", count("*"))
     df1.crossJoin(df1)
   }
+
+  test("SPARK-44007: Unresolved hint cause query failure") {
+    withTable("t0", "t1") {
+      sql("CREATE TABLE t0(c0 bigint) USING PARQUET")
+      sql("CREATE TABLE t1(c1 bigint) USING PARQUET")
+      sql(
+        """
+          |WITH
+          |w0 AS (SELECT * FROM t0),
+          |w1 AS (SELECT * FROM w0 group by c0),
+          |w2 AS (SELECT /*+ userHint(t1) */ c1 FROM t1 ),
+          |w3 AS (
+          |SELECT w2.c1, w0.c0, w1.c0
+          |FROM w2
+          |JOIN w0 on w2.c1 = w0.c0
+          |JOIN w1 on w2.c1 = w1.c0
+          |)
+          |SELECT * FROM w3;
+          |""".stripMargin)
+    }
+  }

Review Comment:
   I have tested this test case on the master branch and it seems that 
Unresolved Hints are successfully removed:
   ```
   12:03:33.688 ERROR org.apache.spark.sql.catalyst.rules.PlanChangeLogger: 
   === Result of Batch Remove Unresolved Hints ===
    WithCTE                                                                
WithCTE
    :- CTERelationDef 0, false, false                                      :- 
CTERelationDef 0, false, false
    :  +- SubqueryAlias w0                                                 :  
+- SubqueryAlias w0
    :     +- Project [c0#218L]                                             :    
 +- Project [c0#218L]
    :        +- SubqueryAlias spark_catalog.default.t0                     :    
    +- SubqueryAlias spark_catalog.default.t0
    :           +- Relation spark_catalog.default.t0[c0#218L] parquet      :    
       +- Relation spark_catalog.default.t0[c0#218L] parquet
    :- CTERelationDef 1, false, false                                      :- 
CTERelationDef 1, false, false
    :  +- SubqueryAlias w1                                                 :  
+- SubqueryAlias w1
    :     +- Aggregate [c0#218L], [c0#218L]                                :    
 +- Aggregate [c0#218L], [c0#218L]
    :        +- SubqueryAlias w0                                           :    
    +- SubqueryAlias w0
    :           +- CTERelationRef 0, true, [c0#218L], false                :    
       +- CTERelationRef 0, true, [c0#218L], false
    :- CTERelationDef 2, false, false                                      :- 
CTERelationDef 2, false, false
    :  +- SubqueryAlias w2                                                 :  
+- SubqueryAlias w2
   !:     +- !UnresolvedHint userHint, ['t1]                               :    
 +- Project [c1#219L]
   !:        +- Project [c1#219L]                                          :    
    +- SubqueryAlias spark_catalog.default.t1
   !:           +- SubqueryAlias spark_catalog.default.t1                  :    
       +- Relation spark_catalog.default.t1[c1#219L] parquet
   !:              +- Relation spark_catalog.default.t1[c1#219L] parquet   :- 
CTERelationDef 3, false, false
   !:- CTERelationDef 3, false, false                                      :  
+- SubqueryAlias w3
   !:  +- SubqueryAlias w3                                                 :    
 +- Project [c1#219L, c0#222L, c0#223L]
   !:     +- Project [c1#219L, c0#222L, c0#223L]                           :    
    +- Join Inner, (c1#219L = c0#223L)
   !:        +- Join Inner, (c1#219L = c0#223L)                            :    
       :- Join Inner, (c1#219L = c0#222L)
   !:           :- Join Inner, (c1#219L = c0#222L)                         :    
       :  :- SubqueryAlias w2
   !:           :  :- SubqueryAlias w2                                     :    
       :  :  +- CTERelationRef 2, true, [c1#219L], false
   !:           :  :  +- CTERelationRef 2, true, [c1#219L], false          :    
       :  +- SubqueryAlias w0
   !:           :  +- SubqueryAlias w0                                     :    
       :     +- CTERelationRef 0, true, [c0#222L], false
   !:           :     +- CTERelationRef 0, true, [c0#222L], false          :    
       +- SubqueryAlias w1
   !:           +- SubqueryAlias w1                                        :    
          +- CTERelationRef 1, true, [c0#223L], false
   !:              +- CTERelationRef 1, true, [c0#223L], false             +- 
Project [c1#219L, c0#222L, c0#223L]
   !+- Project [c1#219L, c0#222L, c0#223L]                                    
+- SubqueryAlias w3
   !   +- SubqueryAlias w3                                                      
 +- CTERelationRef 3, true, [c1#219L, c0#222L, c0#223L], false
   !      +- CTERelationRef 3, true, [c1#219L, c0#222L, c0#223L], false    
    
   ```



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


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

Reply via email to