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

[WIP][SPARK-48353][SQL] Introduction of Error Handling mechanism in SQL Scripting #47423

Draft
wants to merge 112 commits into
base: master
Choose a base branch
from

Conversation

miland-db
Copy link
Contributor

@miland-db miland-db commented Jul 19, 2024

What changes were proposed in this pull request?

This pull request introduces the logic of error handling inside SQL Scripting language. Now, it is possible to:

  • declare conditions for specific SQL States
  • declare handlers to catch and process errors that are risen during statement execution

Why are the changes needed?

The intent is to add the possibility for user to handle SQL errors in a custom defined way..

Does this PR introduce any user-facing change?

No.

How was this patch tested?

There are already existing test suites for SQL scripting that have been improved to test new functionalities:

  • SqlScriptingParserSuite
  • SqlScriptingExecutionNodeSuite
  • SqlScriptingInterpreterSuite

Was this patch authored or co-authored using generative AI tooling?

No.

Additional changes:

Added cleanup method inside CompoundBody to handle premature exit. Currently this can happen while executing leave statement.

NEED TO FIX (follow-up work):

  • No checks for recursion (direct or indirect) we will probably skip this for now.
  • If the handler itself raises a condition, it cannot handle that condition, nor can any other handlers declared in the block.

# Conflicts:
#	sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
#	sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreter.scala
#	sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingExecutionNodeSuite.scala
#	sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ThriftServerWithSparkContextSuite.scala
@@ -119,11 +120,13 @@ class AstBuilder extends DataTypeAstBuilder
override def visitCompoundOrSingleStatement(
ctx: CompoundOrSingleStatementContext): CompoundBody = withOrigin(ctx) {
Option(ctx.singleCompoundStatement()).map { s =>
if (!SQLConf.get.sqlScriptingEnabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you get the current config value from the active config obj conf? See other examples in the same file like conf.getConf(SQLConf.ENABLE_DEFAULT_COLUMNS)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be rebased on: #47609. Can you please leave comments there first, and then we can get back to this one.

origin = origin,
errorClass = "UNSUPPORTED_FEATURE.SQL_SCRIPTING_NOT_ENABLED",
cause = null,
messageParameters = Map("sqlScriptingEnabled" -> SQLConf.SQL_SCRIPTING_ENABLED.key))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, follow the existing convention and quote the SQL config name using toSQLConf()

@@ -269,7 +269,7 @@ org.apache.spark.sql.catalyst.parser.ParseException
"errorClass" : "PARSE_SYNTAX_ERROR",
"sqlState" : "42601",
"messageParameters" : {
"error" : "'.'",
"error" : "end of input",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why this PR changes this error parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check this one

@dongjoon-hyun dongjoon-hyun marked this pull request as draft August 31, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants