[SPARK-50840][SQL] Fixing the timestamp parsing failure for Hive table metadata reload, when timestamp alias points to NTZ #49521
+102
−7
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?
The conversion of Hive's timestamp to Catalyst TimestampType needs handling, as during hive table metadata reload, the Hive's timestamp gets incorrectly mapped to spark's TimestampNTZType, if the timestamp alias is set to TimestampNTZType via the conf property spark.sql.timestampType.
The fix is written keeping in mind, that in future when spark's timestamp are mapped correctly with Hive's timestamp, then table reload should not result in incorrect TimestampType in spark.
The changes are that while mapping hive timestamp field to spark's StructField, the actual hive's datatype is stored in the metadata of the struct field.
This allows to rectify the table schema by changing the Spark's TimestampNTZType back to TimestampType if the original hive datatype is "timestamp".
Why are the changes needed?
Any table operation which requires reload of table metadata would fail, as Hive does not understand spark's TimeStampNTZType.
Does this PR introduce any user-facing change?
No
How was this patch tested?
Added bug test.
Was this patch authored or co-authored using generative AI tooling?
No