summaryrefslogtreecommitdiff
path: root/sql/item_create.cc
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2022-10-28 13:03:13 +0530
committerRucha Deodhar <rucha.deodhar@mariadb.com>2023-04-26 11:00:08 +0530
commit358b8495f5ffb19a1a89574fd897261e8ff12938 (patch)
tree7cf421be3ec83efff6a9905c13c3c9e2687cdc1a /sql/item_create.cc
parentaf0e0ad18d5295d57696e3d26d5a7b13dca4e420 (diff)
downloadmariadb-git-358b8495f5ffb19a1a89574fd897261e8ff12938.tar.gz
MDEV-27128: Implement JSON Schema Validation FUNCTION
Implementation: Implementation is made according to json schema validation draft 2020 JSON schema basically has same structure as that of json object, consisting of key-value pairs. So it can be parsed in the same manner as any json object. However, none of the keywords are mandatory, so making guess about the json value type based only on the keywords would be incorrect. Hence we need separate objects denoting each keyword. So during create_object_and_handle_keyword() we create appropriate objects based on the keywords and validate each of them individually on the json document by calling respective validate() function if the type matches. If any of them fails, return false, else return true.
Diffstat (limited to 'sql/item_create.cc')
-rw-r--r--sql/item_create.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc
index 704d86d0ec3..64cb79da31a 100644
--- a/sql/item_create.cc
+++ b/sql/item_create.cc
@@ -1352,6 +1352,18 @@ protected:
virtual ~Create_func_json_overlaps() {}
};
+class Create_func_json_schema_valid: public Create_func_arg2
+{
+public:
+ virtual Item *create_2_arg(THD *thd, Item *arg1, Item *arg2);
+
+ static Create_func_json_schema_valid s_singleton;
+
+protected:
+ Create_func_json_schema_valid() {}
+ virtual ~Create_func_json_schema_valid() {}
+};
+
class Create_func_last_day : public Create_func_arg1
{
@@ -4413,6 +4425,15 @@ Create_func_last_insert_id::create_native(THD *thd, const LEX_CSTRING *name,
return func;
}
+Create_func_json_schema_valid Create_func_json_schema_valid::s_singleton;
+
+Item*
+Create_func_json_schema_valid::create_2_arg(THD *thd, Item *arg1, Item *arg2)
+{
+ status_var_increment(thd->status_var.feature_json);
+ return new (thd->mem_root) Item_func_json_schema_valid(thd, arg1, arg2);
+}
+
Create_func_lcase Create_func_lcase::s_singleton;
@@ -5824,6 +5845,7 @@ Native_func_registry func_array[] =
{ { STRING_WITH_LEN("JSON_OVERLAPS") }, BUILDER(Create_func_json_overlaps)},
{ { STRING_WITH_LEN("JSON_REMOVE") }, BUILDER(Create_func_json_remove)},
{ { STRING_WITH_LEN("JSON_REPLACE") }, BUILDER(Create_func_json_replace)},
+ { { STRING_WITH_LEN("JSON_SCHEMA_VALID") }, BUILDER(Create_func_json_schema_valid)},
{ { STRING_WITH_LEN("JSON_SET") }, BUILDER(Create_func_json_set)},
{ { STRING_WITH_LEN("JSON_SEARCH") }, BUILDER(Create_func_json_search)},
{ { STRING_WITH_LEN("JSON_TYPE") }, BUILDER(Create_func_json_type)},