This is an automated email from the ASF dual-hosted git repository. wenchen 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 9c5384595c8 [SPARK-41976][SQL] Improve error message for `INDEX_NOT_FOUND` 9c5384595c8 is described below commit 9c5384595c8e19afba109b6d38a27856e50c1bc1 Author: itholic <haejoon....@databricks.com> AuthorDate: Fri Jan 20 14:53:53 2023 +0800 [SPARK-41976][SQL] Improve error message for `INDEX_NOT_FOUND` ### What changes were proposed in this pull request? This PR proposes to improve error message for `INDEX_NOT_FOUND`. ### Why are the changes needed? Make the error message more clear and proper. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Fix UT and `./build/sbt "sql/testOnly org.apache.spark.sql.SQLQueryTestSuite*` Closes #39498 from itholic/INDEX_NOT_FOUND. Authored-by: itholic <haejoon....@databricks.com> Signed-off-by: Wenchen Fan <wenc...@databricks.com> --- .../test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala | 11 +++++++---- core/src/main/resources/error/error-classes.json | 2 +- .../spark/sql/catalyst/analysis/NoSuchItemException.scala | 4 ++-- .../src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala | 6 +++++- .../main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala | 6 +++++- .../scala/org/apache/spark/sql/jdbc/PostgresDialect.scala | 7 ++++++- .../test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala | 4 +--- 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala b/connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala index 5bedcbd172e..f16d9b507d5 100644 --- a/connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala +++ b/connector/docker-integration-tests/src/test/scala/org/apache/spark/sql/jdbc/v2/V2JDBCTest.scala @@ -278,10 +278,13 @@ private[v2] trait V2JDBCTest extends SharedSparkSession with DockerIntegrationFu // This should pass without exception sql(s"DROP index IF EXISTS i1 ON $catalogName.new_table") - m = intercept[NoSuchIndexException] { - sql(s"DROP index i1 ON $catalogName.new_table") - }.getMessage - assert(m.contains("Failed to drop index i1 in new_table")) + checkError( + exception = intercept[NoSuchIndexException] { + sql(s"DROP index i1 ON $catalogName.new_table") + }, + errorClass = "INDEX_NOT_FOUND", + parameters = Map("indexName" -> "i1", "tableName" -> "new_table") + ) } } } diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json index 993d1d084e7..5340ba2abc2 100644 --- a/core/src/main/resources/error/error-classes.json +++ b/core/src/main/resources/error/error-classes.json @@ -659,7 +659,7 @@ }, "INDEX_NOT_FOUND" : { "message" : [ - "Cannot find the index. <message>." + "Cannot find the index <indexName> on table <tableName>." ], "sqlState" : "42704" }, diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/NoSuchItemException.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/NoSuchItemException.scala index f6624126e94..8dd46c06e76 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/NoSuchItemException.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/NoSuchItemException.scala @@ -131,6 +131,6 @@ class NoSuchPartitionsException(errorClass: String, messageParameters: Map[Strin class NoSuchTempFunctionException(func: String) extends AnalysisException(errorClass = "ROUTINE_NOT_FOUND", Map("routineName" -> s"`$func`")) -class NoSuchIndexException(message: String, cause: Option[Throwable] = None) +class NoSuchIndexException(indexName: String, tableName: String, cause: Option[Throwable] = None) extends AnalysisException(errorClass = "INDEX_NOT_FOUND", - Map("message" -> message), cause) + Map("indexName" -> indexName, "tableName" -> tableName), cause) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala index eac3dab4f6b..5ede793f6d1 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/H2Dialect.scala @@ -216,7 +216,11 @@ private[sql] object H2Dialect extends JdbcDialect { indexName = indexName, tableName = tableName, cause = Some(e)) // INDEX_NOT_FOUND_1 case 42112 => - throw new NoSuchIndexException(message, cause = Some(e)) + // The message is: Failed to drop index indexName in tableName + val regex = "(?s)Failed to drop index (.*) in (.*)".r + val indexName = regex.findFirstMatchIn(message).get.group(1) + val tableName = regex.findFirstMatchIn(message).get.group(2) + throw new NoSuchIndexException(indexName, tableName, cause = Some(e)) case _ => // do nothing } case _ => // do nothing diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala index 5f15bdf9113..12882dc8e67 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/MySQLDialect.scala @@ -258,7 +258,11 @@ private case object MySQLDialect extends JdbcDialect with SQLConfHelper { throw new IndexAlreadyExistsException( indexName = indexName, tableName = tableName, cause = Some(e)) case 1091 => - throw new NoSuchIndexException(message, cause = Some(e)) + // The message is: Failed to drop index indexName in tableName + val regex = "(?s)Failed to drop index (.*) in (.*)".r + val indexName = regex.findFirstMatchIn(message).get.group(1) + val tableName = regex.findFirstMatchIn(message).get.group(2) + throw new NoSuchIndexException(indexName, tableName, cause = Some(e)) case _ => super.classifyException(message, e) } case unsupported: UnsupportedOperationException => throw unsupported diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala index dd0107beb94..c2ca45d9143 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/PostgresDialect.scala @@ -230,7 +230,12 @@ private object PostgresDialect extends JdbcDialect with SQLConfHelper { val tableName = regex.findFirstMatchIn(message).get.group(2) throw new IndexAlreadyExistsException( indexName = indexName, tableName = tableName, cause = Some(e)) - case "42704" => throw new NoSuchIndexException(message, cause = Some(e)) + case "42704" => + // The message is: Failed to drop index indexName in tableName + val regex = "(?s)Failed to drop index (.*) in (.*)".r + val indexName = regex.findFirstMatchIn(message).get.group(1) + val tableName = regex.findFirstMatchIn(message).get.group(2) + throw new NoSuchIndexException(indexName, tableName, cause = Some(e)) case "2BP01" => throw NonEmptyNamespaceException(message, cause = Some(e)) case _ => super.classifyException(message, e) } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala index d3563219485..6835c6bbc69 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCV2Suite.scala @@ -2667,9 +2667,7 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel sql(s"DROP INDEX people_index ON TABLE h2.test.people") }, errorClass = "INDEX_NOT_FOUND", - parameters = Map( - "message" -> "Failed to drop index people_index in test.people" - ) + parameters = Map("indexName" -> "people_index", "tableName" -> "test.people") ) assert(jdbcTable.indexExists("people_index") == false) val indexes3 = jdbcTable.listIndexes() --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org