Skip to content

Commit d68d974

Browse files
committed
address comment
1 parent dc094a7 commit d68d974

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,29 @@ public int hashCode() {
8484

8585
@Override
8686
public String toString() {
87+
if (months == 0 && days == 0 && microseconds == 0) {
88+
return "0 seconds";
89+
}
90+
8791
StringBuilder sb = new StringBuilder();
8892

8993
if (months != 0) {
90-
appendUnit(sb, months / 12, "year");
91-
appendUnit(sb, months % 12, "month");
94+
appendUnit(sb, months / 12, "years");
95+
appendUnit(sb, months % 12, "months");
9296
}
9397

94-
appendUnit(sb, days, "day");
98+
appendUnit(sb, days, "days");
9599

96100
if (microseconds != 0) {
97101
long rest = microseconds;
98-
appendUnit(sb, rest / MICROS_PER_HOUR, "hour");
102+
appendUnit(sb, rest / MICROS_PER_HOUR, "hours");
99103
rest %= MICROS_PER_HOUR;
100-
appendUnit(sb, rest / MICROS_PER_MINUTE, "minute");
104+
appendUnit(sb, rest / MICROS_PER_MINUTE, "minutes");
101105
rest %= MICROS_PER_MINUTE;
102106
if (rest != 0) {
103107
String s = BigDecimal.valueOf(rest, 6).stripTrailingZeros().toPlainString();
104108
sb.append(s).append(" seconds ");
105109
}
106-
} else if (months == 0 && days == 0) {
107-
sb.append("0 microseconds ");
108110
}
109111

110112
sb.setLength(sb.length() - 1);
@@ -113,7 +115,7 @@ public String toString() {
113115

114116
private void appendUnit(StringBuilder sb, long value, String unit) {
115117
if (value != 0) {
116-
sb.append(value).append(' ').append(unit).append('s').append(' ');
118+
sb.append(value).append(' ').append(unit).append(' ');
117119
}
118120
}
119121

common/unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void toStringTest() {
5151
CalendarInterval i;
5252

5353
i = new CalendarInterval(0, 0, 0);
54-
assertEquals("0 microseconds", i.toString());
54+
assertEquals("0 seconds", i.toString());
5555

5656
i = new CalendarInterval(34, 0, 0);
5757
assertEquals("2 years 10 months", i.toString());

docs/sql-migration-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ license: |
220220

221221
- Since Spark 3.0, the interval literal syntax does not allow multiple from-to units anymore. For example, `SELECT INTERVAL '1-1' YEAR TO MONTH '2-2' YEAR TO MONTH'` throws parser exception.
222222

223+
- Since Spark 3.0, when casting interval values to string type, there is no "interval" prefix, e.g. `1 days 2 hours`. In Spark version 2.4 and earlier, the string contains the "interval" prefix like `interval 1 days 2 hours`.
224+
223225
## Upgrading from Spark SQL 2.4 to 2.4.1
224226

225227
- The value of `spark.executor.heartbeatInterval`, when specified without units like "30" rather than "30s", was

0 commit comments

Comments
 (0)