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/08/09 12:40:11 UTC

[GitHub] [spark] MaxGekk opened a new pull request, #37452: [WIP][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

MaxGekk opened a new pull request, #37452:
URL: https://github.com/apache/spark/pull/37452

   <!--
   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.
   -->
   
   
   ### 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.
   -->
   
   
   ### 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'.
   -->
   
   
   ### 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.
   -->
   


-- 
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] HyukjinKwon commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r941929812


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -128,7 +128,7 @@ select sort_array(array('b', 'd'), '1')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'sort_array(array('b', 'd'), '1')' due to data type mismatch: Sort order in second argument requires a boolean literal.; line 1 pos 7
+{"errorClass":null,"messageParameters":[],"queryContext":[]}

Review Comment:
   Hm, it's a bit odd to me that the user-facing error contains JSON exception. e.g., if you run it in `spark-sql` then users would face such JSON encoded string .. that I don't think it's good.



-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942012454


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -128,7 +128,7 @@ select sort_array(array('b', 'd'), '1')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'sort_array(array('b', 'd'), '1')' due to data type mismatch: Sort order in second argument requires a boolean literal.; line 1 pos 7
+{"errorClass":null,"messageParameters":[],"queryContext":[]}

Review Comment:
   > How about:
   > {"errorClass":"legacy","messageParameters":["message" -> "original message"],"queryContext":[]}
   
   It makes sense. Let me do that. Thanks.



-- 
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 #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

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

   @cloud-fan @gengliangwang @srielau @anchovYu Could you review this PR, please.


-- 
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] srielau commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
srielau commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r941868855


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -128,7 +128,7 @@ select sort_array(array('b', 'd'), '1')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'sort_array(array('b', 'd'), '1')' due to data type mismatch: Sort order in second argument requires a boolean literal.; line 1 pos 7
+{"errorClass":null,"messageParameters":[],"queryContext":[]}

Review Comment:
   I'm with @entong, we can't do this.
   If there is no defined error class we need have a default.
   How about:
   {"errorClass":"legacy","messageParameters":["message" -> "original message"],"queryContext":[]}



