spark icon indicating copy to clipboard operation
spark copied to clipboard

[SPARK-40018][SQL][TESTS] Output `SparkThrowable` to SQL golden files in JSON format

Open MaxGekk opened this issue 3 years ago • 2 comments

What changes were proposed in this pull request?

In the PR, I propose to catch exceptions of the type SparkThrowable in the test suite sub-classes of SQLQueryTestHelper:

  • SQLQueryTestSuite
  • TPCDSQueryTestSuite
  • ThriftServerQueryTestSuite

and output the content of SparkThrowable in the JSON format, see SQLQueryTestHelper.handleExceptions(). The JSON string includes:

  • errorClass - human-readable, unique, and consistent representation of the error category. It is a string, and can be null.
  • errorSubClass - optional sub-class of the error class as a string. It may be missing in the result string.
  • sqlState - optional string w/ error identifier across SQL engines. It may be missing in the result string.
  • messageParameters - an array of message parameters as a strings.
  • queryContext - an array of query contexts of the error message which the following JSON fields:
    • objectType - the string represents the object type of the query which throws the exception. If the exception is directly from the main query, it should be an empty string.
    • objectName - the string represents the object name of the query which throws the exception. If the exception is directly from the main query, it should be an empty string.
    • startIndex - the integer represents the starting index in the query text which throws the exception. The index starts from 0, but it can be -1 if the index is unknown.
    • stopIndex - the integer represents the stopping index in the query which throws the exception. The index starts from 0, but it can be -1 if the index is unknown.
    • fragment - the string represents the corresponding fragment of the query which throws the exception. If the query fragment cannot be identified, the string is empty.

Also, the PR regenerates all SQL golden files.

Why are the changes needed?

  1. To put only important information to SQL golden files
  2. To avoid dependencies from the content of error messages

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running the affected test suite:

$ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"

MaxGekk avatar Aug 09 '22 12:08 MaxGekk

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

MaxGekk avatar Aug 09 '22 15:08 MaxGekk

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.

entong avatar Aug 09 '22 22:08 entong

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

MaxGekk avatar Aug 10 '22 09:08 MaxGekk

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

MaxGekk avatar Aug 19 '22 15:08 MaxGekk