MaxGekk commented on a change in pull request #27491: [SPARK-30754][SQL] Reuse
results of floorDiv in calculations of floorMod in DateTimeUtils
URL: https://github.com/apache/spark/pull/27491#discussion_r376890351
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala
##########
@@ -691,11 +691,11 @@ object DateTimeUtils {
def truncDate(d: SQLDate, level: Int): SQLDate = {
def truncToYearLevel(divider: Int, adjust: Int): SQLDate = {
val oldYear = getYear(d)
- var newYear = Math.floorDiv(oldYear, divider)
- if (adjust > 0 && Math.floorMod(oldYear, divider) == 0) {
- newYear -= 1
+ var newYear = Math.floorDiv(oldYear, divider) * divider
Review comment:
`oldYear` can be negative, have a look at tests in
https://github.com/apache/spark/pull/25230, for instance.
----------------------------------------------------------------
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]