You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/09/05 08:18:17 UTC

[GitHub] [spark] MaxGekk commented on a diff in pull request #37794: [WIP][SPARK-40324][SQL] Provide a query context of `ParseException`

MaxGekk commented on code in PR #37794:
URL: https://github.com/apache/spark/pull/37794#discussion_r962618026


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/ParseDriver.scala:
##########
@@ -315,12 +316,23 @@ class ParseException(
   }
 
   def withCommand(cmd: String): ParseException = {
-    // PARSE_EMPTY_STATEMENT error class overrides the PARSE_SYNTAX_ERROR when cmd is empty
-    if (cmd.trim().isEmpty && errorClass.isDefined && errorClass.get == "PARSE_SYNTAX_ERROR") {
-      new ParseException(Option(cmd), start, stop, "PARSE_EMPTY_STATEMENT", Array[String]())
-    } else {
-      new ParseException(Option(cmd), message, start, stop, errorClass, None, messageParameters)
-    }
+    val (cls, subCls, params) =
+      if (errorClass == Some("PARSE_SYNTAX_ERROR") && cmd.trim().isEmpty) {
+        // PARSE_EMPTY_STATEMENT error class overrides the PARSE_SYNTAX_ERROR when cmd is empty
+        (Some("PARSE_EMPTY_STATEMENT"), None, Array[String]())
+      } else {
+        (errorClass, errorSubClass, messageParameters)
+      }
+    new ParseException(Option(cmd), message, start, stop, cls, subCls, params, queryContext)
+  }
+
+  override def getQueryContext: Array[QueryContext] = queryContext
+}
+
+object ParseException {
+  def getQueryContext(): Array[QueryContext] = {
+    val context = CurrentOrigin.get.context
+    if (context.isValid) Array(context) else Array.empty

Review Comment:
   I check that the context is valid because some errors can occur before the context is set (it is empty). I remove it from output since the empty context is useless.



-- 
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-unsubscribe@spark.apache.org

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


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