This is an automated email from the ASF dual-hosted git repository.
szehon-ho pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new 822eb31f0093 [SPARK-57762][SQL] Add missing error class
COLUMN_IS_NOT_VARIANT_TYPE
822eb31f0093 is described below
commit 822eb31f00936ceff95540e1a36d7a2b636a2131
Author: Szehon Ho <[email protected]>
AuthorDate: Tue Jul 21 15:40:51 2026 -0700
[SPARK-57762][SQL] Add missing error class COLUMN_IS_NOT_VARIANT_TYPE
### What changes were proposed in this pull request?
The semi-structured extraction operator (`:`) throws the
`COLUMN_IS_NOT_VARIANT_TYPE` error class (from `ExtractSemiStructuredFields`
and `SemiStructuredExtractResolver`) when applied to a column that is not of
the VARIANT type, but the error class was never registered in
`error-conditions.json`. This registers the error condition so it resolves
correctly through the error framework, and adds a test.
### Why are the changes needed?
The error class was used but not declared. Hitting this path raised
`INTERNAL_ERROR` ("Cannot find main error class 'COLUMN_IS_NOT_VARIANT_TYPE'")
instead of the intended error.
### Does this PR introduce _any_ user-facing change?
No. Previously this code path raised an `INTERNAL_ERROR` because the error
class was unregistered; now the intended error message is produced.
### How was this patch tested?
Added a unit test in `QueryCompilationErrorsSuite`. Also ran
`SparkThrowableSuite`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor (Claude Opus 4.8)
Closes #56872 from szehon-ho/SPARK-57762.
Authored-by: Szehon Ho <[email protected]>
Signed-off-by: Szehon Ho <[email protected]>
(cherry picked from commit aec7c171b163cbce628c0b50cb2675c160e594df)
Signed-off-by: Szehon Ho <[email protected]>
---
common/utils/src/main/resources/error/error-conditions.json | 6 ++++++
.../analyzer-results/type-coercion-edge-cases.sql.out | 9 +++------
.../sql-tests/results/type-coercion-edge-cases.sql.out | 9 +++------
.../apache/spark/sql/errors/QueryCompilationErrorsSuite.scala | 10 ++++++++++
4 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/common/utils/src/main/resources/error/error-conditions.json
b/common/utils/src/main/resources/error/error-conditions.json
index b6421da945b2..3194a0fba097 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -1064,6 +1064,12 @@
],
"sqlState" : "0A000"
},
+ "COLUMN_IS_NOT_VARIANT_TYPE" : {
+ "message" : [
+ "The semi-structured extraction operator (`:`) can only be applied to a
column of the VARIANT type."
+ ],
+ "sqlState" : "42K09"
+ },
"COLUMN_NOT_DEFINED_IN_TABLE" : {
"message" : [
"<colType> column <colName> is not defined in table <tableName>, defined
table columns are: <tableCols>."
diff --git
a/sql/core/src/test/resources/sql-tests/analyzer-results/type-coercion-edge-cases.sql.out
b/sql/core/src/test/resources/sql-tests/analyzer-results/type-coercion-edge-cases.sql.out
index e99594808b80..95d12ce49f50 100644
---
a/sql/core/src/test/resources/sql-tests/analyzer-results/type-coercion-edge-cases.sql.out
+++
b/sql/core/src/test/resources/sql-tests/analyzer-results/type-coercion-edge-cases.sql.out
@@ -24,13 +24,10 @@ Project [col2#x[cast(field as bigint)] AS field#x]
-- !query
SELECT NULL:a AS b
-- !query analysis
-org.apache.spark.SparkException
+org.apache.spark.sql.AnalysisException
{
- "errorClass" : "INTERNAL_ERROR",
- "sqlState" : "XX000",
- "messageParameters" : {
- "message" : "Cannot find main error class 'COLUMN_IS_NOT_VARIANT_TYPE'"
- }
+ "errorClass" : "COLUMN_IS_NOT_VARIANT_TYPE",
+ "sqlState" : "42K09"
}
diff --git
a/sql/core/src/test/resources/sql-tests/results/type-coercion-edge-cases.sql.out
b/sql/core/src/test/resources/sql-tests/results/type-coercion-edge-cases.sql.out
index da0ceafa8938..584bf6e9a796 100644
---
a/sql/core/src/test/resources/sql-tests/results/type-coercion-edge-cases.sql.out
+++
b/sql/core/src/test/resources/sql-tests/results/type-coercion-edge-cases.sql.out
@@ -45,13 +45,10 @@ SELECT NULL:a AS b
-- !query schema
struct<>
-- !query output
-org.apache.spark.SparkException
+org.apache.spark.sql.AnalysisException
{
- "errorClass" : "INTERNAL_ERROR",
- "sqlState" : "XX000",
- "messageParameters" : {
- "message" : "Cannot find main error class 'COLUMN_IS_NOT_VARIANT_TYPE'"
- }
+ "errorClass" : "COLUMN_IS_NOT_VARIANT_TYPE",
+ "sqlState" : "42K09"
}
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 c626d7183513..3f81b1e6d5b4 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
@@ -413,6 +413,16 @@ class QueryCompilationErrorsSuite
)
}
+ test("COLUMN_IS_NOT_VARIANT_TYPE: semi-structured extraction on non-variant
column") {
+ checkError(
+ exception = intercept[AnalysisException] {
+ sql("SELECT id:field FROM range(1)")
+ },
+ condition = "COLUMN_IS_NOT_VARIANT_TYPE",
+ parameters = Map.empty[String, String]
+ )
+ }
+
test("UNRESOLVED_MAP_KEY: string type literal should be quoted") {
checkAnswer(sql("select m['a'] from (select map('a', 'b') as m, 'aa' as
aa)"), Row("b"))
val query = "select m[a] from (select map('a', 'b') as m, 'aa' as aa)"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]