Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6980#discussion_r33128360
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
 ---
    @@ -41,35 +39,53 @@ object DateTimeUtils {
     
     
       // Java TimeZone has no mention of thread safety. Use thread local 
instance to be safe.
    -  private val LOCAL_TIMEZONE = new ThreadLocal[TimeZone] {
    +  private val threadLocalLocalTimeZone = new ThreadLocal[TimeZone] {
         override protected def initialValue: TimeZone = {
           Calendar.getInstance.getTimeZone
         }
       }
     
    -  private def javaDateToDays(d: Date): Int = {
    -    millisToDays(d.getTime)
    +  // `SimpleDateFormat` is not thread-safe.
    +  private val threadLocalTimestampFormat = new ThreadLocal[DateFormat] {
    +    override def initialValue(): SimpleDateFormat = {
    +      new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    +    }
    +  }
    +
    +  // `SimpleDateFormat` is not thread-safe.
    +  private val threadLocalDateFormat = new ThreadLocal[DateFormat] {
    +    override def initialValue(): SimpleDateFormat = {
    +      new SimpleDateFormat("yyyy-MM-dd")
    +    }
       }
     
    +
       // we should use the exact day as Int, for example, (year, month, day) 
-> day
    -  def millisToDays(millisLocal: Long): Int = {
    -    ((millisLocal + LOCAL_TIMEZONE.get().getOffset(millisLocal)) / 
MILLIS_PER_DAY).toInt
    +  private[sql] def millisToDays(millisLocal: Long): Int = {
    +    ((millisLocal + threadLocalLocalTimeZone.get().getOffset(millisLocal)) 
/ MILLIS_PER_DAY).toInt
       }
     
    -  def toMillisSinceEpoch(days: Int): Long = {
    +  // reverse of millisToDays
    +  private[sql] def daysToMillis(days: Int): Long = {
    --- End diff --
    
    add `private[sql]` to those methods that will only be used inside catalyst.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to