New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-4268] [core] Add parsers for BigDecimal/BigInteger #2304
Conversation
return -1; | ||
} | ||
|
||
String str = new String(bytes, startPos, i - startPos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating String instances, we could copy the relevant bytes into a reusable char[]
and create the BigDecimal
with the BigDecimal(char[] in, int offset, int len)
constructor.
Thanks @twalthr, PR looks good. Good to merge otherwise. |
057af26
to
c9fde0e
Compare
@fhueske I improved the big decimal parsing. Now less objects are created. I hope I didn't introduce new bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update @twalthr. I added a few comments to improve the reusage of the char[]
.
try { | ||
this.result = new BigDecimal(str); | ||
final int length = i - startPos; | ||
if (reuse == null || reuse.length != length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change this to reuse.length < length
to only create a new array in case more space is needed?
reuse[j] = (char) bytes[startPos + j]; | ||
} | ||
|
||
this.result = new BigDecimal(reuse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use the BigDecimal(char[] in, int offset, int len)
and reuse the reuse
object also if it is larger than then provided input.
@@ -120,7 +132,14 @@ public static final BigDecimal parseField(byte[] bytes, int startPos, int length | |||
throw new NumberFormatException("There is leading or trailing whitespace in the numeric field."); | |||
} | |||
|
|||
String str = new String(bytes, startPos, i); | |||
return new BigDecimal(str); | |||
final char[] reuse = new char[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reuse
is not reused here but created new in every method invocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't notice it's a static
method...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to rename the variable though.
Thanks again for the review @fhueske. I will fix your comments and merge this. |
Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the How To Contribute guide.
In addition to going through the list, please provide a meaningful description of your changes.
mvn clean verify
has been executed successfully locally or a Travis build has passedThis PR is similar to FLINK-4248. It adds parsers for the basic types
BigDecimal
andBigInteger
.