Skip to content

Commit 2c8c557

Browse files
author
Amith Nagarajappa
committed
WL#16046 - Support of JSON functions and aggregation with JSON types
I. This WL adds support for below functions 1. JSON_VALID 2. JSON_TYPE 3. JSON_PRETTY 4. JSON_QUOTE 5. JSON_OVERLAPS 6. JSON_STORAGE_SIZE 7. JSON_STROAGE_FREE 8. JSON_CONTAINS 9. JSON_CONTAINS_PATH 10. JSON_KEYS 11. JSON_MEMBER_OF 12. JSON_VALUE 13. JSON_SEARCH This WL also adds group by and aggregation support with JSON types Bug#36418296 Segmentation fault in rpdmqxra2_write_prepare_varlen Bug#36424081 HeatWave does not return Invalid JSON text msg with JSON_SEARCH query Bug#36425131 Improve error message returned with invalid case of JSON_STORAGE_SIZE Bug#36454002 rpdserver crash in rpdmrtms_get_stats at rpdmrtms.c Bug#36449578 mysqld crash in rpd::(anonymous namespace):: NotSupportedType Change-Id: I8fe8b301734d18592c01f210e1553955f0b8defc
1 parent 75e3077 commit 2c8c557

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

sql-common/json_dom.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,6 @@ bool Json_wrapper::get_boolean() const {
18801880
return m_value.type() == json_binary::Value::LITERAL_TRUE;
18811881
}
18821882

