-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46611][CORE] Remove ThreadLocal by replace SimpleDateFormat with DateTimeFormatter #44613
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
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
private val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss", Locale.US)
.withZone(java.time.ZoneId.systemDefault())
def formatDate(date: Date): String = dateTimeFormatter.format(date.toInstant)
def formatDate(timestamp: Long): String = dateTimeFormatter.format(Instant.ofEpochMilli(timestamp))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.
This is even better than my suggestion, thanks @LuciferYang !
mridulm
left a comment
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.
This is a nice change.
There are other usages of SimpleDateFormat which are candidates for this pattern.
I will check. |
|
ping @dongjoon-hyun @srowen cc @yaooqinn |
|
I sent info about the spam from @llkj1 to GitHub support. |
|
I tried to block the user and have been deleting the spam |
|
is this one ready to go? |
LuciferYang
left a comment
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.
+1, LGTM
| batchTimeFormat.get.setTimeZone(timezone) | ||
| batchTimeFormatWithMilliseconds.get.setTimeZone(timezone) | ||
| val zoneId = timezone.toZoneId | ||
| batchTimeFormat.withZone(zoneId) |
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.
This looks like a regression - see #44619
|
@LuciferYang @srowen @mridulm Thank you! |
…one in UIUtils ### What changes were proposed in this pull request? Simplify code and fix new use of DateTimeFormat.withZone introduced in #44613 ; need to use the new object copy this creates. ### Why are the changes needed? Describing on mailing list from Janda Martin: ``` DateTimeFormatter is thread-safe and immutable according to JavaDoc so method DateTimeFormatter::withZone returns new instance when zone is changed. Following code has no effect: val oldTimezones = (batchTimeFormat.getZone, batchTimeFormatWithMilliseconds.getZone) if (timezone != null) { val zoneId = timezone.toZoneId batchTimeFormat.withZone(zoneId) batchTimeFormatWithMilliseconds.withZone(zoneId) } Suggested fix: introduce local variables for "batchTimeFormat" and "batchTimeFormatWithMilliseconds" and remove "oldTimezones" and "finally" block. ``` ### Does this PR introduce _any_ user-facing change? Unlikely, the path in question is apparently test-only ### How was this patch tested? Existing tests ### Was this patch authored or co-authored using generative AI tooling? No Closes #44619 from srowen/SPARK-46611.2. Authored-by: Sean Owen <srowen@gmail.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
What changes were proposed in this pull request?
This PR propose to remove
ThreadLocalby replaceSimpleDateFormatwithDateTimeFormatter.Why are the changes needed?
SimpleDateFormatis not thread safe, so we wrap it withThreadLocal.DateTimeFormatteris thread safe, we can use it instead.According to the javadoc of
SimpleDateFormat, it recommended to useDateTimeFormattertoo.In addition,
DateTimeFormatterhave better performance thanSimpleDateFormattoo.Does this PR introduce any user-facing change?
'No'.
How was this patch tested?
GA tests.
Was this patch authored or co-authored using generative AI tooling?
'No'.