-
Notifications
You must be signed in to change notification settings - Fork 191
Cannot retrieve map that contains BigInteger using SDC. #1611
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
Comments
The work-around would be to save BigIntegers as strings when using the java sdk directly. Edit: Although the following is mostly correct, numbers greater than 53 bits will have the lower-bits truncated when retrieved through a n1ql query. Thus the 12345678901234567890 used in the example will be returned as 12345678901234567000 from a n1ql query. It is better to store BigIntegers as strings (SDC does this automatically). It's odd that this hasn't come up earlier. The issue stems from org.springframework.data.mapping.model omitting BigInteger (it also omits BigDecimal) - and CouchbaseSimpleTypes does not add it. A better solution would be to add NumberToBigInteger/BigIntegerToNumber converters to OtherConverters - but this would make data written by the "fixed" SDC incompatible for reading with an un-fixed version SDC. I've re-worked the provided test cases to use the BigIntegerEntity from MappingCouchbaseConverterTests.java.
Yes. But on retrieval it is being stored (put) in a CouchbaseDocument, which is decoded into the entity. |
Are there any news on this issue? I have the same problem, and I don't understand if there is a way forward.
I don't think this is an argument against adding these converters: as long as large numbers in a document can be mapped to BigDecimal/BigInteger, I think SDC should handle them. They could come from any source, not necessarily SDC. |
SDC serialize/deserialezes BigIntegers as strings because Integers larger than 2^64 do not fit in longs. What do you want the behavior to be? Fail on Bigintegers larger than 2^64 ? |
I don't understand: is it doing it already or not? Because in your first comment you said this would be a workaround. |
If you have the "same problem", then it is not doing "it". This work-around is a work-around. The java sdk does not do this. The application using the java sdk would need to do this. It's up to the application on how to implement that.
What do you want the "way forward" to be? Given that there already documents with BigIntegers written as integer numbers in documents by the Java SDK, and also documents with BigIntegers written as strings by SDC, and that any "way forward" cannot break anything that already works.
You can provide your own customer converters to handle any conversion. Do you have converters to propose that wouldn't break on existing documents?
Breaking existing functionality is indeed an argument. |
I understand your point, but how can I read a document created with another interface, which puts the numbers in as they are? Is there a way to support both formats? |
Including Number as a valid simple type for DOCUMENT_TYPES will result in BigInteger and BigDecimal (and any Number) to be written (and read) in the form of a number (no quotes). I don't know why this was not allowed from the beginning. CouchbaseSimpleTypes.java:
This also solves the issue of BigIntegers and BigDecimals that have already been written as Strings. The only problem is that that using query truncates (rounds-down) over 63 bits down to 53 bits. https://issues.couchbase.com/browse/MB-24464 |
Also be able to read BigDecimal and BigInteger that were written as String. Also does not lose precision by converting BigDecimal to double in the transcoder. Closes #1611.
Hi!
I am running into an issue when i try to retrieve a document that contains a key with a BigInteger type value.
The error I am getting is a bit missleading since the document is stored correctly but fail to retrieve:
This seems to be a limitation only on the SDC sdk since I tried to store and retrieve the document with the Couchbase Driver class (Cluster) and I was able to do it without any issues.
I did some debugging in the code and it looks like there is check in the CouchbaseDocument.java class (line 126) that uses CouchbaseSimpleTypes to test if the type of the value that is beign loaded matches certain types: CouchbaseDocument.class, CouchbaseList.class.
I created a repository with a couple test to repro the issue: https://github.com/mmonti/sdc-biginteger-issue/blob/master/src/test/java/com/example/biginteger/BigIntegerIssue.java
I am using spring-data-couchbase 4.4.5 in the repro project, but i can confirm that the issue is also present in spring-data-couchbase 3.1.18.
I just wanted to know if this is a known issue and if there is any possible workaround for it.
Thanks!
The text was updated successfully, but these errors were encountered: