You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/02/04 07:52:26 UTC

[GitHub] [spark] SaurabhChawla100 commented on a change in pull request #35389: [SPARK-37943][SQL]Use error classes in the compilation errors of grouping

SaurabhChawla100 commented on a change in pull request #35389:
URL: https://github.com/apache/spark/pull/35389#discussion_r799232253



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
##########
@@ -77,4 +78,56 @@ class QueryCompilationErrorsSuite extends QueryTest with SharedSparkSession {
       " but got: org.apache.spark.sql.types.NumericType"))
   }
 
+  test("UNSUPPORTED_GROUPING_EXPRESSION: filter with grouping/grouping_Id expression") {
+    val df = Seq(
+      (536361, "85123A", 2, 17850),
+      (536362, "85123B", 4, 17850),
+      (536363, "86123A", 6, 17851)
+    ).toDF("InvoiceNo", "StockCode", "Quantity", "CustomerID")
+
+    // filter with grouping
+    var errMsg = intercept[AnalysisException] {
+      df.filter("grouping(CustomerId)=17850")
+        .groupBy("CustomerId").agg(Map("Quantity" -> "max"))
+    }
+    assert(errMsg.message ===
+      "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")
+    assert(errMsg.errorClass === Some("UNSUPPORTED_GROUPING_EXPRESSION"))
+
+    // filter with grouping_id
+    errMsg = intercept[AnalysisException] {
+      df.filter("grouping_id(CustomerId)=17850").
+        groupBy("CustomerId").agg(Map("Quantity" -> "max"))
+    }
+    assert(errMsg.errorClass === Some("UNSUPPORTED_GROUPING_EXPRESSION"))
+    assert(errMsg.message ===
+      "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")
+  }
+
+  test("UNSUPPORTED_GROUPING_EXPRESSION: Sort with grouping/grouping_Id expression") {
+    val df = Seq(
+      (536361, "85123A", 2, 17850),
+      (536362, "85123B", 4, 17850),
+      (536363, "86123A", 6, 17851)
+    ).toDF("InvoiceNo", "StockCode", "Quantity", "CustomerID")
+
+   // Sort with grouping
+    var errMsg = intercept[AnalysisException] {
+      df.sort(grouping("CustomerId"))
+        .groupBy("CustomerId").agg(Map("Quantity" -> "max"))
+    }
+    assert(errMsg.errorClass === Some("UNSUPPORTED_GROUPING_EXPRESSION"))
+    assert(errMsg.message ===
+      "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup")

Review comment:
       If I am understanding correctly So the message should be like this 
   "Sort with grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup" instead of 
   "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup"
   
   Similar case for filter
   "Filter with grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup" instead of 
   "grouping()/grouping_id() can only be used with GroupingSets/Cube/Rollup"
   




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org