You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/06/18 11:20:29 UTC
[GitHub] [spark] cloud-fan commented on a change in pull request #27617: [SPARK-30865][SQL] Refactor DateTimeUtils
cloud-fan commented on a change in pull request #27617:
URL: https://github.com/apache/spark/pull/27617#discussion_r442153462
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -42,49 +42,42 @@ import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String}
*/
object DateTimeUtils {
- // we use Int and Long internally to represent [[DateType]] and [[TimestampType]]
- type SQLDate = Int
- type SQLTimestamp = Long
-
// see http://stackoverflow.com/questions/466321/convert-unix-timestamp-to-julian
// it's 2440587.5, rounding up to compatible with Hive
final val JULIAN_DAY_OF_EPOCH = 2440588
final val julianCommonEraStart = Timestamp.valueOf("0001-01-01 00:00:00")
- final val TimeZoneGMT = TimeZone.getTimeZone("GMT")
final val TimeZoneUTC = TimeZone.getTimeZone("UTC")
val TIMEZONE_OPTION = "timeZone"
- def defaultTimeZone(): TimeZone = TimeZone.getDefault()
-
def getZoneId(timeZoneId: String): ZoneId = ZoneId.of(timeZoneId, ZoneId.SHORT_IDS)
def getTimeZone(timeZoneId: String): TimeZone = {
TimeZone.getTimeZone(getZoneId(timeZoneId))
}
- def microsToDays(timestamp: SQLTimestamp): SQLDate = {
- microsToDays(timestamp, defaultTimeZone().toZoneId)
+ def microsToDays(micros: Long): Int = {
+ microsToDays(micros, ZoneId.systemDefault())
}
- def microsToDays(timestamp: SQLTimestamp, zoneId: ZoneId): SQLDate = {
- val instant = microsToInstant(timestamp)
+ def microsToDays(micros: Long, zoneId: ZoneId): Int = {
+ val instant = microsToInstant(micros)
localDateToDays(LocalDateTime.ofInstant(instant, zoneId).toLocalDate)
}
- def daysToMicros(days: SQLDate): SQLTimestamp = {
- daysToMicros(days, defaultTimeZone().toZoneId)
+ def daysToMicros(days: Int): Long = {
+ daysToMicros(days, ZoneId.systemDefault())
}
- def daysToMicros(days: SQLDate, zoneId: ZoneId): SQLTimestamp = {
+ def daysToMicros(days: Int, zoneId: ZoneId): Long = {
val instant = daysToLocalDate(days).atStartOfDay(zoneId).toInstant
instantToMicros(instant)
}
- // Converts Timestamp to string according to Hive TimestampWritable convention.
- def timestampToString(tf: TimestampFormatter, us: SQLTimestamp): String = {
- tf.format(us)
+ // Converts the `micros` timestamp to string according to Hive TimestampWritable convention.
+ def timestampToString(tf: TimestampFormatter, micros: Long): String = {
+ tf.format(micros)
Review comment:
`tf.format(micros)` is shorter than `timestampToString`, do we really need this method?
----------------------------------------------------------------
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org