cloud-fan commented on a change in pull request #26572:
[SPARK-29870][SQL][FOLLOW-UP] Keep CalendarInterval's toString
URL: https://github.com/apache/spark/pull/26572#discussion_r347352365
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -332,34 +332,7 @@ object IntervalUtils {
fromDoubles(interval.months / num, interval.days / num,
interval.microseconds / num)
}
- def toMultiUnitsString(interval: CalendarInterval): String = {
- if (interval.months == 0 && interval.days == 0 && interval.microseconds ==
0) {
- return "0 seconds"
- }
- val sb = new StringBuilder
- if (interval.months != 0) {
- appendUnit(sb, interval.months / 12, "years")
- appendUnit(sb, interval.months % 12, "months")
- }
- appendUnit(sb, interval.days, "days")
- if (interval.microseconds != 0) {
- var rest = interval.microseconds
- appendUnit(sb, rest / MICROS_PER_HOUR, "hours")
- rest %= MICROS_PER_HOUR
- appendUnit(sb, rest / MICROS_PER_MINUTE, "minutes")
- rest %= MICROS_PER_MINUTE
- if (rest != 0) {
- val s = BigDecimal.valueOf(rest, 6).stripTrailingZeros.toPlainString
- sb.append(s).append(" seconds ")
- }
- }
- sb.setLength(sb.length - 1)
- sb.toString
- }
-
- private def appendUnit(sb: StringBuilder, value: Long, unit: String): Unit =
{
- if (value != 0) sb.append(value).append(' ').append(unit).append(' ')
- }
+ def toMultiUnitsString(interval: CalendarInterval): String =
interval.toString
Review comment:
probably add a comment saying that the `toString` implementation is the
multi-units format.
----------------------------------------------------------------
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]