Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8034#discussion_r36546166
  
    --- Diff: 
unsafe/src/main/java/org/apache/spark/unsafe/types/CalendarInterval.java ---
    @@ -79,6 +87,152 @@ public static CalendarInterval fromString(String s) {
         }
       }
     
    +  public static long toLongWithRange(String fieldName,
    +      String s, long minValue, long maxValue) throws 
IllegalArgumentException {
    +    long result = 0;
    +    if (s != null) {
    +      result = Long.valueOf(s);
    +      if (result < minValue || result > maxValue) {
    +        throw new IllegalArgumentException(String.format("%s %d outside 
range [%d, %d]",
    +          fieldName, result, minValue, maxValue));
    +      }
    +    }
    +    return result;
    +  }
    +
    +  /**
    +   * Parse YearMonth string in form: [-]YYYY-MM
    +   *
    +   * adapted from HiveIntervalYearMonth.valueOf
    +   */
    +  public static CalendarInterval fromYearMonthString(String s) {
    +    CalendarInterval result = null;
    +    if (s == null) {
    +      throw new IllegalArgumentException("Interval year-month string was 
null");
    +    }
    +    s = s.trim();
    +    Matcher m = yearMonthPattern.matcher(s);
    +    if (!m.matches()) {
    +      throw new IllegalArgumentException(
    +        "Interval string does not match year-month format of 'y-m': " + s);
    +    } else {
    +      try {
    +        int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
    +        int years = (int) toLongWithRange("year", m.group(2), 0, 
Integer.MAX_VALUE);
    +        int months = (int) toLongWithRange("month", m.group(3), 0, 11);
    +        result = new CalendarInterval(sign * (years * 12 + months), 0);
    +      } catch (Exception e) {
    +        throw new IllegalArgumentException(
    +          "Error parsing interval year-month string: " + e.getMessage(), 
e);
    +      }
    +    }
    +    return result;
    +  }
    +
    +  /**
    +   * Parse dayTime string in form: [-]d HH:mm:ss.nnnnnnnnn
    +   *
    +   * adapted from HiveIntervalDayTime.valueOf
    +   */
    +  public static CalendarInterval fromDayTimeString(String s) {
    --- End diff --
    
    and here


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to