davidm-db commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1928379828
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala:
##########
@@ -159,44 +159,142 @@ 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)
+ }
+ }
+
+ private def visitConditionValueImpl(
+ ctx: ConditionValueContext,
+ handlerTriggers: HandlerTriggers): Unit = {
+ // Current element is SQLSTATE.
+ Option(ctx.sqlStateValue())
+ .foreach { sqlStateValueContext =>
+ val sqlState = sqlStateValueContext.getText.replace("'", "")
+ assertSqlState(sqlState)
+ handlerTriggers.addUniqueSqlState(sqlState)
+ }
- val compoundStatements = buff.toList
+ // Current element is condition.
+ Option(ctx.multipartIdentifier())
+ .foreach { conditionContext =>
+ handlerTriggers.addUniqueCondition(conditionContext.getText)
Review Comment:
We have a check to fail for qualified condition names, but only during their
declaration - in `visitDeclareConditionStatementImpl`.
This visitor here is part of the handler declaration hierarchy, and here we
should allow qualified condition names, in case someone is referencing a
built-in error condition - like
`INVALID_AGGREGATE_FILTER.CONTAINS_WINDOW_FUNCTION`.
For my knowledge, what's considered under a special char? Can `.` be a
special char? How to we differentiate then between the dot as a special char
and as a delimiter?
--
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]