Skip to content

Add codec for BigInteger #235

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

Merged
merged 1 commit into from
Jan 29, 2020
Merged

Conversation

timve
Copy link

@timve timve commented Jan 29, 2020

Applicable to any numeric type with scale 0

[resolves #233]

Applicable to any numeric type with scale 0

[resolves pgjdbc#233]
BigInteger doDecode(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format format, @Nullable Class<? extends BigInteger> type) {
Assert.requireNonNull(buffer, "byteBuf must not be null");

return this.decodeNumber(buffer, dataType, format, BigInteger.class, it -> new BigInteger(it.toString()));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code potentially throws NumberFormatException when the scale is > 0.
I did not find any defensive code in the other subclasses of AbstractNumericCodec so I did not add checks to see if construction of the BigInteger is possible using the decoded value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our codecs downcast values if they are requested to do so. E.g. a FLOAT8 column result can be consumed as Double, Long, Int etc. I think we should do the same here and return the BigInteger value.

I will take care of this aspect during the merge.

@timve timve mentioned this pull request Jan 29, 2020
@mp911de mp911de added this to the 0.8.1.RELEASE milestone Jan 29, 2020
@mp911de mp911de changed the title Add codec for BigIntegers (#233) Add codec for BigInteger Jan 29, 2020
@mp911de mp911de added the type: enhancement A general enhancement label Jan 29, 2020
@mp911de mp911de merged commit 69d832b into pgjdbc:master Jan 29, 2020
mp911de added a commit that referenced this pull request Jan 29, 2020
Add fast-path BigInteger conversion from BigDecimal. Use long value for all other numeric types to construct a BigInteger. Update copyright license header years.

[#233][#235]
mp911de added a commit that referenced this pull request Jan 29, 2020
mp911de pushed a commit that referenced this pull request Jan 29, 2020
Applicable to any numeric type with scale 0

[resolves #233][#235]
mp911de added a commit that referenced this pull request Jan 29, 2020
Add fast-path BigInteger conversion from BigDecimal. Use long value for all other numeric types to construct a BigInteger. Update copyright license header years.

[#233][#235]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a codec for BigInteger
2 participants