cloud-fan commented on a change in pull request #23462: [SPARK-26546][SQL] 
Caching of java.time.format.DateTimeFormatter
URL: https://github.com/apache/spark/pull/23462#discussion_r246073272
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeFormatterHelper.scala
 ##########
 @@ -39,15 +63,17 @@ trait DateTimeFormatterHelper {
       .withResolverStyle(ResolverStyle.STRICT)
   }
 
-  protected def toInstantWithZoneId(temporalAccessor: TemporalAccessor, 
zoneId: ZoneId): Instant = {
-    val localTime = if (temporalAccessor.query(TemporalQueries.localTime) == 
null) {
-      LocalTime.ofNanoOfDay(0)
-    } else {
-      LocalTime.from(temporalAccessor)
+  def getFormatter(pattern: String, locale: Locale): DateTimeFormatter = {
+    try {
+      cache.get(
+        (pattern, locale),
+        new Callable[DateTimeFormatter]() {
 
 Review comment:
   I'm not sure if there is a better way. To save the computation we must pass 
a "function" to `getOrElse`, and "function" in Java/Scala is an object. Another 
way is to sacrifice multi-thread contention a little bit:
   ```
   synchronized {
     val formatter = cache.get...
     if (formatter == null) {
       val f = create formatter
       cache.put(key, f)
       f
     } else {
       formatter
     }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to