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 c90cad6ad2d1 [SPARK-21529][SQL] Improve the error message for 
unsupported Hive union type
c90cad6ad2d1 is described below

commit c90cad6ad2d1c70e630f55aab6b652f4ba9fcfb4
Author: AgenticSpark <[email protected]>
AuthorDate: Wed Jul 1 16:37:07 2026 +0200

    [SPARK-21529][SQL] Improve the error message for unsupported Hive union type
    
    ### What changes were proposed in this pull request?
    
    Detect unsupported Hive `uniontype<...>` values when converting Hive 
`FieldSchema` types to Spark SQL types and raise a dedicated 
`UNSUPPORTED_HIVE_TYPE` error instead of the generic 
`CANNOT_RECOGNIZE_HIVE_TYPE` parser error.
    
    ### Why are the changes needed?
    
    Spark SQL does not support Hive union types. Today the failure message 
comes from the parser path and does not clearly identify that the Hive union 
type is unsupported.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. Reading a Hive table column that uses `uniontype<...>` now reports 
`UNSUPPORTED_HIVE_TYPE` with the offending Hive type and column name.
    
    ### How was this patch tested?
    
    - `SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "core/testOnly 
*SparkThrowableSuite -- -t \"Error conditions are correctly formatted\""`
    - `build/sbt "hive/testOnly *HiveClientImplSuite"`
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Yes. GitHub Copilot assisted with preparing and validating this change.
    
    Closes #56775 from AgenticSpark/agenticspark/SPARK-21529-uniontype-error.
    
    Authored-by: AgenticSpark <[email protected]>
    Signed-off-by: Max Gekk <[email protected]>
---
 .../src/main/resources/error/error-conditions.json |  6 +++
 .../spark/sql/errors/QueryExecutionErrors.scala    |  7 ++++
 .../spark/sql/hive/client/HiveClientImpl.scala     |  5 +++
 .../sql/hive/client/HiveClientImplSuite.scala      | 49 ++++++++++++++++++++++
 4 files changed, 67 insertions(+)

diff --git a/common/utils/src/main/resources/error/error-conditions.json 
b/common/utils/src/main/resources/error/error-conditions.json
index af7007c17f6f..baf168c5c97c 100644
--- a/common/utils/src/main/resources/error/error-conditions.json
+++ b/common/utils/src/main/resources/error/error-conditions.json
@@ -8675,6 +8675,12 @@
     ],
     "sqlState" : "0A000"
   },
+  "UNSUPPORTED_HIVE_TYPE" : {
+    "message" : [
+      "Cannot read the Hive type <fieldType> of the column <fieldName> because 
Spark SQL does not support this data type."
+    ],
+    "sqlState" : "0A000"
+  },
   "UNSUPPORTED_INSERT" : {
     "message" : [
       "Can't insert into the target."
diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
index d11f2e6742a6..ad426c347914 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
@@ -1696,6 +1696,13 @@ private[sql] object QueryExecutionErrors extends 
QueryErrorsBase with ExecutionE
       cause = e)
   }
 
+  def unsupportedHiveTypeError(fieldType: String, fieldName: String): 
Throwable = {
+    new SparkUnsupportedOperationException(
+      errorClass = "UNSUPPORTED_HIVE_TYPE",
+      messageParameters = Map(
+        "fieldType" -> toSQLType(fieldType),
+        "fieldName" -> toSQLId(fieldName)))
+  }
   def getTablesByTypeUnsupportedByHiveVersionError(): 
SparkUnsupportedOperationException = {
     new SparkUnsupportedOperationException(
       errorClass = "GET_TABLES_BY_TYPE_UNSUPPORTED_BY_HIVE_VERSION")
diff --git 
a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala 
b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
index ed9bcf74b2f5..d1c6b7c20e37 100644
--- 
a/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
+++ 
b/sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala
@@ -1144,6 +1144,11 @@ private[hive] object HiveClientImpl extends Logging {
       CatalystSqlParser.parseDataType(typeStr)
     } catch {
       case e: ParseException =>
+        // Hive's union type (uniontype<...>) is not supported by Spark SQL 
and makes the parser
+        // fail with a generic message. Detect it and report a clearer error 
(SPARK-21529).
+        if (hc.getType.toLowerCase(Locale.ROOT).contains("uniontype<")) {
+          throw QueryExecutionErrors.unsupportedHiveTypeError(hc.getType, 
hc.getName)
+        }
         throw QueryExecutionErrors.cannotRecognizeHiveTypeError(e, typeStr, 
hc.getName)
     }
   }
diff --git 
a/sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientImplSuite.scala
 
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientImplSuite.scala
new file mode 100644
index 000000000000..9bee44f8f57e
--- /dev/null
+++ 
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/client/HiveClientImplSuite.scala
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.hive.client
+
+import org.apache.hadoop.hive.metastore.api.FieldSchema
+
+import org.apache.spark.{SparkFunSuite, SparkUnsupportedOperationException}
+
+class HiveClientImplSuite extends SparkFunSuite {
+
+  test("SPARK-21529: a clear error is raised for an unsupported Hive union 
type") {
+    val column = new FieldSchema("c", "uniontype<int,string>", null)
+    checkError(
+      exception = intercept[SparkUnsupportedOperationException] {
+        HiveClientImpl.fromHiveColumn(column)
+      },
+      condition = "UNSUPPORTED_HIVE_TYPE",
+      parameters = Map(
+        "fieldType" -> "\"UNIONTYPE<INT,STRING>\"",
+        "fieldName" -> "`c`"))
+  }
+
+  test("SPARK-21529: a Hive union type nested in a struct is detected") {
+    val column = new FieldSchema("c", "struct<a:uniontype<int,string>>", null)
+    checkError(
+      exception = intercept[SparkUnsupportedOperationException] {
+        HiveClientImpl.fromHiveColumn(column)
+      },
+      condition = "UNSUPPORTED_HIVE_TYPE",
+      parameters = Map(
+        "fieldType" -> "\"STRUCT<A:UNIONTYPE<INT,STRING>>\"",
+        "fieldName" -> "`c`"))
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to