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

    https://github.com/apache/spark/pull/5574#discussion_r28914579
  
    --- Diff: 
network/common/src/main/java/org/apache/spark/network/util/JavaUtils.java ---
    @@ -186,5 +199,84 @@ public static long timeStringAsMs(String str) {
       public static long timeStringAsSec(String str) {
         return parseTimeString(str, TimeUnit.SECONDS);
       }
    +  
    +  /**
    +   * Convert a passed byte string (e.g. 50b, 100kb, or 250mb) to a 
ByteUnit for
    +   * internal use. If no suffix is provided a direct conversion of the 
provided default is 
    +   * attempted.
    +   */
    +  private static long parseByteString(String str, ByteUnit unit) {
    +    String lower = str.toLowerCase().trim();
    +
    +    try {
    +      Matcher m = Pattern.compile("([0-9]+)([a-z]+)?").matcher(lower);
    +      Matcher fractionMatcher = 
Pattern.compile("([0-9]*\\.[0-9]*)([a-z]+)?").matcher(lower);
    +      
    +      if(m.matches()) {
    +        long val = Long.parseLong(m.group(1));
    +        String suffix = m.group(2);
    +
    +        // Check for invalid suffixes
    +        if (suffix != null && !byteSuffixes.containsKey(suffix)) {
    +          throw new NumberFormatException("Invalid suffix: \"" + suffix + 
"\"");
    +        }
    +
    +        // If suffix is valid use that, otherwise none was provided and 
use the default passed
    +        return unit.interpret(val, suffix != null ? 
byteSuffixes.get(suffix) : unit);  
    +      } else if (fractionMatcher.matches()) {
    +        double val = Double.parseDouble(fractionMatcher.group(1));
    +
    +        throw new NumberFormatException("Fractional values are not 
supported. Input was: " + val);
    --- End diff --
    
    hmmm... why bother with the match then?


---
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