-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-30865][SQL][SS] Refactor DateTimeUtils #27617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Test build #118615 has finished for PR 27617 at commit
|
|
jenkins, retest this, please |
|
Test build #118623 has finished for PR 27617 at commit
|
|
@cloud-fan @HyukjinKwon Please, take a look at this PR. |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TimestampFormatter.scala
Outdated
Show resolved
Hide resolved
|
Test build #118757 has finished for PR 27617 at commit
|
|
Test build #118759 has finished for PR 27617 at commit
|
|
jenkins, retest this, please |
|
Test build #118768 has finished for PR 27617 at commit
|
|
Test build #118804 has finished for PR 27617 at commit
|
|
cc: @viirya @cloud-fan |
A bit confused. |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
Outdated
Show resolved
Hide resolved
viirya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good except few minor comments.
|
Test build #124138 has finished for PR 27617 at commit
|
|
@cloud-fan @HyukjinKwon It is ready already. Can we continue with this PR? |
| tf.format(us) | ||
| // Converts the `micros` timestamp to string according to Hive TimestampWritable convention. | ||
| def timestampToString(tf: TimestampFormatter, micros: Long): String = { | ||
| tf.format(micros) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tf.format(micros) is shorter than timestampToString, do we really need this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it
|
|
||
| def microsToEpochDays(epochMicros: SQLTimestamp, zoneId: ZoneId): SQLDate = { | ||
| localDateToDays(microsToInstant(epochMicros).atZone(zoneId).toLocalDate) | ||
| def microsToEpochDays(micros: Long, zoneId: ZoneId): Int = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it the same with microsToDays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like, yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we unify them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the duplicates
|
|
||
| def epochDaysToMicros(epochDays: SQLDate, zoneId: ZoneId): SQLTimestamp = { | ||
| val localDate = LocalDate.ofEpochDay(epochDays) | ||
| def epochDaysToMicros(days: Int, zoneId: ZoneId): Long = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
| def microsToEpochDays(epochMicros: SQLTimestamp, zoneId: ZoneId): SQLDate = { | ||
| localDateToDays(microsToInstant(epochMicros).atZone(zoneId).toLocalDate) | ||
| def microsToEpochDays(micros: Long, zoneId: ZoneId): Int = { | ||
| localDateToDays(microsToInstant(micros).atZone(zoneId).toLocalDate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: localDateToDays(getLocalDateTime(micros, zoneId))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the function
| def convertTz(ts: SQLTimestamp, fromZone: ZoneId, toZone: ZoneId): SQLTimestamp = { | ||
| val rebasedDateTime = microsToInstant(ts).atZone(toZone).toLocalDateTime.atZone(fromZone) | ||
| def convertTz(micros: Long, fromZone: ZoneId, toZone: ZoneId): Long = { | ||
| val rebasedDateTime = microsToInstant(micros).atZone(toZone).toLocalDateTime.atZone(fromZone) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can reuse getLocalDateTime here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
Test build #124234 has finished for PR 27617 at commit
|
|
Test build #124235 has finished for PR 27617 at commit
|
|
thanks, merging to master! |
What changes were proposed in this pull request?
*DateTimeUtils.in fromJulianDay()DateTimeUtils.subtractDates()julianCommonEraStart,timestampToString(),microsToEpochDays(),epochDaysToMicros(),instantToDays()fromDateTimeUtils.def daysToMicros(days: Int): Longanddef microsToDays(micros: Long): Int.Why are the changes needed?
This simplifies the common code related to date-time operations, and should improve maintainability. In particular:
millisToDaysanddaysToMillison Java 8 time API #27494, Spark expressions and DateTimeUtils functions switched to ZoneId instead of TimeZone completely.defaultTimeZone()withTimeZoneas return type is not needed anymore.*DateTimeUtils.in fromJulianDay().DateTimeUtils.subtractDates().Does this PR introduce any user-facing change?
No
How was this patch tested?
By existing test suites