WL#13196: XProtocol: Collection with json-schema validation must return error for concrete row
Affects: Server-8.0
—
Status: Complete
Motivation ========== WL#12965 introduced a mechanism for validating data used in a collection. Operations that are not matching with existing validation schema return a generic error according to WL#12965 design. This error is just an indication of a validation failure but do not give any information how the schema constraint was violated. Goals ===== Get a meaningful error for each operation on a collection that violates the validation schema constraints. It is crucial for operations processing lots of data, because locating an offending data can be difficult. New error should describe how the schema was violated.
FR1 - each operation that violates validation schema on a collection must return an error that unambiguously determine what causes the validation schema failure. FR2 - insert operation violating a collection validation schema must return a meaningful error. FR3 - update operation violating a collection validation schema must return a meaningful error. FR4 - modify_collection_options command which sets new validation schema for which existing collection data violates the validation schema must return a meaningful error. FR5 - modify_collection_options command which enables validation for which the existing collection data violates schema constraints must return a meaningful error.
Validation error ================ WL#12965 introduced a validation mechanism for working with collections. Each operation on a collection is now validated against a validation schema, and in case when validation schema is violated an error is returned. This worklog aims at improving the existing generic error with a more detailed one. JSON constraint validation check error reporting is improved in WL#13195. It allows to use the 'GET DIAGNOSTICS' to get detailed information why the JSON validation failed. Based on this information the error message related with ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA error should be changed to forward this information to the user. Each existing occurence of ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA should trigger the following SQL to get validation error details: GET DIAGNOSTICS CONDITION 1 @%validation_message% = MESSAGE_TEXT; where %validation_message% is an identifier constructed in the following way: 1. Start with a dollar character, like all internal X Plugin identifiers. 2. Followed by "internal_" string. 3. Followed by "validation_error_message" string. Based on the information in %validation_message% variable the ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA error should contain the following error message: "Document is not valid according to the schema assigned to collection. %s.", %validation_message% Operations that affect multiple items must return an error about the first document not matching the validation schema. Example ======= Each operation listed below: 1. Insert a document containing 'latitude' field less than 45 to collection created with JSON schema like: '{"properties": {"latitude": { "minimum": 45}}, "required": ["latitude"]}' 2. Update the first existing document in a collection created with JSON schema: '{"properties": {"latitude": { "minimum": 45}}, "required": ["latitude"]}' to be less than 45. 3. For collection containing document with 'latitude' field less than 45 and with disabled schema validation: '{"properties": {"latitude": { "minimum": 45}}, "required": ["latitude"]}' enabling a schema validation by the 'modify_collection_options' command. 4. For collection containing document with 'latitude'=15 and schema: '{"properties": {"latitude": { "minimum": 0}}, "required": ["latitude"]}' modifying the validation schema using the 'modify_collection_options' command to be equal to: '{"properties": {"latitude": { "minimum": 45}}, "required": ["latitude"]}' Must return an ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA error with message like: "Document is not valid according to the schema assigned to collection. The JSON document location '#/latitude' failed requirement 'minimum' at JSON Schema location '#/properties/latitude'". Errors and warnings =================== * Operations on a collection that violates the validation schema should trigger the following error: |Property |Value | |--------------|------------------------------------------------------------| |Error code |ER_X_DOCUMENT_DOESNT_MATCH_EXPECTED_SCHEMA | |Error text |Document is not valid according to the schema assigned to | | |collection. %s. | |New error code|NO
Copyright (c) 2000, 2024, Oracle Corporation and/or its affiliates. All rights reserved.