MaxGekk commented on a change in pull request #28119: [WIP][SPARK-31359][SQL] 
Speed up timestamps rebasing
URL: https://github.com/apache/spark/pull/28119#discussion_r405702588
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/RebaseDateTime.scala
 ##########
 @@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.util
+
+import java.time.{LocalDateTime, ZoneId}
+import java.time.temporal.ChronoField
+import java.util.{Calendar, TimeZone}
+
+import scala.collection.mutable.AnyRefMap
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.scala.{DefaultScalaModule, 
ScalaObjectMapper}
+
+import org.apache.spark.sql.catalyst.util.DateTimeConstants._
+import org.apache.spark.sql.catalyst.util.DateTimeUtils._
+
+/**
+ * The collection of functions for rebasing days and microseconds from/to 
Proleptic Gregorian
+ * calendar used by default in Spark SQL since version 3.0, see SPARK-26651 
to/from
+ * the hybrid calendar (Julian + Gregorian since 1582-10-15) which is used by 
Spark 2.4
+ * and earlier versions.
+ */
+object RebaseDateTime {
+  /**
+   * Rebases days since the epoch from an original to an target calendar, for 
instance,
+   * from a hybrid (Julian + Gregorian) to Proleptic Gregorian calendar.
+   *
+   * It finds the latest switch day which is less than `value`, and adds the 
difference
+   * in days associated with the switch days to the given `value`.
+   * The function is based on linear search which starts from the most recent 
switch days.
+   * This allows to perform less comparisons for modern dates.
+   *
+   * @param switches The days when difference in days between original and 
target
+   *                   calendar was changed.
 
 Review comment:
   fixed

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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