Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-40205][SQL] Provide a query context of ELEMENT_AT_BY_INDEX_ZERO #37645

Closed

Conversation

MaxGekk
Copy link
Member

@MaxGekk MaxGekk commented Aug 24, 2022

What changes were proposed in this pull request?

In the PR, I propose to pass a query context in the ElementAt expression (element_at function) when the index is 0. For instance:

spark-sql> set spark.sql.ansi.enabled=true;
spark.sql.ansi.enabled	true
spark-sql> set spark.sql.error.messageFormat=standard;
spark.sql.error.messageFormat	standard
spark-sql> select element_at(array(1), 0);
{
  "errorClass" : "ELEMENT_AT_BY_INDEX_ZERO",
  "message" : "The index 0 is invalid. An index shall be either < 0 or > 0 (the first element has index 1).",
  "messageParameters" : { },
  "queryContext" : [ {
    "objectType" : "",
    "objectName" : "",
    "startIndex" : 8,
    "stopIndex" : 30,
    "fragment" : "element_at(array(1), 0)"
  } ]
}

Why are the changes needed?

To improve user experience with Spark SQL, and provide additional query contexts when the error happens.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running the affected test suites:

$ build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite"
$ build/sbt "test:testOnly *QueryExecutionErrorsSuite"
$ build/sbt "test:testOnly *QueryExecutionAnsiErrorsSuite"

@github-actions github-actions bot added the SQL label Aug 24, 2022
@MaxGekk MaxGekk changed the title [WIP][SPARK-40205][SQL] Provide a query context of ELEMENT_AT_BY_INDEX_ZERO [SPARK-40205][SQL] Provide a query context of ELEMENT_AT_BY_INDEX_ZERO Aug 24, 2022
@MaxGekk MaxGekk marked this pull request as ready for review August 24, 2022 08:49
@MaxGekk
Copy link
Member Author

MaxGekk commented Aug 24, 2022

also cc @panbingkun

@MaxGekk
Copy link
Member Author

MaxGekk commented Aug 25, 2022

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

@MaxGekk MaxGekk closed this in 7026b3c Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants