-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-31939][SQL][test-java11] Fix Parsing day of year when year field pattern is missing #28766
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6afd5f7
[SPARK-31939][SQL] Fix Parsing day of year when year field pattern is…
yaooqinn 2d797e0
nit
yaooqinn a11a049
refine
yaooqinn f78db47
add tests
yaooqinn b7da48e
Merge branch 'master' into SPARK-31939
yaooqinn cd55187
add tests
yaooqinn 20b585d
for java 11
yaooqinn b3cdccf
address comments
yaooqinn 6b8dec4
nit
yaooqinn 52184fc
fix test
yaooqinn 04ce7ee
nit
yaooqinn 1899e81
more tests
yaooqinn 78c676e
adress cloudfan's comments
yaooqinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -258,19 +258,19 @@ class TimestampFormatterSuite extends DatetimeFormatterSuite { | |
| } | ||
| } | ||
|
|
||
| def assertParsingError(f: => Unit): Unit = { | ||
| intercept[Exception](f) match { | ||
| case e: SparkUpgradeException => | ||
| assert(e.getCause.isInstanceOf[DateTimeException]) | ||
| case e => | ||
| assert(e.isInstanceOf[DateTimeException]) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-30958: parse timestamp with negative year") { | ||
| val formatter1 = TimestampFormatter("yyyy-MM-dd HH:mm:ss", UTC, isParsing = true) | ||
| assert(formatter1.parse("-1234-02-22 02:22:22") === date(-1234, 2, 22, 2, 22, 22)) | ||
|
|
||
| def assertParsingError(f: => Unit): Unit = { | ||
| intercept[Exception](f) match { | ||
| case e: SparkUpgradeException => | ||
| assert(e.getCause.isInstanceOf[DateTimeException]) | ||
| case e => | ||
| assert(e.isInstanceOf[DateTimeException]) | ||
| } | ||
| } | ||
|
|
||
| // "yyyy" with "G" can't parse negative year or year 0000. | ||
| val formatter2 = TimestampFormatter("G yyyy-MM-dd HH:mm:ss", UTC, isParsing = true) | ||
| assertParsingError(formatter2.parse("BC -1234-02-22 02:22:22")) | ||
|
|
@@ -433,4 +433,35 @@ class TimestampFormatterSuite extends DatetimeFormatterSuite { | |
| assert(formatter.format(date(1970, 4, 10)) == "100") | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-31939: Fix Parsing day of year when year field pattern is missing") { | ||
| // resolved to queryable LocaleDate or fail directly | ||
| val f0 = TimestampFormatter("yyyy-dd-DD", UTC, isParsing = true) | ||
|
yaooqinn marked this conversation as resolved.
Outdated
|
||
| assert(f0.parse("2020-29-60") === date(2020, 2, 29)) | ||
| assertParsingError(f0.parse("2020-02-60")) | ||
| val f1 = TimestampFormatter("yyyy-MM-DD", UTC, isParsing = true) | ||
| assert(f1.parse("2020-02-60") === date(2020, 2, 29)) | ||
| assertParsingError(f1.parse("2020-03-60")) | ||
| val f2 = TimestampFormatter("yyyy-MM-dd-DD", UTC, isParsing = true) | ||
| assert(f2.parse("2020-02-29-60") === date(2020, 2, 29)) | ||
| assertParsingError(f2.parse("2020-03-01-60")) | ||
| val f3 = TimestampFormatter("yyyy-DDD", UTC, isParsing = true) | ||
| assert(f3.parse("2020-366") === date(2020, 12, 31)) | ||
| assertParsingError(f3.parse("2019-366")) | ||
|
|
||
| // unresolved and need to check manually(SPARK-31939 fixed) | ||
| val f4 = TimestampFormatter("DDD", UTC, isParsing = true) | ||
| assert(f4.parse("365") === date(1970, 12, 31)) | ||
| assertParsingError(f4.parse("366")) // 1970 is not a leap year | ||
| val f5 = TimestampFormatter("MM-DD", UTC, isParsing = true) | ||
| assert(f5.parse("03-60") === date(1970, 3, 1)) | ||
| assertParsingError(f5.parse("02-60")) | ||
| val f6 = TimestampFormatter("MM-dd-DD", UTC, isParsing = true) | ||
| assert(f6.parse("02-28-59") === date(1970, 2, 28)) | ||
| assertParsingError(f6.parse("02-28-60")) | ||
| assertParsingError(f6.parse("02-28-58")) | ||
| val f7 = TimestampFormatter("dd-DD", UTC, isParsing = true) | ||
| assert(f7.parse("28-59") === date(1970, 2, 28)) | ||
| assertParsingError(f7.parse("27-59")) | ||
| } | ||
|
Contributor
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. can we also add tests in the .sql file? |
||
| } | ||
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.
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.
candidate.isSupported(field)this is always true?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.
For the time being, yes. I can remove this condition