[MDEV-27128] Implement JSON Schema Validation FUNCTION Created: 2021-11-26 Updated: 2023-11-27 Resolved: 2023-04-26 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Fix Version/s: | 11.1.1 |
| Type: | Task | Priority: | Blocker |
| Reporter: | Rúben Ferreira | Assignee: | Rucha Deodhar |
| Resolution: | Fixed | Votes: | 4 |
| Labels: | CONSTRAINT, JSON, Preview_11.1, compat80 | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Sub-Tasks: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Epic Link: | Implement JSON functions available in MySQL 8.0 but not MariaDB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
A great addition to MariaDB would be able to validate JSON schemas. MySQL already have this implemented as follows: JSON_SCHEMA_VALID(schema,document) Validates a JSON document against a JSON schema. Both schema and document are required. The schema must be a valid JSON object; the document must be a valid JSON document. Provided that these conditions are met: If the document validates against the schema, the function returns true (1); otherwise, it returns false (0). Since MariaDB is great and it allows the use of UDFs and deterministic functions on constraints something like this would be awesome:
or
The word schema should be replaced by a string representing a valid JSON schema. |
| Comments |
| Comment by Federico Razzoli [ 2022-08-16 ] | |||||||||||||||||||||||||||||||
|
Which JSON Schema version is being implemented? Note that MySQL uses Draft 4 - actually a subset of it, as the documentation omits to mention. Draft 4 problems:
| |||||||||||||||||||||||||||||||
| Comment by Rucha Deodhar [ 2022-09-13 ] | |||||||||||||||||||||||||||||||
|
Final Patch: https://github.com/MariaDB/server/tree/bb-11.1-MDEV-27128 | |||||||||||||||||||||||||||||||
| Comment by Rucha Deodhar [ 2022-09-13 ] | |||||||||||||||||||||||||||||||
|
f_razzoli We support the 2020 draft with some exception. | |||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2022-09-18 ] | |||||||||||||||||||||||||||||||
|
didn't agree with parts of the design. Comments sent by email. | |||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2022-12-22 ] | |||||||||||||||||||||||||||||||
|
ok with a couple of corrections discussed on Slack. | |||||||||||||||||||||||||||||||
| Comment by Lena Startseva [ 2023-02-27 ] | |||||||||||||||||||||||||||||||
|
Some cases I'm not sure how it should be: 1. I suppose that for all cases where JSON_SCHEMA_VALID returns warning due to incorrect schema the result must be NULL. An example can be taken from
2. With uniqueItems=true for array I guess 'null' and 'null' should be duplicate items, but that's not the case right now:
3. All parameters marked as "be a non-negative integer" in the schema must be checked for this condidtion. So, I suppose in cases like the following one should return null and warning or error:
4. Also for parameter "required": The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.
After fixing bugs and rebasing on the actual tree, a little rechecking will be required (for checked options). | |||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2023-03-06 ] | |||||||||||||||||||||||||||||||
|
See comments to the commit | |||||||||||||||||||||||||||||||
| Comment by Rucha Deodhar [ 2023-03-06 ] | |||||||||||||||||||||||||||||||
|
lstartseva Thanks for the comment. You're right. I've fixed it as part of below patch 1) https://github.com/MariaDB/server/commit/357c208d67fa90b79da013c6cb7fae044af8c1b6 | |||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2023-03-15 ] | |||||||||||||||||||||||||||||||
|
Comments on slack. | |||||||||||||||||||||||||||||||
| Comment by Rucha Deodhar [ 2023-03-16 ] | |||||||||||||||||||||||||||||||
|
( Reassigned after working on review 2 for final check ) | |||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2023-03-16 ] | |||||||||||||||||||||||||||||||
|
commit 70a7de2aed7677ef9e0a14f5734150cbc58023ae | |||||||||||||||||||||||||||||||
| Comment by Ramesh Sivaraman [ 2023-04-25 ] | |||||||||||||||||||||||||||||||
|
ok to push |