[SPARK-48176][SQL] Adjust name of FIELD_ALREADY_EXISTS error condition
### What changes were proposed in this pull request?
Rename `FIELDS_ALREADY_EXISTS` to `FIELD_ALREADY_EXISTS`.
### Why are the changes needed?
Though it's not meant to be a proper English sentence, `FIELDS_ALREADY_EXISTS` is grammatically incorrect. It should either be "fields already exist[]" or "field[] already exists". I opted for the latter.
### Does this PR introduce _any_ user-facing change?
Yes, it changes the name of an error condition.
### How was this patch tested?
CI only.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #46510 from nchammas/SPARK-48176-field-exists-error.
Authored-by: Nicholas Chammas <nicholas.chammas@gmail.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
diff --git a/common/utils/src/main/resources/error/error-conditions.json b/common/utils/src/main/resources/error/error-conditions.json
index 8a64c4c..7c9886c 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -1339,7 +1339,7 @@
],
"sqlState" : "54001"
},
- "FIELDS_ALREADY_EXISTS" : {
+ "FIELD_ALREADY_EXISTS" : {
"message" : [
"Cannot <op> column, because <fieldNames> already exists in <struct>."
],
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 c80fbfc..b60107f 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
@@ -107,7 +107,7 @@
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $catalogName.alt_table ADD COLUMNS (C3 DOUBLE)")
},
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
parameters = Map(
"op" -> "add",
"fieldNames" -> "`C3`",
@@ -179,7 +179,7 @@
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $catalogName.alt_table RENAME COLUMN ID1 TO ID2")
},
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
parameters = Map(
"op" -> "rename",
"fieldNames" -> "`ID2`",
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
index e55f23b..e18f4d1 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
@@ -1403,7 +1403,7 @@
if (struct.findNestedField(
fieldNames, includeCollections = true, alter.conf.resolver).isDefined) {
alter.failAnalysis(
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
messageParameters = Map(
"op" -> op,
"fieldNames" -> toSQLId(fieldNames),
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/connector/AlterTableTests.scala b/sql/core/src/test/scala/org/apache/spark/sql/connector/AlterTableTests.scala
index 996d7ac..2860595 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/connector/AlterTableTests.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/connector/AlterTableTests.scala
@@ -466,7 +466,7 @@
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $t ADD COLUMNS $field double")
},
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
parameters = expectedParameters,
context = ExpectedContext(
fragment = s"ALTER TABLE $t ADD COLUMNS $field double",
@@ -1116,7 +1116,7 @@
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $t RENAME COLUMN $field TO $newName")
},
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
parameters = Map(
"op" -> "rename",
"fieldNames" -> s"${toSQLId(expectedName)}",
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/connector/V2CommandsCaseSensitivitySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/connector/V2CommandsCaseSensitivitySuite.scala
index ee71bd3..3ab7edb 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/connector/V2CommandsCaseSensitivitySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/connector/V2CommandsCaseSensitivitySuite.scala
@@ -306,7 +306,7 @@
None,
Some(UnresolvedFieldPosition(ColumnPosition.after("id"))),
None))),
- "FIELDS_ALREADY_EXISTS",
+ "FIELD_ALREADY_EXISTS",
Map(
"op" -> "add",
"fieldNames" -> "`ID`",
@@ -317,7 +317,7 @@
test("SPARK-36381: Check column name exist case sensitive and insensitive when rename column") {
alterTableErrorClass(
RenameColumn(table, UnresolvedFieldName(Array("id").toImmutableArraySeq), "DATA"),
- "FIELDS_ALREADY_EXISTS",
+ "FIELD_ALREADY_EXISTS",
Map(
"op" -> "rename",
"fieldNames" -> "`DATA`",
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala
index f4e7921..daf5d85 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/JDBCTableCatalogSuite.scala
@@ -200,7 +200,7 @@
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $tableName ADD COLUMNS (c3 DOUBLE)")
},
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
parameters = Map(
"op" -> "add",
"fieldNames" -> "`c3`",
@@ -239,7 +239,7 @@
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $tableName RENAME COLUMN C TO C0")
},
- errorClass = "FIELDS_ALREADY_EXISTS",
+ errorClass = "FIELD_ALREADY_EXISTS",
parameters = Map(
"op" -> "rename",
"fieldNames" -> "`C0`",