Github user tejasapatil commented on a diff in the pull request:
https://github.com/apache/spark/pull/17184#discussion_r104843817
--- 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 --
Using IntWrapper for integers gives better perf. If we use LongWrapper for
integers, there would be a conversion needed from long -> int. Its not that big
of a difference but given that ints are used heavily in workloads, I dont want
to leave that behind.
Here is microbenchmark result for current approach VS using LongWrapper
everywhere
```
conversion to int: Best/Avg Time(ms) Rate(M/s)
Per Row(ns) Relative
------------------------------------------------------------------------------------------------
IntWrapper 20397 / 20564 26.3
38.0 1.0X
LongWrapper 20855 / 21530 25.7
38.8 1.0X
```
---
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]