Skip to content

Commit 533dd8d

Browse files
committed
Remove the timezone conversions
1 parent 020e701 commit 533dd8d

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
471471
case StringType =>
472472
buildCast[UTF8String](_, s => DateTimeUtils.stringToDate(s, zoneId).orNull)
473473
case DoubleType =>
474-
buildCast[Double](_, daysSinceEpoch => convertTz(daysSinceEpoch.toInt))
474+
buildCast[Double](_, daysSinceEpoch => daysSinceEpoch.toInt)
475475
case TimestampType =>
476476
// throw valid precision more than seconds, according to Hive.
477477
// Timestamp.nanos is in 0 to 999,999,999, no more than a second.
@@ -1110,8 +1110,7 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit
11101110
$evNull = true;
11111111
}
11121112
"""
1113-
case DoubleType => (c, evPrim, evNull) =>
1114-
code"$evPrim = org.apache.spark.sql.catalyst.util.DateTimeUtils.convertTz((int)$c);"
1113+
case DoubleType => (c, evPrim, evNull) => code"$evPrim = (int) $c;"
11151114
case TimestampType =>
11161115
val zid = getZoneId()
11171116
(c, evPrim, evNull) =>

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,6 @@ object DateTimeUtils {
422422
Instant.ofEpochSecond(secs, mos * NANOS_PER_MICROS)
423423
}
424424

425-
def daysToInstant(daysSinceEpoch: SQLDate): Instant = {
426-
Instant.ofEpochSecond(daysSinceEpoch * SECONDS_PER_DAY)
427-
}
428-
429425
def instantToDays(instant: Instant): Int = {
430426
val seconds = instant.getEpochSecond
431427
val days = Math.floorDiv(seconds, SECONDS_PER_DAY)
@@ -825,21 +821,6 @@ object DateTimeUtils {
825821
instantToMicros(rebasedDateTime.toInstant)
826822
}
827823

828-
/**
829-
* Convert the date `ts` from one date to another.
830-
*
831-
* TODO: Because of DST, the conversion between UTC and human time is not exactly one-to-one
832-
* mapping, the conversion here may return wrong result, we should make the timestamp
833-
* timezone-aware.
834-
*/
835-
def convertTz(ts: SQLDate, fromZone: ZoneId, toZone: ZoneId): SQLDate = {
836-
val rebasedDateTime = daysToInstant(ts).atZone(toZone).toLocalDateTime.atZone(fromZone)
837-
instantToDays(rebasedDateTime.toInstant)
838-
}
839-
840-
// Convenience method for making it easier to only pass the first argument in Java codegen
841-
def convertTz(ts: SQLDate): SQLDate = convertTz(ts, ZoneOffset.UTC, defaultTimeZone().toZoneId)
842-
843824
/**
844825
* Returns a timestamp of given timezone from utc timestamp, with the same string
845826
* representation in their timezone.

0 commit comments

Comments
 (0)