This is an automated email from the ASF dual-hosted git repository.

cloud-fan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b38f9c84833 [SPARK-58193][SQL] Classify Databricks syntax errors by 
message
4b38f9c84833 is described below

commit 4b38f9c84833a90995ca67ab8fd1e7cf9a5bf9a6
Author: Alek Jarmov <[email protected]>
AuthorDate: Mon Jul 20 22:18:18 2026 +0800

    [SPARK-58193][SQL] Classify Databricks syntax errors by message
    
    ### What changes were proposed in this pull request?
    
    Recognize remote Databricks parse errors when the JDBC driver reports the 
SYNTAX_ERROR condition only in its message.
    Optimise `isSyntaxErrorBestEffort` for Databricks to catch syntax error 
even if SQLState is missing.
    
    ### Why are the changes needed?
    
    To improve the error classification.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Update the user-facing-change section from No: matching this driver error 
now produces Spark's JDBC_EXTERNAL_ENGINE_SYNTAX_ERROR classification during 
schema resolution or query execution.
    
    ### How was this patch tested?
    
    Added a unit-test and checked a case on a Databricks workspace
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude 4.7
    
    Closes #57333 from alekjarmov/alekjarmov/classify-databricks-syntax-errors.
    
    Authored-by: Alek Jarmov <[email protected]>
    Signed-off-by: Wenchen Fan <[email protected]>
---
 .../main/scala/org/apache/spark/sql/jdbc/DatabricksDialect.scala | 7 +++++--
 .../src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala     | 9 ++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git 
a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DatabricksDialect.scala 
b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DatabricksDialect.scala
index a56aa90d6d72..0c606ce71f91 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DatabricksDialect.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DatabricksDialect.scala
@@ -55,9 +55,12 @@ private case class DatabricksDialect() extends JdbcDialect 
with NoLegacyJDBCErro
     case _ => None
   }
 
-  // See https://docs.databricks.com/aws/en/error-messages/sqlstates
+  // See https://docs.databricks.com/aws/en/error-messages/sqlstates.
+  // The driver may report syntax errors with a non-class-42 SQLState.
   override def isSyntaxErrorBestEffort(exception: SQLException): Boolean = {
-    Option(exception.getSQLState).exists(_.startsWith("42"))
+    Option(exception.getSQLState).exists(_.startsWith("42")) ||
+      Option(exception.getMessage)
+        .exists(_.toUpperCase(Locale.ROOT).contains("SYNTAX_ERROR"))
   }
 
   override def quoteIdentifier(colName: String): String = {
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala 
b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
index 58797e68b8ab..de863b244be8 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
@@ -18,7 +18,7 @@
 package org.apache.spark.sql.jdbc
 
 import java.math.BigDecimal
-import java.sql.{Connection, Date, DriverManager, ResultSet, Statement, 
Timestamp}
+import java.sql.{Connection, Date, DriverManager, ResultSet, SQLException, 
Statement, Timestamp}
 import java.time.{Instant, LocalDate, LocalDateTime}
 import java.time.format.DateTimeFormatter
 import java.util.{Calendar, GregorianCalendar, Properties, TimeZone}
@@ -2608,6 +2608,13 @@ class JDBCSuite extends SharedSparkSession {
       .getJDBCType(BinaryType).map(_.databaseTypeDefinition).get == "BINARY")
   }
 
+  test("SPARK-58193: DatabricksDialect syntax error detection") {
+    val dialect = DatabricksDialect()
+    assert(dialect.isSyntaxErrorBestEffort(
+      new SQLException("[parse_syntax_error] Syntax error at or near 'SQL'", 
"07000")))
+    assert(!dialect.isSyntaxErrorBestEffort(new SQLException("Connection 
reset", "08001")))
+  }
+
   test("SPARK-45425: Mapped TINYINT to ShortType for MsSqlServerDialect") {
     val msSqlServerDialect = JdbcDialects.get("jdbc:sqlserver")
     val metadata = new MetadataBuilder().putLong("scale", 1)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to