Skip to content

Commit f1e5a13

Browse files
committed
[SPARK-46393][SQL] Classify exceptions in the JDBC table catalog
### What changes were proposed in this pull request? In the PR, I propose to handle exceptions from JDBC drivers in the JDBC table catalog, classify them and converted to appropriate Spark exception w/ an error class. This PR covers the following functions where such errors haven't been classified yet: - list tables - namespace exists - list namespaces ### Why are the changes needed? To unify Spark exceptions, and migrate onto new error framework. ### Does this PR introduce _any_ user-facing change? Yes, if user code expects that Spark SQL bypass Java exceptions from JDBC drivers. ### How was this patch tested? By existing test suites: ``` $ build/sbt "test:testOnly *JDBCV2Suite" $ build/sbt "test:testOnly *JDBCTableCatalogSuite" ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #44335 from MaxGekk/classifyException-JDBCTableCatalog. Authored-by: Max Gekk <max.gekk@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
1 parent b8c49a1 commit f1e5a13

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalog.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ class JDBCTableCatalog extends TableCatalog
6565
checkNamespace(namespace)
6666
JdbcUtils.withConnection(options) { conn =>
6767
val schemaPattern = if (namespace.length == 1) namespace.head else null
68-
val rs = conn.getMetaData
69-
.getTables(null, schemaPattern, "%", Array("TABLE"))
68+
val rs = JdbcUtils.classifyException(
69+
s"Failed get tables from: ${namespace.mkString(".")}", dialect) {
70+
conn.getMetaData.getTables(null, schemaPattern, "%", Array("TABLE"))
71+
}
7072
new Iterator[Identifier] {
7173
def hasNext = rs.next()
7274
def next() = Identifier.of(namespace, rs.getString("TABLE_NAME"))
@@ -179,14 +181,18 @@ class JDBCTableCatalog extends TableCatalog
179181
override def namespaceExists(namespace: Array[String]): Boolean = namespace match {
180182
case Array(db) =>
181183
JdbcUtils.withConnection(options) { conn =>
182-
JdbcUtils.schemaExists(conn, options, db)
184+
JdbcUtils.classifyException(s"Failed namespace exists: ${namespace.mkString}", dialect) {
185+
JdbcUtils.schemaExists(conn, options, db)
186+
}
183187
}
184188
case _ => false
185189
}
186190

187191
override def listNamespaces(): Array[Array[String]] = {
188192
JdbcUtils.withConnection(options) { conn =>
189-
JdbcUtils.listSchemas(conn, options)
193+
JdbcUtils.classifyException(s"Failed list namespaces", dialect) {
194+
JdbcUtils.listSchemas(conn, options)
195+
}
190196
}
191197
}
192198

0 commit comments

Comments
 (0)