[SPARK-57556][SQL] Raise a clear error for the TIME data type in Hive SerDe interop#56850
Open
MaxGekk wants to merge 2 commits into
Open
[SPARK-57556][SQL] Raise a clear error for the TIME data type in Hive SerDe interop#56850MaxGekk wants to merge 2 commits into
MaxGekk wants to merge 2 commits into
Conversation
… SerDe interop ### What changes were proposed in this pull request? Apache Hive has no TIME type, so `TimeType` has no faithful representation in Hive SerDe interop. This PR makes `TimeType` produce a clear `AnalysisException` instead of a `scala.MatchError` or an internal error when it reaches the `HiveInspectors` mapping functions, and rejects it in the Hive SerDe write path: - `HiveInspectors.toInspector(dataType)`, `toInspector(expr)` (TIME literal) and `toTypeInfo` now throw `UNSUPPORTED_DATATYPE` via a shared helper. - `HiveFileFormat.supportDataType` rejects `TimeType` (recursing into nested types) so Hive SerDe writes raise `UNSUPPORTED_DATA_TYPE_FOR_DATASOURCE`. ### Why are the changes needed? `HiveInspectors` had no `TimeType` case, so object-inspector creation and TypeInfo mapping fell through to a `MatchError`/internal error when a TIME column or literal reached Hive SerDe paths (e.g. a Hive UDF argument). This makes the behavior explicit and documented, consistent with the existing TIME rejection for Hive ORC (SPARK-51590). ### Does this PR introduce any user-facing change? Yes. Using TIME with Hive UDFs or Hive SerDe writes now fails with a clear error message naming the unsupported TIME type rather than a MatchError/internal error. ### How was this patch tested? Added tests in `HiveInspectorSuite`, `HiveUDFSuite` and `InsertSuite`, and documented the limitation in `docs/sql-ref-datatypes.md`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Apache Hive has no TIME type, so
TimeTypehas no faithful representation in Hive SerDe interop. This PR (the Option B / "clear, documented error" path from SPARK-57556) makesTimeTypeproduce a clearAnalysisExceptioninstead of ascala.MatchError/internal error when it reaches theHiveInspectorsmapping functions, and rejects it in the Hive SerDe write path:HiveInspectors.toInspector(dataType),toInspector(expr)(TIME literal) andtoTypeInfonow throwUNSUPPORTED_DATATYPEvia a sharedunsupportedHiveTypehelper. PreviouslytoInspector(dataType)had noTimeTypecase and no default branch, so a TIME column hit a rawscala.MatchError.HiveFileFormat.supportDataTyperejectsTimeType(recursing into nested struct/array/map/UDT types, preserving the prior default for all other types) so Hive SerDe writes raiseUNSUPPORTED_DATA_TYPE_FOR_DATASOURCE(formatHive) viaFileFormatWriter.verifySchema.docs/sql-ref-datatypes.md.Why are the changes needed?
HiveInspectorshad noTimeTypecase, so object-inspector creation and TypeInfo mapping fell through to aMatchError/internal error when a TIME column or literal reached Hive SerDe paths (for example, a TIME argument to a Hive UDF/UDAF/UDTF). This makes the behavior explicit and documented, consistent with the existing TIME rejection for Hive ORC (SPARK-51590).Does this PR introduce any user-facing change?
Yes. Using TIME with Hive UDFs or in a Hive SerDe write now fails with a clear error that names the unsupported TIME type, instead of a
MatchError/internal error. For example,SELECT myHiveUDF(TIME'12:01:02')now reports[UNSUPPORTED_DATATYPE] Unsupported data type "TIME(6)"(wrapped by the Hive UDF resolver), and writing a TIME column through the Hive SerDe write path reports[UNSUPPORTED_DATA_TYPE_FOR_DATASOURCE] The Hive datasource doesn't support the column ... of the type "TIME(6)".How was this patch tested?
Added tests and ran them locally (
build/sbt 'hive/testOnly *HiveInspectorSuite *HiveUDFSuite *InsertSuite'):HiveInspectorSuite:toInspector(TimeType()), a TIME literal, andTimeType().toTypeInforaiseUNSUPPORTED_DATATYPE.HiveUDFSuite: passingTIME'12:01:02'to a HiveGenericUDFHashfails with a message naming the unsupported TIME type.InsertSuite:INSERT OVERWRITE LOCAL DIRECTORY ... STORED AS PARQUET SELECT TIME'...'(withspark.sql.hive.convertMetastoreInsertDir=false) raisesUNSUPPORTED_DATA_TYPE_FOR_DATASOURCE.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Cursor (Claude Opus 4.8)