You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by we...@apache.org on 2026/09/19 13:02:13 UTC
(spark) branch master updated: [SPARK-59632][SQL] Unwrap reflected SQL Server parser exceptions
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 3419e88430c5 [SPARK-59632][SQL] Unwrap reflected SQL Server parser exceptions
3419e88430c5 is described below
commit 3419e88430c517ff6189d05258cbd22a32d9a357
Author: Alek Jarmov <al...@databricks.com>
AuthorDate: Sat Sep 19 13:01:58 2026 +0000
[SPARK-59632][SQL] Unwrap reflected SQL Server parser exceptions
### What changes were proposed in this pull request?
The SQL Server connection provider invokes the JDBC driver's URL parser through reflection. This change unwraps `InvocationTargetException` when the reflected parser throws and propagates the original exception.
### Why are the changes needed?
Reflection wraps parser failures in `InvocationTargetException`, hiding the original structured JDBC exception details from callers. Propagating the cause preserves those details.
### Does this PR introduce _any_ user-facing change?
Yes. Failures from the SQL Server JDBC driver's reflected URL parser now surface as their original exceptions instead of `InvocationTargetException` wrappers.
### How was this patch tested?
Added a test to `MSSQLConnectionProviderSuite` that verifies the exact original `SQLException` is propagated.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor GPT-5.6 Sol
Closes #58898 from alekjarmov/alekjarmov/oss-runtime-pr-255979.
Authored-by: Alek Jarmov <al...@databricks.com>
Signed-off-by: Wenchen Fan <we...@databricks.com>
---
.../jdbc/connection/MSSQLConnectionProvider.scala | 14 +++++++++--
.../connection/MSSQLConnectionProviderSuite.scala | 28 +++++++++++++++++++++-
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProvider.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProvider.scala
index aa8c9227377c..938b48da041c 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProvider.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProvider.scala
@@ -17,6 +17,7 @@
package org.apache.spark.sql.execution.datasources.jdbc.connection
+import java.lang.reflect.InvocationTargetException
import java.security.PrivilegedExceptionAction
import java.sql.{Connection, Driver}
import java.util.Properties
@@ -31,6 +32,14 @@ private[sql] class MSSQLConnectionProvider extends SecureConnectionProvider {
override val name: String = "mssql"
+ private def withInvocationTargetExceptionUnwrapped[T](invocation: => T): T = {
+ try {
+ invocation
+ } catch {
+ case e: InvocationTargetException if e.getCause != null => throw e.getCause
+ }
+ }
+
override def appEntry(driver: Driver, options: JDBCOptions): String = {
val configName = "jaasConfigurationName"
val appEntryDefault = "SQLJDBCDriver"
@@ -48,8 +57,9 @@ private[sql] class MSSQLConnectionProvider extends SecureConnectionProvider {
parseURL match {
case Some(m) =>
logDebug("Property parser method found, using it")
- m.invoke(driver, options.url, null).asInstanceOf[Properties]
- .getProperty(configName, appEntryDefault)
+ withInvocationTargetExceptionUnwrapped {
+ m.invoke(driver, options.url, null)
+ }.asInstanceOf[Properties].getProperty(configName, appEntryDefault)
case None =>
logDebug("Property parser method not found, using custom parsing mechanism")
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProviderSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProviderSuite.scala
index a0b9af2d82e1..76d097a39c0c 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProviderSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/jdbc/connection/MSSQLConnectionProviderSuite.scala
@@ -17,11 +17,24 @@
package org.apache.spark.sql.execution.datasources.jdbc.connection
-import java.sql.Driver
+import java.sql.{Connection, Driver, DriverPropertyInfo, SQLException}
+import java.util.Properties
+import java.util.logging.Logger
import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions
class MSSQLConnectionProviderSuite extends ConnectionProviderSuiteBase {
+ test("appEntry unwraps reflected parser exceptions") {
+ val expected = new SQLException("parser failure")
+ val driver = new ThrowingParserDriver(expected)
+
+ val actual = intercept[SQLException] {
+ new MSSQLConnectionProvider().appEntry(driver, options("jdbc:sqlserver://localhost/mssql"))
+ }
+
+ assert(actual eq expected)
+ }
+
test("setAuthenticationConfig default parser must set authentication all the time") {
val provider = new MSSQLConnectionProvider()
val driver = registerDriver(provider.driverClass)
@@ -49,3 +62,16 @@ class MSSQLConnectionProviderSuite extends ConnectionProviderSuiteBase {
testSecureConnectionProvider(provider, driver, customOptions)
}
}
+
+private class ThrowingParserDriver(failure: SQLException) extends Driver {
+ def parseAndMergeProperties(url: String, properties: Properties): Properties = throw failure
+
+ override def connect(url: String, info: Properties): Connection = null
+ override def acceptsURL(url: String): Boolean = true
+ override def getPropertyInfo(url: String, info: Properties): Array[DriverPropertyInfo] =
+ Array.empty
+ override def getMajorVersion: Int = 0
+ override def getMinorVersion: Int = 0
+ override def jdbcCompliant(): Boolean = false
+ override def getParentLogger: Logger = null
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org