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
Draft
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
0dea6c6
Initial changes for SQL scripting interpreter
davidm-db Jun 18, 2024
d7b1950
Add comments
davidm-db Jun 18, 2024
0872769
Whitespace changes
davidm-db Jun 19, 2024
dd20a7e
Addressing comments vol1
davidm-db Jun 19, 2024
0117228
Addressing comments vol2
davidm-db Jun 21, 2024
bd2a907
Addressing comments vol3
davidm-db Jun 26, 2024
746e04b
Improve getText in SingleStatement logical operator
davidm-db Jun 26, 2024
3126baf
Build break fix + minor styling
davidm-db Jun 26, 2024
df563bd
Add minor missing comments
davidm-db Jun 26, 2024
6d402fc
Exclude Scripting from Connect client compatibility check
davidm-db Jun 27, 2024
5a2055f
Minor doc comment changes
davidm-db Jun 27, 2024
fcbc98d
Remove inheritdoc comment
davidm-db Jun 27, 2024
a98259a
Initial changes for SQL Batch Lang Parser
davidm-db May 20, 2024
14ec8e0
Add missing empty line
davidm-db May 20, 2024
b4638a8
Addressing comments
davidm-db May 20, 2024
57c446e
Further improvements
davidm-db May 21, 2024
d663024
Temp changes for interpreter
davidm-db May 29, 2024
3989e12
Add tests
miland-db Jun 28, 2024
623cd2b
Add error tests
miland-db Jun 28, 2024
214c685
Add default value for CompoundBody constructor
miland-db Jun 28, 2024
e888bab
Fix scalastyle pt1
miland-db Jul 1, 2024
b417ddf
Fix SqlScriptingParserSuite
miland-db Jul 1, 2024
55e34d7
Remove IntegrationSuite
miland-db Jul 1, 2024
8f24084
Merge branch 'master' into sql_batch_labels
miland-db Jul 1, 2024
45294b0
Remove unnecessary level in parser
miland-db Jul 2, 2024
e65123b
Add default argument value for label to visitCompoundBodyImpl
miland-db Jul 2, 2024
435454d
Add logical operators and lexer changes
miland-db Jul 8, 2024
5d95075
Add changes to visitor nodes and grammar
miland-db Jul 8, 2024
83f6651
Fix grammar and add AST visitors
miland-db Jul 10, 2024
f497be9
Add grammar changes for handlers
miland-db Jul 10, 2024
f0c2026
Add visit for conditions and handlers
miland-db Jul 11, 2024
8488904
Change grammar
miland-db Jul 11, 2024
1392a76
Merge branch 'master' into sql_batch_error_handlers
miland-db Jul 11, 2024
1e45373
Fix AstBuilder
miland-db Jul 11, 2024
75bfb62
Add check for sqlstate format
miland-db Jul 11, 2024
428570b
Add interpreterBuilder to SparkSessionExtensions
miland-db Jul 11, 2024
0571f3a
Include SparkSession into interpreter
miland-db Jul 11, 2024
f65ecd7
Move some things to concrete class
miland-db Jul 11, 2024
46e41e8
Add handler execution node
miland-db Jul 12, 2024
b9d74b9
Add error checking
miland-db Jul 12, 2024
3c4c9de
Add default values in constructor
miland-db Jul 15, 2024
874ed32
Revert empty lines in imports
miland-db Jul 15, 2024
5d9c4d1
Fix imports
miland-db Jul 15, 2024
41df74e
Add script execution in sql API
miland-db Jul 16, 2024
7557dd2
Add script execution to sql API
miland-db Jul 16, 2024
02579c9
Testing with print
miland-db Jul 16, 2024
f2fb470
Clean debugging stugg
miland-db Jul 16, 2024
6f71896
Add comment and remove unused parameters from constructors
miland-db Jul 17, 2024
2c1ab0d
Add execution functions
miland-db Jul 18, 2024
a1028bb
Fix one sql() method
miland-db Jul 18, 2024
e3f3638
Fix other sql() method
miland-db Jul 18, 2024
b749f95
Change the execution of handler
miland-db Jul 19, 2024
b6f4740
Address comments
miland-db Jul 19, 2024
0845967
Update execute method to call buildExecutionPlan
miland-db Jul 19, 2024
e49716e
Add check for already executed statement
miland-db Jul 19, 2024
03ba9e3
Add compound body test in interpreter suite
miland-db Jul 19, 2024
1fd896b
Fix Interpreter test suite
miland-db Jul 19, 2024
458d45f
Remove comment
miland-db Jul 22, 2024
c707776
Add sqlScriptingEnabled flag
miland-db Jul 22, 2024
655543b
Add error condition
miland-db Jul 22, 2024
0f0389a
Merge branch 'master' into sql_batch_execution
miland-db Jul 22, 2024
04d6031
Move error class to UNSUPPORTED_FEATURE class
miland-db Jul 22, 2024
a32df9c
Add check for sqlconf
miland-db Jul 22, 2024
e391ee7
Add test for SQLConf
miland-db Jul 22, 2024
ef89698
Remove nested iterator and fix tests:
miland-db Jul 22, 2024
4905fa3
Change List to Seq in SparkSession sql
miland-db Jul 22, 2024
a4f9ac6
Update result collection logic
miland-db Jul 22, 2024
df6e5fd
Fix access modifiers and add comments
miland-db Jul 22, 2024
b412d40
Merge branch 'sql_batch_execution' into sql_batch_handler_in_interator
miland-db Jul 22, 2024
c758a62
Sync handlers with the latest changes
miland-db Jul 22, 2024
a6571e3
Add check if handler is defined
miland-db Jul 23, 2024
b90e159
Remove isExecuted flag because it is not necessary
miland-db Jul 23, 2024
1a22353
Merge branch 'sql_batch_execution' into sql_batch_handler_in_interator
miland-db Jul 23, 2024
f452cc1
Add test and separate logic into functions
miland-db Jul 23, 2024
574b3da
Add leave statement execution node
miland-db Jul 23, 2024
b1d867d
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Jul 23, 2024
156a2d7
Add handler logic and stopIteration flag
miland-db Jul 25, 2024
62f230c
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Jul 25, 2024
6a37dcc
Add tests
miland-db Jul 26, 2024
fa82a44
Add test
miland-db Jul 26, 2024
b5516e4
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Aug 5, 2024
56ca9fd
Merge with the latest changes and update tests:
miland-db Aug 6, 2024
6962986
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Aug 6, 2024
29b4f3d
Fix continue handler and add check for duplicate handlers
miland-db Aug 7, 2024
17282c4
Add check for duplicate sqlstate inside condition value list in signl…
miland-db Aug 8, 2024
736e481
Add check for duplicate handler for the same sqlstate
miland-db Aug 9, 2024
3b6dca0
Add catch all handler
miland-db Aug 9, 2024
67fd0d4
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Aug 9, 2024
9675b3d
Fix tests
miland-db Aug 9, 2024
47485ff
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Aug 12, 2024
cbe2f0f
Fix error throw condition from interpreter
miland-db Aug 12, 2024
564f584
Fix scalastyle
miland-db Aug 12, 2024
5c519c1
Add keywords
miland-db Aug 12, 2024
c807359
Regenerate golden files
miland-db Aug 12, 2024
0dddefc
Revert QueryPlan to original state
miland-db Aug 12, 2024
5ad3474
Remove logical operator for leave statement
miland-db Aug 12, 2024
e8d9506
Address comments v1
miland-db Aug 12, 2024
dc7f521
Address comments v2
miland-db Aug 12, 2024
29f1afb
Make ErrorHandlerExec body param public
miland-db Aug 12, 2024
5389e0c
Explain get handler logic and fix coding style
miland-db Aug 12, 2024
12bdede
Add more comments abou iterator execution
miland-db Aug 12, 2024
2e07461
Fix error
miland-db Aug 12, 2024
c0c2d5d
Refactor label equality check for leave statement
miland-db Aug 13, 2024
a1573f6
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Aug 13, 2024
7598e0f
Add setStatementWithOptionalVarKeyword to the handler grammar and vis…
miland-db Aug 13, 2024
3e3373d
Add the rest of the keywords
miland-db Aug 13, 2024
bf9f409
Make CONDITION reserved word
miland-db Aug 13, 2024
ff0f330
Add variable cleanup when executing leave statement
miland-db Aug 13, 2024
a81a64e
Fix imports
miland-db Aug 13, 2024
48c5929
Update doc
miland-db Aug 14, 2024
e7ac5ad
Merge branch 'master' into sql_batch_handler_in_interator
miland-db Aug 15, 2024
97c0f5c
Fix tests
miland-db Aug 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,18 @@
],
"sqlState" : "42614"
},
"DUPLICATE_CONDITION_NAME_FOR_DIFFERENT_SQL_STATE" : {
"message" : [
"Found duplicate condition name <conditionName> for different SQL states. Please, remove one of them."
],
"sqlState" : "42710"
},
"DUPLICATE_HANDLER_FOR_SAME_SQL_STATE" : {
"message" : [
"Found duplicate handlers for the same SQL state <sqlState>. Please, remove one of them."
],
"sqlState" : "42710"
},
"DUPLICATE_KEY" : {
"message" : [
"Found duplicate keys <keyColumn>."
Expand All @@ -1152,6 +1164,12 @@
},
"sqlState" : "4274K"
},
"DUPLICATE_SQL_STATE_FOR_SAME_HANDLER" : {
"message" : [
"Found duplicate SQL state <sqlState> for the same handler. Please, remove one of them."
],
"sqlState" : "42710"
},
"EMITTING_ROWS_OLDER_THAN_WATERMARK_NOT_ALLOWED" : {
"message" : [
"Previous node emitted a row with eventTime=<emittedRowEventTime> which is older than current_watermark_value=<currentWatermark>",
Expand Down Expand Up @@ -4824,6 +4842,11 @@
"<variableName> is a VARIABLE and cannot be updated using the SET statement. Use SET VARIABLE <variableName> = ... instead."
]
},
"SQL_SCRIPTING_NOT_ENABLED" : {
"message" : [
"SQL scripting is under development and not all features are supported. To enable existing features set <sqlScriptingEnabled> to `true`."
]
},
"STATE_STORE_MULTIPLE_COLUMN_FAMILIES" : {
"message" : [
"Creating multiple column families with <stateStoreProvider> is not supported."
Expand Down
2 changes: 2 additions & 0 deletions docs/sql-ref-ansi-compliance.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ Below is a list of all the keywords in Spark SQL.
|CONCATENATE|non-reserved|non-reserved|non-reserved|
miland-db marked this conversation as resolved.
Show resolved Hide resolved
|CONSTRAINT|reserved|non-reserved|reserved|
|CONTAINS|non-reserved|non-reserved|non-reserved|
|CONTINUE|non-reserved|non-reserved|non-reserved|
|COST|non-reserved|non-reserved|non-reserved|
|CREATE|reserved|non-reserved|reserved|
|CROSS|reserved|strict-non-reserved|reserved|
Expand Down Expand Up @@ -530,6 +531,7 @@ Below is a list of all the keywords in Spark SQL.
|GRANT|reserved|non-reserved|reserved|
|GROUP|reserved|non-reserved|reserved|
|GROUPING|non-reserved|non-reserved|reserved|
|HANDLER|non-reserved|non-reserved|non-reserved|
|HAVING|reserved|non-reserved|reserved|
|HOUR|non-reserved|non-reserved|non-reserved|
|HOURS|non-reserved|non-reserved|non-reserved|
Expand Down
5 changes: 5 additions & 0 deletions python/pyspark/errors/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@
"Slice with step is not supported."
]
},
"SQL_SCRIPTING_NOT_ENABLED": {
"message": [
"SQL Scripting is under development and not all features are supported. To enable existing features set <sqlScriptingEnabled> to `true`."
]
},
"STATE_NOT_EXISTS": {
"message": [
"State is either not defined or has already been removed."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ COMPACTIONS: 'COMPACTIONS';
COMPENSATION: 'COMPENSATION';
COMPUTE: 'COMPUTE';
CONCATENATE: 'CONCATENATE';
CONDITION: 'CONDITION';
CONSTRAINT: 'CONSTRAINT';
CONTAINS: 'CONTAINS';
CONTINUE: 'CONTINUE';
COST: 'COST';
CREATE: 'CREATE';
CROSS: 'CROSS';
Expand Down Expand Up @@ -223,6 +225,7 @@ EXCEPT: 'EXCEPT';
EXCHANGE: 'EXCHANGE';
EXCLUDE: 'EXCLUDE';
EXISTS: 'EXISTS';
EXIT: 'EXIT';
EXPLAIN: 'EXPLAIN';
EXPORT: 'EXPORT';
EXTENDED: 'EXTENDED';
Expand All @@ -240,6 +243,7 @@ FOR: 'FOR';
FOREIGN: 'FOREIGN';
FORMAT: 'FORMAT';
FORMATTED: 'FORMATTED';
FOUND: 'FOUND';
FROM: 'FROM';
FULL: 'FULL';
FUNCTION: 'FUNCTION';
Expand All @@ -249,6 +253,7 @@ GLOBAL: 'GLOBAL';
GRANT: 'GRANT';
GROUP: 'GROUP';
GROUPING: 'GROUPING';
HANDLER: 'HANDLER';
HAVING: 'HAVING';
BINARY_HEX: 'X';
HOUR: 'HOUR';
Expand Down Expand Up @@ -402,6 +407,7 @@ SORTED: 'SORTED';
SOURCE: 'SOURCE';
SPECIFIC: 'SPECIFIC';
SQL: 'SQL';
SQLEXCEPTION: 'SQLEXCEPTION';
START: 'START';
STATISTICS: 'STATISTICS';
STORED: 'STORED';
Expand Down Expand Up @@ -570,6 +576,10 @@ IDENTIFIER
| UNICODE_LETTER+ '://' (UNICODE_LETTER | DIGIT | '_' | '/' | '-' | '.' | '?' | '=' | '&' | '#' | '%')+
;

SQLSTATE
miland-db marked this conversation as resolved.
Show resolved Hide resolved
: '\'' (LETTER | DIGIT)(LETTER | DIGIT)(LETTER | DIGIT)(LETTER | DIGIT)(LETTER | DIGIT) '\''
;

BACKQUOTED_IDENTIFIER
: '`' ( ~'`' | '``' )* '`'
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ compoundStatement
: statement
| setStatementWithOptionalVarKeyword
| beginEndCompoundBlock
| declareCondition
| declareHandler
| ifElseStatement
;

Expand All @@ -82,6 +84,23 @@ singleStatement
: (statement|setResetStatement) SEMICOLON* EOF
;

conditionValue
: stringLit
| multipartIdentifier
;

conditionValueList
: ((conditionValues+=conditionValue (COMMA conditionValues+=conditionValue)*) | SQLEXCEPTION | NOT FOUND)
;

declareCondition
: DECLARE multipartIdentifier CONDITION (FOR stringLit)?
;

declareHandler
: DECLARE (CONTINUE | EXIT) HANDLER FOR conditionValueList (BEGIN compoundBody END | statement)
miland-db marked this conversation as resolved.
Show resolved Hide resolved
;

beginLabel
: multipartIdentifier COLON
;
Expand Down Expand Up @@ -1498,6 +1517,7 @@ ansiNonReserved
| COMPUTE
| CONCATENATE
| CONTAINS
| CONTINUE
| COST
| CUBE
| CURRENT
Expand Down Expand Up @@ -1536,6 +1556,7 @@ ansiNonReserved
| EXCHANGE
| EXCLUDE
| EXISTS
| EXIT
| EXPLAIN
| EXPORT
| EXTENDED
Expand Down Expand Up @@ -1823,6 +1844,7 @@ nonReserved
| CONCATENATE
| CONSTRAINT
| CONTAINS
| CONTINUE
| COST
| CREATE
| CUBE
Expand Down Expand Up @@ -1871,6 +1893,7 @@ nonReserved
| EXCLUDE
| EXECUTE
| EXISTS
| EXIT
| EXPLAIN
| EXPORT
| EXTENDED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.sql.catalyst.parser
import java.util.Locale
import java.util.concurrent.TimeUnit

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer, Set}
import scala.jdk.CollectionConverters._
import scala.util.{Left, Right}
Expand Down Expand Up @@ -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.

throw SqlScriptingErrors.sqlScriptingNotEnabled(CurrentOrigin.get)
}
visit(s).asInstanceOf[CompoundBody]
}.getOrElse {
val logicalPlan = visitSingleStatement(ctx.singleStatement())
CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan)),
Some(java.util.UUID.randomUUID.toString.toLowerCase(Locale.ROOT)))
CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan)))
}
}

