This is an automated email from the ASF dual-hosted git repository.

gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 95b61abe5c4 [SPARK-42044][SQL] Fix incorrect error message for 
`MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY`
95b61abe5c4 is described below

commit 95b61abe5c4ed5aadb85c533735325249a9d000b
Author: itholic <[email protected]>
AuthorDate: Tue Jan 24 23:01:33 2023 +0900

    [SPARK-42044][SQL] Fix incorrect error message for 
`MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY`
    
    ### What changes were proposed in this pull request?
    
    This PR proposes to fix incorrect error message for 
`MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY`
    
    ### Why are the changes needed?
    
    The current error message:
    
    `Correlated scalar subqueries in the GROUP BY clause must also be in the 
aggregate expressions<treeNode>`
    
    is incorrect since it's not related with group by clause at all.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    `./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite*"`
    
    Closes #39543 from itholic/MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY.
    
    Authored-by: itholic <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 core/src/main/resources/error/error-classes.json                   | 2 +-
 .../org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala     | 4 ++--
 .../apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala    | 7 +++++--
 sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala   | 5 ++---
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/core/src/main/resources/error/error-classes.json 
b/core/src/main/resources/error/error-classes.json
index 08ce9fe1021..5d2e184874a 100644
--- a/core/src/main/resources/error/error-classes.json
+++ b/core/src/main/resources/error/error-classes.json
@@ -1667,7 +1667,7 @@
       },
       "MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY" : {
         "message" : [
-          "Correlated scalar subqueries in the GROUP BY clause must also be in 
the aggregate expressions<treeNode>."
+          "Correlated scalar subqueries must be aggregated to return at most 
one row."
         ]
       },
       "MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY_OUTPUT" : {
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
index 4dc0bf98a54..250e4f3c5df 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
@@ -947,7 +947,7 @@ trait CheckAnalysis extends PredicateHelper with 
LookupCatalog with QueryErrorsB
               expr.failAnalysis(
                 errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY." +
                   "MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY",
-                messageParameters = Map("treeNode" -> planToString(other)))
+                messageParameters = Map.empty)
           }
 
           // Only certain operators are allowed to host subquery expression 
containing
@@ -962,7 +962,7 @@ trait CheckAnalysis extends PredicateHelper with 
LookupCatalog with QueryErrorsB
                 a.failAnalysis(
                   errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY." +
                     "MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY",
-                  messageParameters = Map("treeNode" -> planToString(a)))
+                  messageParameters = Map.empty)
               }
             case other =>
               other.failAnalysis(
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala
index 9acdad0a428..af62ec1f516 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala
@@ -934,8 +934,11 @@ class AnalysisErrorSuite extends AnalysisTest {
             t.as("t2")))
       ) :: Nil,
       sum($"c2").as("sum") :: Nil, t.as("t1"))
-    assertAnalysisError(plan, "Correlated scalar subqueries in the group by 
clause must also be " +
-      "in the aggregate expressions" :: Nil)
+    assertAnalysisErrorClass(
+      plan,
+      expectedErrorClass =
+        
"UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY",
+      expectedMessageParameters = Map.empty)
   }
 
   test("SPARK-34946: correlated scalar subquery in aggregate expressions 
only") {
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala 
b/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
index 2d7cd007bee..e4e69633e0f 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SubquerySuite.scala
@@ -545,12 +545,11 @@ class SubquerySuite extends QueryTest
     val exception1 = intercept[AnalysisException] {
       sql("select a, (select b from l l2 where l2.a = l1.a) sum_b from l l1")
     }
-    checkErrorMatchPVals(
+    checkError(
       exception1,
       errorClass = "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY." +
         "MUST_AGGREGATE_CORRELATED_SCALAR_SUBQUERY",
-      parameters = Map("treeNode" -> "(?s)Filter .*"),
-      sqlState = None,
+      parameters = Map.empty,
       context = ExpectedContext(
         fragment = "(select b from l l2 where l2.a = l1.a)", start = 10, stop 
= 47))
     val exception2 = intercept[AnalysisException] {


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

Reply via email to