-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-31879][SQL][test-java11] Make week-based pattern invalid for formatting too #28728
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
Conversation
| formatter.format(LocalDate.of(2000, 1, 1)) == "1 1" | ||
| } | ||
| final val unsupportedLetters = Set('A', 'c', 'e', 'n', 'N', 'p') | ||
| final val unsupportedLetters = Set('A', 'c', 'n', 'N', 'p', 'Y', 'W', 'w', 'u') |
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.
how about we add a new list weekBasedLetters? They deserve a dedicated error message, to suggest users using the SQL function EXTRACT.
| intercept[SparkUpgradeException](formatter.parse("02-29")) | ||
| } | ||
|
|
||
| override def checkFormatterCreation(pattern: String, isParsing: Boolean): Unit = { |
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.
can we move it to the beginning of this class? to avoid code conflict when we add new tests
| .foreach { pattern => | ||
| intercept[SparkUpgradeException](TimestampFormatter(pattern, UTC).format(0)) | ||
| } | ||
| override def checkFormatterCreation(pattern: String, isParsing: Boolean): Unit = { |
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.
ditto
|
Test build #123534 has finished for PR 28728 at commit
|
|
retest this please |
docs/sql-ref-datetime-pattern.md
Outdated
| |**W**|week-of-month|number(1)|4| | ||
| |**E**|day-of-week|text|Tue; Tuesday| | ||
| |**u**|localized day-of-week|number/text|2; 02; Tue; Tuesday| | ||
| |**e**|localized day-of-week|number/text|2; 02; Tue; Tuesday| |
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.
shall we forbid e as well? It's not supported in 2.4 either.
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.
Forgot to update the doc, thanks for reminding
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateFormatter.scala
Show resolved
Hide resolved
|
I'm fine with it, what do you think? @bart-samwel @maropu @MaxGekk @HyukjinKwon @dongjoon-hyun |
|
Test build #123536 has finished for PR 28728 at commit
|
|
Test build #123535 has finished for PR 28728 at commit
|
|
Test build #123537 has finished for PR 28728 at commit
|
|
Test build #123538 has finished for PR 28728 at commit
|
|
@cloud-fan Yes, let's forbid the legacy week-based letters that were non-localized. We can keep the new format letters, those are new features then. |
|
thanks, merging to master/3.0! |
…ormatting too After all these attempts apache#28692 and apache#28719 an apache#28727. they all have limitations as mentioned in their discussions. Maybe the only way is to forbid them all These week-based fields need Locale to express their semantics, the first day of the week varies from country to country. From the Java doc of WeekFields ```java /** * Gets the first day-of-week. * <p> * The first day-of-week varies by culture. * For example, the US uses Sunday, while France and the ISO-8601 standard use Monday. * This method returns the first day using the standard {code DayOfWeek} enum. * * return the first day-of-week, not null */ public DayOfWeek getFirstDayOfWeek() { return firstDayOfWeek; } ``` But for the SimpleDateFormat, the day-of-week is not localized ``` u Day number of week (1 = Monday, ..., 7 = Sunday) Number 1 ``` Currently, the default locale we use is the US, so the result moved a day or a year or a week backward. e.g. For the date `2019-12-29(Sunday)`, in the Sunday Start system(e.g. en-US), it belongs to 2020 of week-based-year, in the Monday Start system(en-GB), it goes to 2019. the week-of-week-based-year(w) will be affected too ```sql spark-sql> SELECT to_csv(named_struct('time', to_timestamp('2019-12-29', 'yyyy-MM-dd')), map('timestampFormat', 'YYYY', 'locale', 'en-US')); 2020 spark-sql> SELECT to_csv(named_struct('time', to_timestamp('2019-12-29', 'yyyy-MM-dd')), map('timestampFormat', 'YYYY', 'locale', 'en-GB')); 2019 spark-sql> SELECT to_csv(named_struct('time', to_timestamp('2019-12-29', 'yyyy-MM-dd')), map('timestampFormat', 'YYYY-ww-uu', 'locale', 'en-US')); 2020-01-01 spark-sql> SELECT to_csv(named_struct('time', to_timestamp('2019-12-29', 'yyyy-MM-dd')), map('timestampFormat', 'YYYY-ww-uu', 'locale', 'en-GB')); 2019-52-07 spark-sql> SELECT to_csv(named_struct('time', to_timestamp('2020-01-05', 'yyyy-MM-dd')), map('timestampFormat', 'YYYY-ww-uu', 'locale', 'en-US')); 2020-02-01 spark-sql> SELECT to_csv(named_struct('time', to_timestamp('2020-01-05', 'yyyy-MM-dd')), map('timestampFormat', 'YYYY-ww-uu', 'locale', 'en-GB')); 2020-01-07 ``` For other countries, please refer to [First Day of the Week in Different Countries](http://chartsbin.com/view/41671) With this change, user can not use 'YwuW', but 'e' for 'u' instead. This can at least turn this not to be a silent data change. add unit tests Closes apache#28728 from yaooqinn/SPARK-31879-NEW2. Authored-by: Kent Yao <[email protected]> Signed-off-by: Wenchen Fan <[email protected]> (cherry picked from commit 9d5b5d0) Signed-off-by: Wenchen Fan <[email protected]>
What changes were proposed in this pull request?
After all these attempts #28692 and #28719 an #28727.
they all have limitations as mentioned in their discussions.
Maybe the only way is to forbid them all
Why are the changes needed?
These week-based fields need Locale to express their semantics, the first day of the week varies from country to country.
From the Java doc of WeekFields
But for the SimpleDateFormat, the day-of-week is not localized
Currently, the default locale we use is the US, so the result moved a day or a year or a week backward.
e.g.
For the date
2019-12-29(Sunday), in the Sunday Start system(e.g. en-US), it belongs to 2020 of week-based-year, in the Monday Start system(en-GB), it goes to 2019. the week-of-week-based-year(w) will be affected tooFor other countries, please refer to First Day of the Week in Different Countries
Does this PR introduce any user-facing change?
With this change, user can not use 'YwuW', but 'e' for 'u' instead. This can at least turn this not to be a silent data change.
How was this patch tested?
add unit tests