-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-21529][SQL] Improve the error message for unsupported Hive union type #56775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ee5fb78
7b8dbca
aedba32
c52eb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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))) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you clarify what was the previous error message, @AgenticSpark ?
|
||
| throw QueryExecutionErrors.cannotRecognizeHiveTypeError(e, typeStr, hc.getName) | ||
| } | ||
| } | ||
|
|
||
| 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`")) | ||
| } | ||
| } |
There was a problem hiding this comment.
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:
i.e. the
UNSUPPORTED_HIVE_TYPEclosing 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: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 unrelatedtimestampNanos…rename is reverted here.)