1883-
#ifdef MYSQL_SERVER
18841883
Json_path Json_dom::get_location() const {
18851884
if (m_parent == nullptr) {
18861885
Json_path result(key_memory_JSON);
@@ -1908,7 +1907,6 @@ Json_path Json_dom::get_location() const {
19081907
return result;
19091908
}
19101909

1911-
#endif // ifdef MYSQL_SERVER
19121910
bool Json_dom::seek(const Json_seekable_path &path, size_t legs,
19131911
Json_dom_vector *hits, bool auto_wrap, bool only_need_one) {
19141912
const auto begin = path.begin();

sql/item_func.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,16 @@ class Item_func : public Item_result_field {
342342
JSON_DEPTH_FUNC,
343343
JSON_EXTRACT_FUNC,
344344
JSON_OBJECT_FUNC,
345-
JSON_ARRAY_FUNC
345+
JSON_ARRAY_FUNC,
346+
JSON_VALID_FUNC,
347+
JSON_TYPE_FUNC,
348+
JSON_PRETTY_FUNC,
349+
JSON_QUOTE_FUNC,
350+
JSON_CONTAINS_PATH_FUNC,
351+
JSON_STORAGE_SIZE_FUNC,
352+
JSON_STORAGE_FREE_FUNC,
353+
JSON_VALUE_FUNC,
354+
JSON_SEARCH_FUNC
346355
};
347356
enum optimize_type {
348357
OPTIMIZE_NONE,

sql/item_json_func.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,14 @@ enum Item_result Item_func_json_value::result_type() const {
40344034
return json_cast_result_type(m_cast_target);
40354035
}
40364036

4037+
Json_on_response_type Item_func_json_value::on_empty_response_type() const {
4038+
return m_on_empty;
4039+
}
4040+
4041+
Json_on_response_type Item_func_json_value::on_error_response_type() const {
4042+
return m_on_error;
4043+
}
4044+
40374045
bool Item_func_json_value::resolve_type(THD *) {
40384046
// The path must be a character literal, so it's never NULL.
40394047
assert(!args[1]->is_nullable());

sql/item_json_func.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class Item_func_json_valid final : public Item_int_func {
323323
Item_func_json_valid(const POS &pos, Item *a) : Item_int_func(pos, a) {}
324324

325325
const char *func_name() const override { return "json_valid"; }
326+
enum Functype functype() const override { return JSON_VALID_FUNC; }
326327

327328
bool is_bool_func() const override { return true; }
328329

@@ -442,6 +443,7 @@ class Item_func_json_contains_path final : public Item_int_func {
442443
m_path_cache(thd, arg_count) {}
443444

444445
const char *func_name() const override { return "json_contains_path"; }
446+
enum Functype functype() const override { return JSON_CONTAINS_PATH_FUNC; }
445447

446448
bool is_bool_func() const override { return true; }
447449

@@ -473,6 +475,7 @@ class Item_func_json_type : public Item_str_func {
473475
Item_func_json_type(const POS &pos, Item *a) : Item_str_func(pos, a) {}
474476

475477
const char *func_name() const override { return "json_type"; }
478+
enum Functype functype() const override { return JSON_TYPE_FUNC; }
476479

477480
bool resolve_type(THD *) override;
478481

@@ -788,6 +791,8 @@ class Item_func_json_search : public Item_json_func {
788791

789792
const char *func_name() const override { return "json_search"; }
790793

794+
enum Functype functype() const override { return JSON_SEARCH_FUNC; }
795+
791796
bool val_json(Json_wrapper *wr) override;
792797

793798
/**
@@ -890,6 +895,8 @@ class Item_func_json_quote : public Item_str_func {
890895

891896
const char *func_name() const override { return "json_quote"; }
892897

898+
enum Functype functype() const override { return JSON_QUOTE_FUNC; }
899+
893900
bool resolve_type(THD *thd) override {
894901
if (reject_vector_args()) return true;
895902
if (param_type_is_default(thd, 0, -1)) return true;
@@ -944,6 +951,8 @@ class Item_func_json_pretty final : public Item_str_func {
944951

945952
const char *func_name() const override { return "json_pretty"; }
946953

954+
enum Functype functype() const override { return JSON_PRETTY_FUNC; }
955+
947956
bool resolve_type(THD *thd) override {
948957
if (reject_vector_args()) return true;
949958
if (param_type_is_default(thd, 0, -1, MYSQL_TYPE_JSON)) return true;
@@ -962,6 +971,7 @@ class Item_func_json_storage_size final : public Item_int_func {
962971
Item_func_json_storage_size(const POS &pos, Item *a)
963972
: Item_int_func(pos, a) {}
964973
const char *func_name() const override { return "json_storage_size"; }
974+
enum Functype functype() const override { return JSON_STORAGE_SIZE_FUNC; }
965975

966976
bool resolve_type(THD *thd) override {
967977
if (reject_vector_args()) return true;
@@ -982,6 +992,7 @@ class Item_func_json_storage_free final : public Item_int_func {
982992
Item_func_json_storage_free(const POS &pos, Item *a)
983993
: Item_int_func(pos, a) {}
984994
const char *func_name() const override { return "json_storage_free"; }
995+
enum Functype functype() const override { return JSON_STORAGE_FREE_FUNC; }
985996

986997
bool resolve_type(THD *thd) override {
987998
if (reject_vector_args()) return true;
@@ -1121,6 +1132,7 @@ class Item_func_json_value final : public Item_func {
11211132
Item *on_error_default);
11221133
~Item_func_json_value() override;
11231134
const char *func_name() const override { return "json_value"; }
1135+
enum Functype functype() const override { return JSON_VALUE_FUNC; }
11241136
enum Item_result result_type() const override;
11251137
bool resolve_type(THD *) override;
11261138
bool fix_fields(THD *thd, Item **ref) override;
@@ -1134,6 +1146,8 @@ class Item_func_json_value final : public Item_func {
11341146
my_decimal *val_decimal(my_decimal *value) override;
11351147
bool get_date(MYSQL_TIME *ltime, my_time_flags_t flags) override;
11361148
bool get_time(MYSQL_TIME *ltime) override;
1149+
Json_on_response_type on_empty_response_type() const;
1150+
Json_on_response_type on_error_response_type() const;
11371151

11381152
private:
11391153
/// Represents a default value given in JSON_VALUE's DEFAULT xxx ON EMPTY or

0 commit comments

Comments
 (0)