Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8561,6 +8561,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."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few lines below this, the new entry closes as:

  },  "UNSUPPORTED_INSERT" : {

i.e. the UNSUPPORTED_HIVE_TYPE closing brace and the next error key are on the same line (missing newline). SparkThrowableSuite's "Error conditions are correctly formatted" test re-serializes the error map with a pretty-printer (one key per line) and asserts the file matches exactly, so this will fail CI:

  },
  "UNSUPPORTED_INSERT" : {

Alphabetical placement (HIVE_TYPE before INSERT) is correct — only the line break is missing. Re-running SPARK_GENERATE_GOLDEN_FILES=1 … SparkThrowableSuite -- -t "Error conditions are correctly formatted" regenerates it correctly. (Otherwise the detection logic and tests look good, and the unrelated timestampNanos… rename is reverted here.)

],
"sqlState" : "0A000"
},
"UNSUPPORTED_INSERT" : {
"message" : [
"Can't insert into the target."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,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)))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. We need a new line after this.

def getTablesByTypeUnsupportedByHiveVersionError(): SparkUnsupportedOperationException = {
new SparkUnsupportedOperationException(
errorClass = "GET_TABLES_BY_TYPE_UNSUPPORTED_BY_HIVE_VERSION")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify what was the previous error message, @AgenticSpark ?

Today the failure message comes from the parser path and does not clearly identify that the Hive union type is unsupported.

throw QueryExecutionErrors.cannotRecognizeHiveTypeError(e, typeStr, hc.getName)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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`"))
}
}