-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-23715][SQL] the input of to/from_utc_timestamp can not have timezone #21169
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,10 +296,27 @@ object DateTimeUtils { | |
| * `T[h]h:[m]m:[s]s.[ms][ms][ms][us][us][us]+[h]h:[m]m` | ||
| */ | ||
| def stringToTimestamp(s: UTF8String): Option[SQLTimestamp] = { | ||
| stringToTimestamp(s, defaultTimeZone()) | ||
| stringToTimestamp(s, defaultTimeZone(), forceTimezone = false) | ||
| } | ||
|
|
||
| def stringToTimestamp(s: UTF8String, timeZone: TimeZone): Option[SQLTimestamp] = { | ||
| stringToTimestamp(s, timeZone, forceTimezone = false) | ||
| } | ||
|
|
||
| /** | ||
| * Converts a timestamp string to microseconds from the unix epoch, w.r.t. the given timezone. | ||
|
Member
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. BTW, I usually avoid abbreviation in doc tho (w.r.t.). |
||
| * Returns None if the input string is not a valid timestamp format. | ||
| * | ||
| * @param s the input timestamp string. | ||
| * @param timeZone the timezone of the timestamp string, will be ignored if the timestamp string | ||
| * already contains timezone information and `forceTimezone` is false. | ||
| * @param forceTimezone if true, force to apply the given timezone to the timestamp string. If the | ||
| * timestamp string already contains timezone, return None. | ||
| */ | ||
| def stringToTimestamp( | ||
| s: UTF8String, | ||
| timeZone: TimeZone, | ||
| forceTimezone: Boolean): Option[SQLTimestamp] = { | ||
|
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. It seems more like rejectTzInString or rejectStringTZ. |
||
| if (s == null) { | ||
| return None | ||
| } | ||
|
|
@@ -417,6 +434,8 @@ object DateTimeUtils { | |
| return None | ||
| } | ||
|
|
||
| if (tz.isDefined && forceTimezone) return None | ||
|
|
||
| val c = if (tz.isEmpty) { | ||
| Calendar.getInstance(timeZone) | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,3 +27,8 @@ select current_date = current_date(), current_timestamp = current_timestamp(), a | |
| select a, b from ttf2 order by a, current_date; | ||
|
|
||
| select weekday('2007-02-03'), weekday('2009-07-30'), weekday('2017-05-27'), weekday(null), weekday('1582-10-15 13:10:15'); | ||
|
|
||
|
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. Does it matter if there are no success cases for from_utc_timestamp and to_utc_timestamp in here (that is, cases that don't return null)? |
||
| -- SPARK-23715: the input of to/from_utc_timestamp can not have timezone | ||
| select from_utc_timestamp('2000-10-10 00:00:00+00:00', 'PST'); | ||
|
|
||
| select to_utc_timestamp('2000-10-10 00:00:00+00:00', 'PST'); | ||
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.
Should these checks go in their own rule that runs before ImplicitTypeCasts?
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.
Catalyst suggests rules in the same batch is order insensitive, since here this rule must be run before implicit type cast, we'd better put them in the same rule to guarantee the order.