lipzhu commented on a change in pull request #25000: [SPARK-28107][SQL] Support
'day to hour', 'day to minute', ‘day to second’, 'hour to minute', 'hour to
second' and 'minute to second'
URL: https://github.com/apache/spark/pull/25000#discussion_r301404225
##########
File path:
common/unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java
##########
@@ -174,12 +191,47 @@ public static CalendarInterval fromDayTimeString(String
s) throws IllegalArgumen
int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
long days = m.group(2) == null ? 0 : toLongWithRange("day", m.group(3),
0, Integer.MAX_VALUE);
- long hours = toLongWithRange("hour", m.group(4), 0, 23);
- long minutes = toLongWithRange("minute", m.group(5), 0, 59);
- long seconds = toLongWithRange("second", m.group(6), 0, 59);
+ long hours;
+ long minutes;
+ long seconds;
+ if ("minute".equals(from)) {
+ hours = m.group(6) == null ? 0 : toLongWithRange("hour", m.group(4),
0, 23);
+ minutes = m.group(6) == null ? toLongWithRange("minute", m.group(4),
0, 59)
+ : toLongWithRange("minute", m.group(5), 0, 59);
+ seconds = m.group(6) == null ? toLongWithRange("minute", m.group(5),
0, 59)
+ : toLongWithRange("second", m.group(7), 0, 59);
+ } else {
+ if (m.group(8) != null && m.group(6) == null) {
+ hours = 0;
+ minutes = toLongWithRange("minute", m.group(4), 0, 59);
+ seconds = toLongWithRange("second", m.group(5), 0, 59);
+ } else {
+ hours = toLongWithRange("hour", m.group(4), 0, 23);
+ minutes = toLongWithRange("minute", m.group(5), 0, 59);
+ seconds = toLongWithRange("second", m.group(7), 0, 59);
+ }
+ }
// Hive allow nanosecond precision interval
- String nanoStr = m.group(8) == null ? null : (m.group(8) +
"000000000").substring(0, 9);
+ String nanoStr = m.group(8) == null ? null : (m.group(9) +
"000000000").substring(0, 9);
Review comment:
This is because the `dayTimePattern` changed. The length of the pattern
groups is 9.
e.g. '20 15:40:32.99899999' group(8) = ".99899999" and group(9) =
"99899999"
----------------------------------------------------------------
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]