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/08 05:57:53 UTC

[GitHub] [spark] yutoacts opened a new pull request #35433: [SPARK-38097] Update the error message of checkUnsupportedTypeInLiteral

yutoacts opened a new pull request #35433:
URL: https://github.com/apache/spark/pull/35433


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Improved the error for unsupported literal types.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   To clarify the error.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes, the error message changed.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   `$ build/sbt "test:testOnly *QueryExecutionErrorsSuite"`


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


[GitHub] [spark] yutoacts commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
yutoacts commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r805668485



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala
##########
@@ -452,7 +453,14 @@ class RelationalGroupedDataset protected[sql](
       case RelationalGroupedDataset.GroupByType =>
         val valueExprs = values.map(_ match {
           case c: Column => c.expr
-          case v => Literal.apply(v)
+          case v =>
+            try {
+              Literal.apply(v)
+            } catch {
+              case _: SparkRuntimeException =>
+                throw QueryExecutionErrors.pivotColumnUnsupportedError(
+                  v, pivotColumn.expr.dataType)

Review comment:
       thanks for fixing it!




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


[GitHub] [spark] MaxGekk commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r802469266



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
##########
@@ -133,8 +133,8 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
         .agg(sum($"sales.earnings"))
         .collect()
     }
-    assert(e2.getMessage === "The feature is not supported: " +
-      "literal for '[dotnet,Dummies]' of class " +
-      "org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema.")
+    assert(e2.getMessage ===
+      "The feature is not supported: pivoting by values of the column " +
+      """'[dotnet,Dummies]' of the type 'struct(lower(sales.course), training)'.""")

Review comment:
       Is this `struct(lower(sales.course), training)` a type? or a column name?




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


[GitHub] [spark] MaxGekk commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r805572902



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
##########
@@ -247,6 +247,13 @@ object QueryExecutionErrors {
       messageParameters = Array(s"literal for '${v.toString}' of ${v.getClass.toString}."))
   }
 
+  def pivotColumnUnsupportedError(v: Any, dataType: DataType): RuntimeException = {
+    new SparkRuntimeException(
+      errorClass = "UNSUPPORTED_FEATURE",
+      messageParameters = Array(
+        s"pivoting by the value '${v.toString}' of the column data type '$dataType'."))

Review comment:
       SQL users can be not aware of Scala's types like `StructField`. Let's call `${dataType.catalogString}`
   ```suggestion
           s"pivoting by the value '${v.toString}' of the column data type '${dataType.catalogString}'."))
   ```




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


[GitHub] [spark] yutoacts commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Update the error message of checkUnsupportedTypeInLiteral

Posted by GitBox <gi...@apache.org>.
yutoacts commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r801484461



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
##########
@@ -134,7 +135,6 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
         .collect()
     }
     assert(e2.getMessage === "The feature is not supported: " +
-      "literal for '[dotnet,Dummies]' of class " +
-      "org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema.")
+      "a type '[dotnet,Dummies]' is not supported as a literal type.")

Review comment:
       Thanks for the review. sorry I misunderstood and it makes sense. I’ll work on it.




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


[GitHub] [spark] yutoacts commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
yutoacts commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r805642857



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
##########
@@ -247,6 +247,14 @@ object QueryExecutionErrors {
       messageParameters = Array(s"literal for '${v.toString}' of ${v.getClass.toString}."))
   }
 
