-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31879][SQL][test-java11] Preset monday start(iso) for the first day of week by reflection #28727
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
[SPARK-31879][SQL][test-java11] Preset monday start(iso) for the first day of week by reflection #28727
Changes from all commits
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 |
|---|---|---|
|
|
@@ -17,11 +17,13 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.util | ||
|
|
||
| import java.lang.reflect.{Field, Modifier} | ||
| import java.time._ | ||
| import java.time.chrono.IsoChronology | ||
| import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder, ResolverStyle} | ||
| import java.time.temporal.{ChronoField, TemporalAccessor, TemporalQueries} | ||
| import java.time.temporal.{ChronoField, TemporalAccessor, TemporalQueries, WeekFields} | ||
| import java.util.Locale | ||
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| import com.google.common.cache.CacheBuilder | ||
|
|
||
|
|
@@ -155,7 +157,22 @@ trait DateTimeFormatterHelper { | |
| } | ||
| } | ||
|
|
||
| private object DateTimeFormatterHelper { | ||
| private[spark] object DateTimeFormatterHelper { | ||
| val defaultLocale = Locale.US | ||
|
|
||
| def presetSundayStartToMondayStart(): Unit = { | ||
| val CACHE: Field = classOf[WeekFields].getDeclaredField("CACHE") | ||
|
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. Yikes, isn't this going to change the Locale's settings for the whole JVM?
Member
Author
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. Only for those trying to use the original value of
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. yea, we shouldn't change a global cache, which is shared in the entire JVM, including user code. |
||
| CACHE.setAccessible(true) | ||
| val modifiers: Field = CACHE.getClass.getDeclaredField("modifiers") | ||
| modifiers.setAccessible(true) | ||
| modifiers.setInt(CACHE, CACHE.getModifiers & ~Modifier.FINAL) | ||
| val newCache = new ConcurrentHashMap[String, WeekFields]() | ||
| // Preset the Sunday start entry to ISO-based Monday start instance for retrieving first day | ||
| // of week | ||
| newCache.put(DayOfWeek.SUNDAY.toString + 1, WeekFields.ISO) | ||
| CACHE.set(null, newCache) | ||
| } | ||
|
|
||
| val cache = CacheBuilder.newBuilder() | ||
| .maximumSize(128) | ||
| .build[(String, Locale, Boolean), DateTimeFormatter]() | ||
|
|
@@ -222,7 +239,7 @@ private object DateTimeFormatterHelper { | |
| .appendValue(ChronoField.MINUTE_OF_HOUR, 2).appendLiteral(':') | ||
| .appendValue(ChronoField.SECOND_OF_MINUTE, 2) | ||
| .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true) | ||
| toFormatter(builder, TimestampFormatter.defaultLocale) | ||
| toFormatter(builder, defaultLocale) | ||
| } | ||
|
|
||
| private final val bugInStandAloneForm = { | ||
|
|
||
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
BTW we should remove
Exactly 5 pattern letters will use the narrow form