Expand All @@ -136,8 +139,24 @@ class AstBuilder extends DataTypeAstBuilder
label: Option[String],
allowVarDeclare: Boolean): CompoundBody = {
val buff = ListBuffer[CompoundPlanStatement]()
val handlers = ListBuffer[ErrorHandler]()
Copy link
Contributor

Choose a reason for hiding this comment

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

we miss a logic for statement ordering? i.e. if I recall correctly, we should have variable and condition declarations first, followed by handler declarations, and the actual body afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that check is missing at the moment. It will be added.

val conditions = mutable.HashMap[String, String]()
val sqlStates = mutable.Set[String]()

ctx.compoundStatements.forEach(compoundStatement => {
buff += visit(compoundStatement).asInstanceOf[CompoundPlanStatement]
val stmt = visit(compoundStatement).asInstanceOf[CompoundPlanStatement]

stmt match {
case handler: ErrorHandler => handlers += handler
case condition: ErrorCondition =>
if (conditions.contains(condition.conditionName)) {
throw SqlScriptingErrors.duplicateConditionNameForDifferentSqlState(
CurrentOrigin.get, condition.conditionName)
}
conditions += condition.conditionName -> condition.value
sqlStates += condition.value
case s => buff += s
}
})

val compoundStatements = buff.toList
Expand Down Expand Up @@ -171,7 +190,7 @@ class AstBuilder extends DataTypeAstBuilder
case _ =>
}