+  def pivotColumnUnsupportedError(v: Any, dataType: DataType): RuntimeException = {
+    new SparkRuntimeException(
+      errorClass = "UNSUPPORTED_FEATURE",
+      messageParameters = Array(
+        s"pivoting by the value '${v.toString}' of the column data type" +
+          s" '${dataType.catalogString}'."))

Review comment:
       @MaxGekk thanks. fixed.




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


[GitHub] [spark] MaxGekk closed pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk closed pull request #35433:
URL: https://github.com/apache/spark/pull/35433


   


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


[GitHub] [spark] MaxGekk commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r801717384



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala
##########
@@ -452,7 +453,13 @@ class RelationalGroupedDataset protected[sql](
       case RelationalGroupedDataset.GroupByType =>
         val valueExprs = values.map(_ match {
           case c: Column => c.expr
-          case v => Literal.apply(v)
+          case v =>
+            try {
+            Literal.apply(v)

Review comment:
       Please, fix indentation.

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
##########
@@ -134,7 +134,6 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
         .collect()
     }
     assert(e2.getMessage === "The feature is not supported: " +
-      "literal for '[dotnet,Dummies]' of class " +
-      "org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema.")
+      "the input column is not supported for pivoting.")

Review comment:
       It would be nice to give users more context, like:
   ```
   The feature is not supported: pivoting by values of the column '[dotnet,Dummies]' of the type 'struct'.
   ```




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


[GitHub] [spark] yutoacts commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
yutoacts commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r805627991



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
##########
@@ -247,6 +247,13 @@ object QueryExecutionErrors {
       messageParameters = Array(s"literal for '${v.toString}' of ${v.getClass.toString}."))
   }
 
+  def pivotColumnUnsupportedError(v: Any, dataType: DataType): RuntimeException = {
+    new SparkRuntimeException(
+      errorClass = "UNSUPPORTED_FEATURE",
+      messageParameters = Array(
+        s"pivoting by the value '${v.toString}' of the column data type '$dataType'."))

Review comment:
       @MaxGekk thanks. fixed.




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


[GitHub] [spark] MaxGekk commented on pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on pull request #35433:
URL: https://github.com/apache/spark/pull/35433#issuecomment-1038869742


   LGTM, waiting for CI.


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


[GitHub] [spark] MaxGekk commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r805628984



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
##########
@@ -247,6 +247,14 @@ object QueryExecutionErrors {
       messageParameters = Array(s"literal for '${v.toString}' of ${v.getClass.toString}."))
   }
 
+  def pivotColumnUnsupportedError(v: Any, dataType: DataType): RuntimeException = {
+    new SparkRuntimeException(
+      errorClass = "UNSUPPORTED_FEATURE",
+      messageParameters = Array(
+        s"pivoting by the value '${v.toString}' of the column data type" +
+          s" '${dataType.catalogString}'."))

Review comment:
       nit: no need additional indentation.
   ```suggestion
           s" '${dataType.catalogString}'."))
   ```




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


[GitHub] [spark] MaxGekk commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Update the error message of checkUnsupportedTypeInLiteral

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r801342538



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
##########
@@ -121,7 +121,8 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
       val e1 = intercept[SparkRuntimeException] { lit(v) }
       assert(e1.getErrorClass === "UNSUPPORTED_FEATURE")
       assert(e1.getSqlState === "0A000")
-      assert(e1.getMessage.matches("""The feature is not supported: literal for '.+' of .+\."""))
+      assert(e1.getMessage.matches(
+      """The feature is not supported: a type '.+' is not supported as a literal type."""))

Review comment:
       The goal of SPARK-38097 is to improve error message in the pivot code. This error is fine, and could be the same.

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
##########
@@ -134,7 +135,6 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
         .collect()
     }
     assert(e2.getMessage === "The feature is not supported: " +
-      "literal for '[dotnet,Dummies]' of class " +
-      "org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema.")
+      "a type '[dotnet,Dummies]' is not supported as a literal type.")

Review comment:
       The message still can confuse users because there are no explicit literals in the code above. It would be nice if you catch the exception in the pivot code, and raise more clear exception with more precise error message.




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


[GitHub] [spark] yutoacts commented on pull request #35433: [SPARK-38097][SQL][TESTS] Update the error message of checkUnsupportedTypeInLiteral

Posted by GitBox <gi...@apache.org>.
yutoacts commented on pull request #35433:
URL: https://github.com/apache/spark/pull/35433#issuecomment-1032244410


   @cloud-fan @MaxGekk  Could you review this? Thanks in advance.


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


[GitHub] [spark] MaxGekk commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r805661276



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala
##########
@@ -452,7 +453,14 @@ class RelationalGroupedDataset protected[sql](
       case RelationalGroupedDataset.GroupByType =>
         val valueExprs = values.map(_ match {
           case c: Column => c.expr
-          case v => Literal.apply(v)
+          case v =>
+            try {
+              Literal.apply(v)
+            } catch {
+              case _: SparkRuntimeException =>
+                throw QueryExecutionErrors.pivotColumnUnsupportedError(
+                  v, pivotColumn.expr.dataType)

Review comment:
       This can fit to one line (100 chars):
   ```suggestion
                   throw QueryExecutionErrors.pivotColumnUnsupportedError(v, pivotColumn.expr.dataType)
   ```




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


[GitHub] [spark] yutoacts commented on a change in pull request #35433: [SPARK-38097][SQL][TESTS] Improved the error message for pivoting unsupported column

Posted by GitBox <gi...@apache.org>.
yutoacts commented on a change in pull request #35433:
URL: https://github.com/apache/spark/pull/35433#discussion_r803654699



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/errors/QueryExecutionErrorsSuite.scala
##########
@@ -133,8 +133,8 @@ class QueryExecutionErrorsSuite extends QueryTest with SharedSparkSession {
         .agg(sum($"sales.earnings"))
         .collect()
     }
-    assert(e2.getMessage === "The feature is not supported: " +
-      "literal for '[dotnet,Dummies]' of class " +
-      "org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema.")
+    assert(e2.getMessage ===
+      "The feature is not supported: pivoting by values of the column " +
+      """'[dotnet,Dummies]' of the type 'struct(lower(sales.course), training)'.""")

Review comment:
       It was actually the column name and I fixed it.
   With the latest change the datatype of the column is thrown.




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