dongjoon-hyun commented on a change in pull request #24472: [SPARK-27578][SQL]
Add support for "interval '23:59:59' hour to second"
URL: https://github.com/apache/spark/pull/24472#discussion_r287858167
##########
File path:
common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java
##########
@@ -164,6 +167,35 @@ public static CalendarInterval fromDayTimeString(String
s) throws IllegalArgumen
return result;
}
+ /**
+ * Parse dayTime string in form: HH:mm:ss.nnnnnnnnn
+ */
+ public static CalendarInterval fromHourTimeString(String s) throws
IllegalArgumentException {
+ if (s == null) {
+ throw new IllegalArgumentException("Interval hour-time string was null");
+ }
+ s = s.trim();
+ Matcher m = hourTimePattern.matcher(s);
+ if (!m.matches()) {
+ throw new IllegalArgumentException(
+ "Interval string does not match hour-time format of 'h:m:s.n': " + s);
+ } else {
+ try {
+ int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
+ long hours = toLongWithRange("hour", m.group(2), 0, 23);
+ long minutes = toLongWithRange("minute", m.group(3), 0, 59);
+ long seconds = toLongWithRange("second", m.group(4), 0, 59);
+ // Hive allow nanosecond precision interval
+ long nanos = toLongWithRange("nanosecond", m.group(6), 0L, 999999999L);
+ return new CalendarInterval(0, sign * (hours * MICROS_PER_HOUR +
+ minutes * MICROS_PER_MINUTE + seconds * MICROS_PER_SECOND + nanos /
1000L));
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ "Error parsing interval hour-time string: " + e.getMessage(), e);
+ }
+ }
+ }
Review comment:
We can remove this new function.
----------------------------------------------------------------
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]