cloud-fan commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1927034312
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -159,44 +159,113 @@ class AstBuilder extends DataTypeAstBuilder
script
}
- private def visitCompoundBodyImpl(
- ctx: CompoundBodyContext,
- label: Option[String],
- allowVarDeclare: Boolean,
- labelCtx: SqlScriptingLabelContext,
- isScope: Boolean): CompoundBody = {
- val buff = ListBuffer[CompoundPlanStatement]()
- ctx.compoundStatements.forEach(
- compoundStatement => buff +=
visitCompoundStatementImpl(compoundStatement, labelCtx))
+ private def assertSqlState(sqlState: String): Unit = {
+ val sqlStateRegex = "^[A-Za-z0-9]{5}$".r
+ if (sqlStateRegex.findFirstIn(sqlState).isEmpty
+ || sqlState.startsWith("00")
+ || sqlState.startsWith("01")
+ || sqlState.startsWith("XX")) {
+ throw SqlScriptingErrors.invalidSqlStateValue(CurrentOrigin.get,
sqlState)
+ }
+ }
- val compoundStatements = buff.toList
+ override def visitConditionValue(ctx: ConditionValueContext): String = {
Review Comment:
condition value is not a string, it can be 4 different things:
`SQLEXCEPTION`, `NOT FOUND`, SQLSTATE literal, and reference of a named
condition.
Without the right data model, we will have bugs in corner cases:
- `DECLARE EXIT HANDLER FOR SQLSTATE 'KP042', KP042, ...` should be allowed
if the condition `KP042` defines a different SQL state.
- `DECLARE EXIT HANDLER FOR SQLSTATE 'KP042', abc, ...` should not be
allowed if the condition `abc` is also defined as `SQLSTATE 'KP042'`
- ``DECLARE EXIT HANDLER FOR SQLEXCEPTION,`SQLEXCEPTION`, ...`` should be
allowed as the second `SQLEXCEPTION` references to a named condition
Let's create a `trait ScriptingErrorConditionValue` and 4 sub-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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]