LuciferYang commented on code in PR #58225:
URL: https://github.com/apache/spark/pull/58225#discussion_r3935136162
##########
sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala:
##########
@@ -228,7 +234,10 @@ private[sql] case class H2Dialect() extends JdbcDialect
with NoLegacyJDBCError {
val relationName = messageParameters.getOrElse("tableName", "")
throw new NoSuchTableException(
errorClass = "TABLE_OR_VIEW_NOT_FOUND",
- messageParameters = Map("relationName" -> relationName),
+ messageParameters = Map(
+ "relationName" -> relationName,
Review Comment:
`case 42102` isn't narrowed by `condition` the way 42111/42112 right below
it are, and `relationName` comes from `messageParameters.getOrElse("tableName",
"")`. In `JDBCTableCatalog`, `renameTable` is the only caller that can hit
"table not found" while passing `oldName`/`newName` instead of `tableName`
(JDBCTableCatalog.scala:142-145); `dropTable`, `tableExists`, `loadTable`,
`createTable`, `alterTable` and `JDBCTable`'s index methods all pass it. So
renaming a missing table renders `The table or view cannot be found.` with an
empty relation name. Before this change the same path produced
`INTERNAL_ERROR`, so this message is new.
The cheap fix is to fall back to `oldName` when `tableName` is absent; it is
already `toSQLId`-quoted at `JDBCTableCatalog.scala:144`. Narrowing the branch
by `condition` so rename falls through to `super.classifyException` also works,
but then it raises a generic `AnalysisException`, and
`TableCatalog.renameTable` documents `NoSuchTableException`.
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala:
##########
@@ -229,6 +230,21 @@ class JDBCTableCatalogSuite extends SharedSparkSession {
}
}
+ test("SPARK-58945: H2 dialect supplies searchPath for
TABLE_OR_VIEW_NOT_FOUND") {
+ val e = intercept[NoSuchTableException] {
+ H2Dialect().classifyException(
+ new SQLException("""Table "NOT_EXISTING_TABLE" not found""", "42S02",
42102),
+ condition = "FAILED_JDBC.LOAD_TABLE",
Review Comment:
This test builds a `FAILED_JDBC.LOAD_TABLE` plus error code 42102 pair that
cannot occur in production: `JDBCRDD.resolveTable` (JDBCRDD.scala:79-81)
intercepts first via `dialect.isObjectNotFoundException`, H2 lists 42102 in
that set (H2Dialect.scala:65-67), and it throws `noSuchTableError(catalogName,
ident)`. `JdbcUtils.classifyException` (JdbcUtils.scala:1214) then rethrows any
`SparkThrowable` unwrapped, so `dialect.classifyException` is never reached.
`case 42102` is reachable through the direct `TableCatalog` API methods, or
through a race where the table is dropped after analysis.
Driving it through `renameTable` instead (load the catalog the way
`JDBCV2Suite.scala:3100` does, then rename a table that does not exist) avoids
hand-building the condition and the parameters, and surfaces the blank relation
name that `case 42102` renders.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]