CompoundBody(buff.toSeq, label)
CompoundBody(buff.toSeq, label, handlers.toSeq, conditions)
}

override def visitBeginEndCompoundBlock(ctx: BeginEndCompoundBlockContext): CompoundBody = {
Expand Down Expand Up @@ -216,6 +235,27 @@ class AstBuilder extends DataTypeAstBuilder
}
}

override def visitConditionValue(ctx: ConditionValueContext): String = {
Option(ctx.multipartIdentifier()).map(_.getText)
.getOrElse(ctx.stringLit().getText).replace("'", "")
}

override def visitConditionValueList(ctx: ConditionValueListContext): Seq[String] = {
Option(ctx.SQLEXCEPTION()).map(_ => Seq("SQLEXCEPTION")).getOrElse {
Option(ctx.NOT()).map(_ => Seq("NOT FOUND")).getOrElse {
val buff = scala.collection.mutable.Set[String]()
ctx.conditionValues.forEach { conditionValue =>
val elem = visit(conditionValue).asInstanceOf[String]
if (buff(elem)) {
throw SqlScriptingErrors.duplicateSqlStateForSameHandler(CurrentOrigin.get, elem)
}
buff += elem
}
buff.toSeq
miland-db marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

override def visitIfElseStatement(ctx: IfElseStatementContext): IfElseStatement = {
IfElseStatement(
conditions = ctx.booleanExpression().asScala.toList.map(boolExpr => withOrigin(boolExpr) {
Expand All @@ -229,6 +269,28 @@ class AstBuilder extends DataTypeAstBuilder
)
}

override def visitDeclareCondition(ctx: DeclareConditionContext): ErrorCondition = {
val conditionName = ctx.multipartIdentifier().getText
val conditionValue = Option(ctx.stringLit()).map(_.getText.replace("'", "")).getOrElse("45000")

val sqlStateRegex = "^[A-Za-z0-9]{5}$".r
assert(sqlStateRegex.findFirstIn(conditionValue).isDefined)

ErrorCondition(conditionName, conditionValue)
}

override def visitDeclareHandler(ctx: DeclareHandlerContext): ErrorHandler = {
val conditions = visit(ctx.conditionValueList()).asInstanceOf[Seq[String]]
val handlerType = Option(ctx.EXIT()).map(_ => HandlerType.EXIT).getOrElse(HandlerType.CONTINUE)

val body = Option(ctx.compoundBody()).map(visit).getOrElse {
val logicalPlan = visit(ctx.statement()).asInstanceOf[LogicalPlan]
CompoundBody(Seq(SingleStatement(parsedPlan = logicalPlan)))
}.asInstanceOf[CompoundBody]
miland-db marked this conversation as resolved.
Show resolved Hide resolved

ErrorHandler(conditions, body, handlerType)
}

override def visitSingleStatement(ctx: SingleStatementContext): LogicalPlan = withOrigin(ctx) {
Option(ctx.statement().asInstanceOf[ParserRuleContext])
.orElse(Option(ctx.setResetStatement().asInstanceOf[ParserRuleContext]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.apache.spark.sql.catalyst.parser

import scala.collection.mutable

import org.apache.spark.sql.catalyst.parser.HandlerType.HandlerType
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.catalyst.trees.{CurrentOrigin, Origin, WithOrigin}

Expand Down Expand Up @@ -54,10 +57,39 @@ case class SingleStatement(parsedPlan: LogicalPlan)
* @param label Label set to CompoundBody by user or UUID otherwise.
* It can be None in case when CompoundBody is not part of BeginEndCompoundBlock
* for example when CompoundBody is inside loop or conditional block.
* @param handlers Collection of handlers defined in the compound body.
* @param conditions Map of Condition Name - Sql State values declared in the compound body.
*/
case class CompoundBody(
collection: Seq[CompoundPlanStatement],
label: Option[String]) extends CompoundPlanStatement
label: Option[String] = None,
handlers: Seq[ErrorHandler] = Seq.empty,
conditions: mutable.HashMap[String, String] = mutable.HashMap()) extends CompoundPlanStatement
miland-db marked this conversation as resolved.
Show resolved Hide resolved

/**
* Logical operator for an error condition.
* @param conditionName Name of the error condition.
* @param value SQLSTATE or Error Code.
*/
case class ErrorCondition(
conditionName: String,
value: String) extends CompoundPlanStatement

object HandlerType extends Enumeration {
type HandlerType = Value
val EXIT, CONTINUE = Value
}

/**
* Logical operator for an error condition.
* @param conditions Name of the error condition variable for which the handler is built.
* @param body CompoundBody of the handler.
* @param handlerType Type of the handler (CONTINUE or EXIT).
*/
case class ErrorHandler(
conditions: Seq[String],
body: CompoundBody,
handlerType: HandlerType) extends CompoundPlanStatement

/**
* Logical operator for IF ELSE statement.
Expand Down
Loading