Skip to content

Commit d1ef6be

Browse files
MaxGekkhvanhovell
authored andcommitted
[SPARK-26978][SQL][FOLLOWUP] Initialize date-time constants by foldable expressions
## What changes were proposed in this pull request? Reverted initialization of date-time constants in `DateTimeUtils` introduced by apache#23878. As a comment in [Delta repo](https://github.com/delta-io/delta) states, the compiler can do additional optimizations if values can be calculated at compile time: https://github.com/delta-io/delta/blob/master/src/main/scala/org/apache/spark/sql/delta/util/DateTimeUtils.scala#L63-L75 ## How was this patch tested? This was tested by existing test suites. Closes apache#25116 from MaxGekk/datetime-consts-init. Authored-by: Maxim Gekk <[email protected]> Signed-off-by: herman <[email protected]>
1 parent e83583e commit d1ef6be

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,19 @@ object DateTimeUtils {
4545
// it's 2440587.5, rounding up to compatible with Hive
4646
final val JULIAN_DAY_OF_EPOCH = 2440588
4747

48-
final val NANOS_PER_MICROS = MICROSECONDS.toNanos(1)
49-
final val NANOS_PER_MILLIS = MILLISECONDS.toNanos(1)
50-
final val NANOS_PER_SECOND = SECONDS.toNanos(1)
51-
final val MICROS_PER_MILLIS = MILLISECONDS.toMicros(1)
52-
final val MICROS_PER_SECOND = SECONDS.toMicros(1)
53-
final val MICROS_PER_DAY = DAYS.toMicros(1)
54-
final val MILLIS_PER_SECOND = SECONDS.toMillis(1)
55-
final val MILLIS_PER_MINUTE = MINUTES.toMillis(1)
56-
final val MILLIS_PER_HOUR = HOURS.toMillis(1)
57-
final val MILLIS_PER_DAY = DAYS.toMillis(1)
58-
final val SECONDS_PER_DAY = DAYS.toSeconds(1)
48+
// Pre-calculated values can provide an opportunity of additional optimizations
49+
// to the compiler like constants propagation and folding.
50+
final val NANOS_PER_MICROS: Long = 1000
51+
final val MICROS_PER_MILLIS: Long = 1000
52+
final val MILLIS_PER_SECOND: Long = 1000
53+
final val SECONDS_PER_DAY: Long = 24 * 60 * 60
54+
final val MICROS_PER_SECOND: Long = MILLIS_PER_SECOND * MICROS_PER_MILLIS
55+
final val NANOS_PER_MILLIS: Long = NANOS_PER_MICROS * MICROS_PER_MILLIS
56+
final val NANOS_PER_SECOND: Long = NANOS_PER_MICROS * MICROS_PER_SECOND
57+
final val MICROS_PER_DAY: Long = SECONDS_PER_DAY * MICROS_PER_SECOND
58+
final val MILLIS_PER_MINUTE: Long = 60 * MILLIS_PER_SECOND
59+
final val MILLIS_PER_HOUR: Long = 60 * MILLIS_PER_MINUTE
60+
final val MILLIS_PER_DAY: Long = SECONDS_PER_DAY * MILLIS_PER_SECOND
5961

6062
// number of days between 1.1.1970 and 1.1.2001
6163
final val to2001 = -11323

0 commit comments

Comments
 (0)