-- 
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] cloud-fan commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r958031660


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -78,9 +80,12 @@ trait SQLQueryTestHelper {
    * @param result a function that returns a pair of schema and output
    */
   protected def handleExceptions(result: => (String, Seq[String])): (String, Seq[String]) = {
+    val format = MINIMAL
     try {
       result
     } catch {
+      case e: SparkThrowable with Throwable if e.getErrorClass != null =>
+        (emptySchema, Seq(e.getClass.getName, getMessage(e, format)))

Review Comment:
   We should normalize the error message as before, see https://github.com/apache/spark/pull/37452/files#diff-739e09a7f5e5fd55fb42ca80b075e0c45f4342853ba66b0df1631310e691950fR94



-- 
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 #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk closed pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format
URL: https://github.com/apache/spark/pull/37452


-- 
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] cloud-fan commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r958031660


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -78,9 +80,12 @@ trait SQLQueryTestHelper {
    * @param result a function that returns a pair of schema and output
    */
   protected def handleExceptions(result: => (String, Seq[String])): (String, Seq[String]) = {
+    val format = MINIMAL
     try {
       result
     } catch {
+      case e: SparkThrowable with Throwable if e.getErrorClass != null =>
+        (emptySchema, Seq(e.getClass.getName, getMessage(e, format)))

Review Comment:
   We should normalize the error message as before, see L94
   ```
           // Do not output the logical plan tree which contains expression IDs.
           // Also implement a crude way of masking expression IDs in the error message
           // with a generic pattern "###".
           val msg = if (a.plan.nonEmpty) a.getSimpleMessage else a.getMessage
           (emptySchema, Seq(a.getClass.getName, msg.replaceAll("#\\d+", "#x")))
   
   ```



-- 
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] cloud-fan commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r958057976


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -78,9 +80,12 @@ trait SQLQueryTestHelper {
    * @param result a function that returns a pair of schema and output
    */
   protected def handleExceptions(result: => (String, Seq[String])): (String, Seq[String]) = {
+    val format = MINIMAL
     try {
       result
     } catch {
+      case e: SparkThrowable with Throwable if e.getErrorClass != null =>
+        (emptySchema, Seq(e.getClass.getName, getMessage(e, format)))

Review Comment:
   The sql fragment (query context) may contain expr IDs.



-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942598311


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -165,10 +165,7 @@ select element_at(array(1, 2, 3), 5)
 struct<>
 -- !query output
 org.apache.spark.SparkArrayIndexOutOfBoundsException
-[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index 5 is out of bounds. The array has 3 elements. Use `try_element_at` to tolerate accessing element at invalid index and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
-== SQL(line 1, position 8) ==
-select element_at(array(1, 2, 3), 5)
-       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+{"errorClass":"INVALID_ARRAY_INDEX_IN_ELEMENT_AT","messageParameters":["5","3","\"spark.sql.ansi.enabled\""],"queryContext":[{"objectType":"","objectName":"","startIndex":7,"stopIndex":35,"fragment":"element_at(array(1, 2, 3), 5"}]}

Review Comment:
   I just have the concern about this: variable schema (JSON object) makes machinery parsing harder. How would you parse such JSON by Spark SQL? Parse `messageParameters` as a map?
   
   Anyway, I am ok to replace the array by map.



-- 
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] srielau commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
srielau commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942582684


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -71,6 +76,30 @@ trait SQLQueryTestHelper {
     if (isSorted(df.queryExecution.analyzed)) (schema, answer) else (schema, answer.sorted)
   }
 
+  private def toJson(e: SparkThrowable): String = {

Review Comment:
   I'm wondering whether we have messed up the order of the PRs here.
   In my mental model I had us implement machineReadable Error message and then simply "flip the config" to produce the golden files in that format. What we have here now is a hand crafted JSON. Is that temporary?
   



-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942598311


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -165,10 +165,7 @@ select element_at(array(1, 2, 3), 5)
 struct<>
 -- !query output
 org.apache.spark.SparkArrayIndexOutOfBoundsException
-[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index 5 is out of bounds. The array has 3 elements. Use `try_element_at` to tolerate accessing element at invalid index and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
-== SQL(line 1, position 8) ==
-select element_at(array(1, 2, 3), 5)
-       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+{"errorClass":"INVALID_ARRAY_INDEX_IN_ELEMENT_AT","messageParameters":["5","3","\"spark.sql.ansi.enabled\""],"queryContext":[{"objectType":"","objectName":"","startIndex":7,"stopIndex":35,"fragment":"element_at(array(1, 2, 3), 5"}]}

Review Comment:
   I just have the concern about this: variable schema (JSON object) makes machinery parsing harder. How would you parse such JSON by Spark SQL? Parse `messageParameters` as a map?
   
   Anyway, I am ok to replace the array by map.



-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942009215


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -128,7 +128,7 @@ select sort_array(array('b', 'd'), '1')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'sort_array(array('b', 'd'), '1')' due to data type mismatch: Sort order in second argument requires a boolean literal.; line 1 pos 7
+{"errorClass":null,"messageParameters":[],"queryContext":[]}

Review Comment:
   @HyukjinKwon This is not user-facing changes. I changed the way how golden files are generated in tests. Output of `spark-sql` is the same.



-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942610741


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -71,6 +76,30 @@ trait SQLQueryTestHelper {
     if (isSorted(df.queryExecution.analyzed)) (schema, answer) else (schema, answer.sorted)
   }
 
+  private def toJson(e: SparkThrowable): String = {

Review Comment:
   Generating the JSON file is a small piece of code. Don't see any problem to remove/move it in the near future. And introduce the config, and then check it on the already existing golden files.
   
   > What we have here now is a hand crafted JSON.
   
   How else would you generate JSON from `SparkThrowable`, I wonder.
   
   > Is that temporary?
   
   Not final.



-- 
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] srielau commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
srielau commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r941868855


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -128,7 +128,7 @@ select sort_array(array('b', 'd'), '1')
 struct<>
 -- !query output
 org.apache.spark.sql.AnalysisException
-cannot resolve 'sort_array(array('b', 'd'), '1')' due to data type mismatch: Sort order in second argument requires a boolean literal.; line 1 pos 7
+{"errorClass":null,"messageParameters":[],"queryContext":[]}

Review Comment:
   I'm with @entong, we can't do this.
   If there is no defined error class we need have a default.
   How about:
   {"errorClass":"legacy","messageParameters":["message" -> "<original message>"],"queryContext":[]}



-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942598311


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -165,10 +165,7 @@ select element_at(array(1, 2, 3), 5)
 struct<>
 -- !query output
 org.apache.spark.SparkArrayIndexOutOfBoundsException
-[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index 5 is out of bounds. The array has 3 elements. Use `try_element_at` to tolerate accessing element at invalid index and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
-== SQL(line 1, position 8) ==
-select element_at(array(1, 2, 3), 5)
-       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+{"errorClass":"INVALID_ARRAY_INDEX_IN_ELEMENT_AT","messageParameters":["5","3","\"spark.sql.ansi.enabled\""],"queryContext":[{"objectType":"","objectName":"","startIndex":7,"stopIndex":35,"fragment":"element_at(array(1, 2, 3), 5"}]}

Review Comment:
   I just have the concern about this: variable schema (JSON object) makes machinery parsing harder. How would you parse such JSON by Spark SQL?



-- 
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] srielau commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
srielau commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942577961


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -165,10 +165,7 @@ select element_at(array(1, 2, 3), 5)
 struct<>
 -- !query output
 org.apache.spark.SparkArrayIndexOutOfBoundsException
-[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index 5 is out of bounds. The array has 3 elements. Use `try_element_at` to tolerate accessing element at invalid index and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
-== SQL(line 1, position 8) ==
-select element_at(array(1, 2, 3), 5)
-       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+{"errorClass":"INVALID_ARRAY_INDEX_IN_ELEMENT_AT","messageParameters":["5","3","\"spark.sql.ansi.enabled\""],"queryContext":[{"objectType":"","objectName":"","startIndex":7,"stopIndex":35,"fragment":"element_at(array(1, 2, 3), 5"}]}

Review Comment:
   I think the design of JSON called for messageParameter entry to be a map (parameterName -> parameterValue).
    



-- 
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 #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

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

   Merging to master. Thank you, @srielau @cloud-fan @entong @HyukjinKwon for review.


-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r958043936


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -78,9 +80,12 @@ trait SQLQueryTestHelper {
    * @param result a function that returns a pair of schema and output
    */
   protected def handleExceptions(result: => (String, Seq[String])): (String, Seq[String]) = {
+    val format = MINIMAL
     try {
       result
     } catch {
+      case e: SparkThrowable with Throwable if e.getErrorClass != null =>
+        (emptySchema, Seq(e.getClass.getName, getMessage(e, format)))

Review Comment:
   @cloud-fan Do you have an example where we output a plan in an error with error class. As far as I know we are trying to avoid output any plans when we migrate on error classes.



-- 
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] entong commented on pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
entong commented on PR #37452:
URL: https://github.com/apache/spark/pull/37452#issuecomment-1209961344

   344 out of the 470 errors changed do not have an error class associated which means losing all the information about the error. This could hide bugs related to unexpected changes on the errors.


-- 
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 diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942654055


##########
sql/core/src/test/resources/sql-tests/results/ansi/array.sql.out:
##########
@@ -165,10 +165,7 @@ select element_at(array(1, 2, 3), 5)
 struct<>
 -- !query output
 org.apache.spark.SparkArrayIndexOutOfBoundsException
-[INVALID_ARRAY_INDEX_IN_ELEMENT_AT] The index 5 is out of bounds. The array has 3 elements. Use `try_element_at` to tolerate accessing element at invalid index and return NULL instead. If necessary set "spark.sql.ansi.enabled" to "false" to bypass this error.
-== SQL(line 1, position 8) ==
-select element_at(array(1, 2, 3), 5)
-       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+{"errorClass":"INVALID_ARRAY_INDEX_IN_ELEMENT_AT","messageParameters":["5","3","\"spark.sql.ansi.enabled\""],"queryContext":[{"objectType":"","objectName":"","startIndex":7,"stopIndex":35,"fragment":"element_at(array(1, 2, 3), 5"}]}

Review Comment:
   If we put `parameterName` to golden files, we prevent tech writers from modifying of parameters names in error-classes.json. It seems it is unnecessary restriction, isn't. In any case, the order of params is fixed/constant in the code.  cc @cloud-fan WDYT?



-- 
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] cloud-fan commented on a diff in pull request #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on code in PR #37452:
URL: https://github.com/apache/spark/pull/37452#discussion_r942656352


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestHelper.scala:
##########
@@ -71,6 +76,30 @@ trait SQLQueryTestHelper {
     if (isSorted(df.queryExecution.analyzed)) (schema, answer) else (schema, answer.sorted)
   }
 
+  private def toJson(e: SparkThrowable): String = {

Review Comment:
   I have the same question: shall we add a user-facing feature first that allows users to enable JSON style error message? Due to the low coverage of error classes today, I'd also suggest keeping the message unchanged for errors without error classes (no JSON).



-- 
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 #37452: [SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

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

   @cloud-fan @HyukjinKwon @srielau @entong @gengliangwang @anchovYu Could you take a look at this PR one more time, please.


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