[SPARK-23436][SQL][BACKPORT-2.3] Infer partition as Date only if it can be casted to Date #20764
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.
This PR is to backport #20621 to branch 2.3�
What changes were proposed in this pull request?
Before the patch, Spark could infer as Date a partition value which cannot be casted to Date (this can happen when there are extra characters after a valid date, like
2018-02-15AAA).When this happens and the input format has metadata which define the schema of the table, then
nullis returned as a value for the partition column, because thecastoperator used in (PartitioningAwareFileIndex.inferPartitioning) is unable to convert the value.The PR checks in the partition inference that values can be casted to Date and Timestamp, in order to infer that datatype to them.
How was this patch tested?
added UT