cloud-fan commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1928130846
##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecution.scala:
##########
@@ -97,18 +107,54 @@ class SqlScriptingExecution(
None
}
- private def handleException(e: Throwable): Unit = {
- // Rethrow the exception.
- // TODO: SPARK-48353 Add error handling for SQL scripts
- throw e
+ /**
+ * Advances through the script and executes statements until a result
statement or
+ * end of script is encountered.
+ *
+ * To know if there is result statement available, the method has to advance
through script and
+ * execute statements until the result statement or end of script is
encountered. For that reason
+ * the returned result must be executed before subsequent calls. Multiple
calls without executing
+ * the intermediate results will lead to incorrect behavior.
+ *
+ * @return Result DataFrame if it is available, otherwise None.
+ */
+ def getNextResult: Option[DataFrame] = {
+ try {
+ getNextResultInternal
+ } catch {
+ case e: SparkThrowable =>
+ handleException(e)
+ getNextResult // After setup for exception handling, try to get the
next result again.
+ case throwable: Throwable =>
+ throw throwable // Rethrow the exception.
+ }
+ }
+
+ private def handleException(e: SparkThrowable): Unit = {
+ context.findHandler(e.getCondition, e.getSqlState) match {
Review Comment:
how is the spark error condition name related here? Seems we messed up two
concepts here: the user-specified error conditions and the spark error's
condition name.
I think we only need to look at the error SQL state, and then use it to find
the matching error handler.
--
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]