Skip to content
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

Schould BigInteger be always used for integral min/max #157

Closed
kosty opened this issue May 31, 2019 · 4 comments
Closed

Schould BigInteger be always used for integral min/max #157

kosty opened this issue May 31, 2019 · 4 comments
Assignees

Comments

@kosty
Copy link
Contributor

kosty commented May 31, 2019

While this comment is absolutely true. In practice it mostly plays out when JsonNode tree was constructed manually and not through jackson's ObjectMapper

//node.isBigInteger is not trustable, the type BigInteger doesn't mean it is a big number.

Generally, given that isBigInteger could not be trusted, should the two cases be merged into one? Original split was based on thinking that ObjectMapper is always used to construct JsonNode tree and allowed to save some memory by not referencing additional BigInteger object. Since it is not longer the case, there is little benefit in keeping

case 2

separate from

case 1

} else if ( schemaNode.isLong() || schemaNode.isInt() ) {

And merging them will probably be more readable

@stevehu
Copy link
Contributor

stevehu commented Jun 25, 2019

@BalloonWen @jiachen1120 I thought we have made some changes on this logic. Could you please comment on this? Thanks.

@BalloonWen
Copy link
Contributor

While this comment is absolutely true. In practice it mostly plays out when JsonNode tree was constructed manually and not through jackson's ObjectMapper

//node.isBigInteger is not trustable, the type BigInteger doesn't mean it is a big number.

Generally, given that isBigInteger could not be trusted, should the two cases be merged into one? Original split was based on thinking that ObjectMapper is always used to construct JsonNode tree and allowed to save some memory by not referencing additional BigInteger object. Since it is not longer the case, there is little benefit in keeping

case 2

separate from

case 1

} else if ( schemaNode.isLong() || schemaNode.isInt() ) {

And merging them will probably be more readable

Hi @kosty , thank you for pointing this out, I found the same problem and made some changes recently,
we need to satisfy another case: the node type is an integer but the maximum in the schema is a float number, related issue: #160
right now the logic will be:

  • only if the node type and the maximum in the schema are both integer/long type:
    • check if the node type is bigInteger, in the case that the node value may be bigger than the max value of long. (compare by BigInteger)
    • if not bigInteger, then compare by long value. ( as you said to save some memory by not referencing additional BigInteger object)
  • if any of the node type and the maximum in the schema is a float type:
    • compare using BigDecimal (this should not be a big use case, using BigDecimal will reduce many defects such as the overflow of a Double value, the edge of the max of a double, compare with "Infinity" etc.). Also, I did a performance test, there are no obvious differences, I think the most time-consuming part is the node constructing instead of comparing.

I should have asked you for reviewing #164 since you did a lot of research and work on those parts. Please advise. 😄

@kosty
Copy link
Contributor Author

kosty commented Jul 16, 2019

Glad there is a resolution on this!

@kosty kosty closed this as completed Jul 16, 2019
kosty added a commit to kosty/json-schema-validator that referenced this issue Jul 18, 2019
kosty added a commit to kosty/json-schema-validator that referenced this issue Jul 19, 2019
kosty added a commit to kosty/json-schema-validator that referenced this issue Jul 19, 2019
@kosty
Copy link
Contributor Author

kosty commented Jul 19, 2019

@BalloonWen was playing with that part of code a bit and decided to dive a bit into performance tradeoffs. see comments in #174

Hopefully you'll find those useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants