HyukjinKwon commented on a change in pull request #26418: [SPARK-29783][SQL]
Support SQL Standard/ISO_8601 output style for interval type
URL: https://github.com/apache/spark/pull/26418#discussion_r347262166
##########
File path:
common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java
##########
@@ -80,39 +79,8 @@ public int compareTo(CalendarInterval that) {
@Override
public String toString() {
- if (months == 0 && days == 0 && microseconds == 0) {
- return "0 seconds";
- }
-
- StringBuilder sb = new StringBuilder();
-
- if (months != 0) {
- appendUnit(sb, months / 12, "years");
- appendUnit(sb, months % 12, "months");
- }
-
- appendUnit(sb, days, "days");
-
- if (microseconds != 0) {
- long rest = 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) {
- String s = BigDecimal.valueOf(rest,
6).stripTrailingZeros().toPlainString();
- sb.append(s).append(" seconds ");
- }
- }
-
- sb.setLength(sb.length() - 1);
- return sb.toString();
- }
-
- private void appendUnit(StringBuilder sb, long value, String unit) {
- if (value != 0) {
- sb.append(value).append(' ').append(unit).append(' ');
- }
+ return "CalendarInterval(months= " + months + ", days = " + days + ",
microsecond = " +
+ microseconds + ")";
Review comment:
Why did we use such string representation now? Was it in order to put the
same logics into `IntervalUtils`? If that's the case, we didn't have to move
but use `toString` of this class until this case becomes completely exposed.
----------------------------------------------------------------
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]