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

    https://github.com/apache/spark/pull/17184#discussion_r104841789
  
    --- Diff: 
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
    @@ -897,41 +898,52 @@ public long toLong() {
             break;
           }
     
    -      int digit = getDigit(b);
    +      int digit;
    +      if (b >= '0' && b <= '9') {
    +        digit = b - '0';
    +      } else {
    +        return false;
    +      }
    +
           // We are going to process the new digit and accumulate the result. 
However, before doing
           // this, if the result is already smaller than the 
stopValue(Long.MIN_VALUE / radix), then
    -      // result * 10 will definitely be smaller than minValue, and we can 
stop and throw exception.
    +      // result * 10 will definitely be smaller than minValue, and we can 
stop.
           if (result < stopValue) {
    -        throw new NumberFormatException(toString());
    +        return false;
           }
     
           result = result * radix - digit;
           // Since the previous result is less than or equal to 
stopValue(Long.MIN_VALUE / radix), we
    -      // can just use `result > 0` to check overflow. If result overflows, 
we should stop and throw
    -      // exception.
    +      // can just use `result > 0` to check overflow. If result overflows, 
we should stop.
           if (result > 0) {
    -        throw new NumberFormatException(toString());
    +        return false;
           }
         }
     
         // This is the case when we've encountered a decimal separator. The 
fractional
         // part will not change the number, but we will verify that the 
fractional part
         // is well formed.
         while (offset < numBytes) {
    -      if (getDigit(getByte(offset)) == -1) {
    -        throw new NumberFormatException(toString());
    +      byte currentByte = getByte(offset);
    +      if (currentByte < '0' || currentByte > '9') {
    +        return false;
           }
           offset++;
         }
     
         if (!negative) {
           result = -result;
           if (result < 0) {
    -        throw new NumberFormatException(toString());
    +        return false;
           }
         }
     
    -    return result;
    +    toLongResult.value = result;
    +    return true;
    +  }
    +
    +  public static class IntWrapper {
    --- End diff --
    
    actually why bother having an IntWrapper? Can't you use LongWrapper?


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