You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2023/02/04 12:19:35 UTC
[spark] branch master updated: [SPARK-41302][SQL] Assign name to _LEGACY_ERROR_TEMP_1185
This is an automated email from the ASF dual-hosted git repository.
maxgekk 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 c49415412e3 [SPARK-41302][SQL] Assign name to _LEGACY_ERROR_TEMP_1185
c49415412e3 is described below
commit c49415412e3027a171c2691df97fe8757f26a0aa
Author: narek_karapetian <na...@yandex.ru>
AuthorDate: Sat Feb 4 15:18:53 2023 +0300
[SPARK-41302][SQL] Assign name to _LEGACY_ERROR_TEMP_1185
### What changes were proposed in this pull request?
This PR proposes to assign name to `_LEGACY_ERROR_TEMP_1185` -> `IDENTIFIER_TOO_MANY_NAME_PARTS`
### Why are the changes needed?
We should assign proper name to LEGACY_ERROR_TEMP*
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Additional test cases were added
Closes #39723 from NarekDW/SPARK-41302.
Lead-authored-by: narek_karapetian <na...@yandex.ru>
Co-authored-by: Narek Karapetian <na...@yandex.ru>
Signed-off-by: Max Gekk <ma...@gmail.com>
---
core/src/main/resources/error/error-classes.json | 11 +++----
.../sql/connector/catalog/CatalogV2Implicits.scala | 20 +++++--------
.../spark/sql/errors/QueryCompilationErrors.scala | 9 ++----
.../sql/errors/QueryCompilationErrorsSuite.scala | 35 ++++++++++++++++++++++
.../datasources/v2/V2SessionCatalogSuite.scala | 18 +++++++++++
.../org/apache/spark/sql/jdbc/JDBCV2Suite.scala | 19 ++++++++++++
6 files changed, 89 insertions(+), 23 deletions(-)
diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json
index 67de6c6a29d..7ecd924ea8d 100644
--- a/core/src/main/resources/error/error-classes.json
+++ b/core/src/main/resources/error/error-classes.json
@@ -575,6 +575,12 @@
],
"sqlState" : "42805"
},
+ "IDENTIFIER_TOO_MANY_NAME_PARTS" : {
+ "message" : [
+ "<identifier> is not a valid identifier as it has more than 2 name parts."
+ ],
+ "sqlState" : "42601"
+ },
"INCOMPARABLE_PIVOT_COLUMN" : {
"message" : [
"Invalid pivot column <columnName>. Pivot columns must be comparable."
@@ -2851,11 +2857,6 @@
"Catalog <plugin> does not support <ability>."
]
},
- "_LEGACY_ERROR_TEMP_1185" : {
- "message" : [
- "<quoted> is not a valid <identifier> as it has more than 2 name parts."
- ]
- },
"_LEGACY_ERROR_TEMP_1186" : {
"message" : [
"Multi-part identifier cannot be empty."
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala
index d9f15d84d89..0c9282f9675 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/connector/catalog/CatalogV2Implicits.scala
@@ -130,22 +130,20 @@ private[sql] object CatalogV2Implicits {
}
}
+ def original: String = ident.namespace() :+ ident.name() mkString "."
+
def asMultipartIdentifier: Seq[String] = ident.namespace :+ ident.name
def asTableIdentifier: TableIdentifier = ident.namespace match {
case ns if ns.isEmpty => TableIdentifier(ident.name)
case Array(dbName) => TableIdentifier(ident.name, Some(dbName))
- case _ =>
- throw QueryCompilationErrors.identifierHavingMoreThanTwoNamePartsError(
- quoted, "TableIdentifier")
+ case _ => throw QueryCompilationErrors.identifierTooManyNamePartsError(original)
}
def asFunctionIdentifier: FunctionIdentifier = ident.namespace() match {
case ns if ns.isEmpty => FunctionIdentifier(ident.name())
case Array(dbName) => FunctionIdentifier(ident.name(), Some(dbName))
- case _ =>
- throw QueryCompilationErrors.identifierHavingMoreThanTwoNamePartsError(
- quoted, "FunctionIdentifier")
+ case _ => throw QueryCompilationErrors.identifierTooManyNamePartsError(original)
}
}
@@ -159,20 +157,18 @@ private[sql] object CatalogV2Implicits {
def asTableIdentifier: TableIdentifier = parts match {
case Seq(tblName) => TableIdentifier(tblName)
case Seq(dbName, tblName) => TableIdentifier(tblName, Some(dbName))
- case _ =>
- throw QueryCompilationErrors.identifierHavingMoreThanTwoNamePartsError(
- quoted, "TableIdentifier")
+ case _ => throw QueryCompilationErrors.identifierTooManyNamePartsError(original)
}
def asFunctionIdentifier: FunctionIdentifier = parts match {
case Seq(funcName) => FunctionIdentifier(funcName)
case Seq(dbName, funcName) => FunctionIdentifier(funcName, Some(dbName))
- case _ =>
- throw QueryCompilationErrors.identifierHavingMoreThanTwoNamePartsError(
- quoted, "FunctionIdentifier")
+ case _ => throw QueryCompilationErrors.identifierTooManyNamePartsError(original)
}
def quoted: String = parts.map(quoteIfNeeded).mkString(".")
+
+ def original: String = parts.mkString(".")
}
implicit class TableIdentifierHelper(identifier: TableIdentifier) {
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
index 35b1b185e8c..0bc3b2fc4f6 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
@@ -1874,13 +1874,10 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {
"ability" -> ability))
}
- def identifierHavingMoreThanTwoNamePartsError(
- quoted: String, identifier: String): Throwable = {
+ def identifierTooManyNamePartsError(originalIdentifier: String): Throwable = {
new AnalysisException(
- errorClass = "_LEGACY_ERROR_TEMP_1185",
- messageParameters = Map(
- "quoted" -> quoted,
- "identifier" -> identifier))
+ errorClass = "IDENTIFIER_TOO_MANY_NAME_PARTS",
+ messageParameters = Map("identifier" -> toSQLId(originalIdentifier)))
}
def emptyMultipartIdentifierError(): Throwable = {
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
index f674ac6e1f6..55964afba74 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/errors/QueryCompilationErrorsSuite.scala
@@ -19,6 +19,7 @@ package org.apache.spark.sql.errors
import org.apache.spark.sql.{AnalysisException, ClassData, IntegratedUDFTestUtils, QueryTest, Row}
import org.apache.spark.sql.api.java.{UDF1, UDF2, UDF23Test}
+import org.apache.spark.sql.catalyst.parser.ParseException
import org.apache.spark.sql.expressions.SparkUserDefinedFunction
import org.apache.spark.sql.functions.{from_json, grouping, grouping_id, lit, struct, sum, udf}
import org.apache.spark.sql.internal.SQLConf
@@ -680,6 +681,40 @@ class QueryCompilationErrorsSuite
context = ExpectedContext("", "", 7, 13, "CAST(1)")
)
}
+
+ test("IDENTIFIER_TOO_MANY_NAME_PARTS: " +
+ "create temp view doesn't support identifiers consisting of more than 2 parts") {
+ checkError(
+ exception = intercept[ParseException] {
+ sql("CREATE TEMPORARY VIEW db_name.schema_name.view_name AS SELECT '1' as test_column")
+ },
+ errorClass = "IDENTIFIER_TOO_MANY_NAME_PARTS",
+ sqlState = "42601",
+ parameters = Map("identifier" -> "`db_name`.`schema_name`.`view_name`")
+ )
+ }
+
+ test("IDENTIFIER_TOO_MANY_NAME_PARTS: " +
+ "alter table doesn't support identifiers consisting of more than 2 parts") {
+ val tableName: String = "t"
+ withTable(tableName) {
+ sql(
+ s"""
+ |CREATE TABLE $tableName (a STRING, b INT, c STRING, d STRING)
+ |USING parquet
+ |PARTITIONED BY (c, d)
+ |""".stripMargin)
+
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql(s"ALTER TABLE $tableName RENAME TO db_name.schema_name.new_table_name")
+ },
+ errorClass = "IDENTIFIER_TOO_MANY_NAME_PARTS",
+ sqlState = "42601",
+ parameters = Map("identifier" -> "`db_name`.`schema_name`.`new_table_name`")
+ )
+ }
+ }
}
class MyCastToString extends SparkUserDefinedFunction(
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala
index 3dfe6063877..2a441157f9d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/V2SessionCatalogSuite.scala
@@ -1119,4 +1119,22 @@ class V2SessionCatalogNamespaceSuite extends V2SessionCatalogBaseSuite {
}
catalog.dropNamespace(testNs, cascade = false)
}
+
+ test("IdentifierHelper should throw exception when identifier has more than 2 parts") {
+ val testIdent: IdentifierHelper = Identifier.of(Array("a", "b"), "c")
+ checkError(
+ exception = intercept[AnalysisException](testIdent.asTableIdentifier),
+ errorClass = "IDENTIFIER_TOO_MANY_NAME_PARTS",
+ parameters = Map("identifier" -> "`a`.`b`.`c`")
+ )
+ }
+
+ test("MultipartIdentifierHelper should throw exception when identifier has more than 2 parts") {
+ val testIdent: MultipartIdentifierHelper = Seq("a", "b", "c")
+ checkError(
+ exception = intercept[AnalysisException](testIdent.asFunctionIdentifier),
+ errorClass = "IDENTIFIER_TOO_MANY_NAME_PARTS",
+ parameters = Map("identifier" -> "`a`.`b`.`c`")
+ )
+ }
}
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 6835c6bbc69..2093fe66dd7 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
@@ -2673,4 +2673,23 @@ class JDBCV2Suite extends QueryTest with SharedSparkSession with ExplainSuiteHel
val indexes3 = jdbcTable.listIndexes()
assert(indexes3.isEmpty)
}
+
+ test("IDENTIFIER_TOO_MANY_NAME_PARTS: " +
+ "jdbc function doesn't support identifiers consisting of more than 2 parts") {
+ JdbcDialects.unregisterDialect(H2Dialect)
+ try {
+ JdbcDialects.registerDialect(testH2Dialect)
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql("SELECT * FROM h2.test.people where h2.db_name.schema_name.function_name()")
+ },
+ errorClass = "IDENTIFIER_TOO_MANY_NAME_PARTS",
+ sqlState = "42601",
+ parameters = Map("identifier" -> "`db_name`.`schema_name`.`function_name`")
+ )
+ } finally {
+ JdbcDialects.unregisterDialect(testH2Dialect)
+ JdbcDialects.registerDialect(H2Dialect)
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org