[SERVER-30742] Fail with a useful error message when given "integer" type keyword for JSON Schema Created: 18/Aug/17  Updated: 30/Oct/23  Resolved: 11/Sep/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.5.13

Type: Task Priority: Major - P3
Reporter: Kyle Suarez Assignee: Nicholas Zolnierz
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Query 2017-10-02
Participants:

 Description   

JSON Schema Draft 04 accepts "integer" as a primitive JSON type. However, we do not plan to support this in MongoDB's implementation. If we encounter type: "integer", we should fail during parsing with a useful error message.



 Comments   
Comment by Ramon Fernandez Marina [ 11/Sep/17 ]

Author:

{'username': u'nzolnierzmdb', 'name': u'Nick Zolnierz', 'email': u'nicholas.zolnierz@mongodb.com'}

Message:SERVER-30742: Fail with a useful error message when given integer type keyword for JSON Schema
Branch:master
https://github.com/mongodb/mongo/commit/7044c03093a01bbbcbdbac9ba49f800d36fc9c1f

Comment by David Storch [ 23/Aug/17 ]

asya that seems reasonable, but I have two reservations:

  1. It's a bit odd that we only partially support the type keyword. The other aspects of JSON Schema we either wholesale support or wholesale omit.
  2. The official JSON Schema test suite, which we have integrated into the mongo code base, uses integer in many places. Our lack of support means that we will either have to modify the official tests or disable many of them.

kyle.suarez, instead of closing as Won't Fix, we should convert this into a task about error reporting. The error should be along the lines of "type:"integer" is not supported" rather than "unknown type".

Comment by Kyle Suarez [ 23/Aug/17 ]

david.storch, given Asya's feedback I think we should just close this as Won't Fix.

Comment by Asya Kamsky [ 23/Aug/17 ]

From the product perspective, I would prefer that we don't support the keyword "integer".

  • it introduces an unnecessary ambiguity where it's difficult to reason whether it will match integral values of Decimal type
  • it's not necessary, those types can be expressed using bson types
  • my research shows it doesn't show up among our customers who already use json schema
  • it's easy to add it later, it would be very difficult to remove it
Comment by David Storch [ 23/Aug/17 ]

As an aside, the second bullet point may be tricky, especially for extremely large binary64 or decimal128 values, as I'm not sure if we can simply round-trip to an integer supported by C++.

I was hoping it would be sufficient for a number to match {type: "integer"} if it has an exact representation as a NumberLong. We already have well-tested code which implements this in the match expression parser:

https://github.com/mongodb/mongo/blob/ee6a79935e98b4a12bc74cb385e7d5f62633347e/src/mongo/db/matcher/expression_parser.h#L126-L134

So a follow-up question is, would this have to work for decimal128 integers that are too large positive or too large negative to fit inside a 64 bit signed integer?

Comment by Kyle Suarez [ 23/Aug/17 ]

asya, after discussing with david.storch, we think we should do this, and that the "integer" type alias should:

  • match anything of type NumberInt and NumberLong;
  • match a NumberDouble or a NumberDecimal that has an integral value

It's not fully spec-compliant with JSON Schema, but this is as close as we're going to get given that MongoDB is more than just JSON. What's your take on this?

As an aside, the second bullet point may be tricky, especially for extremely large binary64 or decimal128 values, as I'm not sure if we can simply round-trip to an integer supported by C++.

Comment by Kyle Suarez [ 18/Aug/17 ]

It's worth noting that more recent versions of the JSON Schema drafts don't include "integer". However, I personally think we should add it, since we advertise that we support Draft 04 and this won't be too difficult to do.

Generated at Thu Feb 08 04:24:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.