yaooqinn commented on a change in pull request #26347: [SPARK-29688][SQL]
Support average for interval type values
URL: https://github.com/apache/spark/pull/26347#discussion_r342422996
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -97,6 +97,16 @@ object IntervalUtils {
Decimal(result, 18, 6)
}
+ def divide(interval: CalendarInterval, divisor: Decimal): CalendarInterval =
{
+ if (divisor == Decimal.ZERO || divisor == null) return null
+ val months = Decimal(interval.months) / divisor
+ val days = months.remainder(Decimal.ONE) * Decimal(DAYS_PER_MONTH) +
+ Decimal(interval.days) / divisor
+ val milliseconds = days.remainder(Decimal.ONE) *
Decimal(DateTimeUtils.MICROS_PER_DAY) +
+ Decimal(interval.microseconds) / divisor
+ new CalendarInterval(months.toInt, days.toInt, milliseconds.toLong)
Review comment:
microseconds. thanks.
----------------------------------------------------------------
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]