davidm-db commented on code in PR #49427:
URL: https://github.com/apache/spark/pull/49427#discussion_r1916417583


##########
sql/core/src/main/scala/org/apache/spark/sql/scripting/SqlScriptingExecution.scala:
##########
@@ -97,18 +101,52 @@ 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 handling the exception, 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 {
+      case Some(handler) =>
+        context.frames.addOne(

Review Comment:
   nit: `append`



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to