cloud-fan commented on a change in pull request #26190: [SPARK-29532][SQL]
simplify interval string parsing
URL: https://github.com/apache/spark/pull/26190#discussion_r336902790
##########
File path:
common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java
##########
@@ -250,62 +167,55 @@ public static CalendarInterval
fromSingleUnitString(String unit, String s)
throw new IllegalArgumentException(String.format("Interval %s string was
null", unit));
}
s = s.trim();
- Matcher m = quoteTrimPattern.matcher(s);
- if (!m.matches()) {
- throw new IllegalArgumentException(
- "Interval string does not match day-time format of 'd h:m:s.n': " + s);
- } else {
- try {
- switch (unit) {
- case "year":
- int year = (int) toLongWithRange("year", m.group(1),
- Integer.MIN_VALUE / 12, Integer.MAX_VALUE / 12);
- result = new CalendarInterval(year * 12, 0L);
- break;
- case "month":
- int month = (int) toLongWithRange("month", m.group(1),
- Integer.MIN_VALUE, Integer.MAX_VALUE);
- result = new CalendarInterval(month, 0L);
- break;
- case "week":
- long week = toLongWithRange("week", m.group(1),
- Long.MIN_VALUE / MICROS_PER_WEEK, Long.MAX_VALUE /
MICROS_PER_WEEK);
- result = new CalendarInterval(0, week * MICROS_PER_WEEK);
- break;
- case "day":
- long day = toLongWithRange("day", m.group(1),
- Long.MIN_VALUE / MICROS_PER_DAY, Long.MAX_VALUE /
MICROS_PER_DAY);
- result = new CalendarInterval(0, day * MICROS_PER_DAY);
- break;
- case "hour":
- long hour = toLongWithRange("hour", m.group(1),
- Long.MIN_VALUE / MICROS_PER_HOUR, Long.MAX_VALUE /
MICROS_PER_HOUR);
- result = new CalendarInterval(0, hour * MICROS_PER_HOUR);
- break;
- case "minute":
- long minute = toLongWithRange("minute", m.group(1),
- Long.MIN_VALUE / MICROS_PER_MINUTE, Long.MAX_VALUE /
MICROS_PER_MINUTE);
- result = new CalendarInterval(0, minute * MICROS_PER_MINUTE);
- break;
- case "second": {
- long micros = parseSecondNano(m.group(1));
- result = new CalendarInterval(0, micros);
- break;
- }
- case "millisecond":
- long millisecond = toLongWithRange("millisecond", m.group(1),
- Long.MIN_VALUE / MICROS_PER_MILLI, Long.MAX_VALUE /
MICROS_PER_MILLI);
- result = new CalendarInterval(0, millisecond * MICROS_PER_MILLI);
- break;
- case "microsecond": {
- long micros = Long.parseLong(m.group(1));
- result = new CalendarInterval(0, micros);
- break;
- }
+ try {
Review comment:
only indentation change
----------------------------------------------------------------
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]