Commit e290e5a7 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-22837 JSON_ARRAYAGG and JSON_OBJECTAGG treat JSON arguments as text.

Item_field::is_json_value() implemented.
parent 6c573a91
...@@ -1320,6 +1320,13 @@ Warnings: ...@@ -1320,6 +1320,13 @@ Warnings:
Warning 1260 Row 1 was cut by JSON_ARRAYAGG() Warning 1260 Row 1 was cut by JSON_ARRAYAGG()
drop table t1; drop table t1;
SET group_concat_max_len= default; SET group_concat_max_len= default;
create table t1 (col1 json);
insert into t1 values('{"color":"red", "size":1}' );
insert into t1 values('{"color":"blue", "size":2}' );
select JSON_ARRAYAGG(col1) from t1;
JSON_ARRAYAGG(col1)
[{"color":"red", "size":1},{"color":"blue", "size":2}]
drop table t1;
# #
# End of 10.5 tests # End of 10.5 tests
# #
...@@ -820,6 +820,12 @@ select json_arrayagg(a) from t1; ...@@ -820,6 +820,12 @@ select json_arrayagg(a) from t1;
drop table t1; drop table t1;
SET group_concat_max_len= default; SET group_concat_max_len= default;
create table t1 (col1 json);
insert into t1 values('{"color":"red", "size":1}' );
insert into t1 values('{"color":"blue", "size":2}' );
select JSON_ARRAYAGG(col1) from t1;
drop table t1;
--echo # --echo #
--echo # End of 10.5 tests --echo # End of 10.5 tests
--echo # --echo #
......
...@@ -3052,6 +3052,17 @@ Item_field::Item_field(THD *thd, Item_field *item) ...@@ -3052,6 +3052,17 @@ Item_field::Item_field(THD *thd, Item_field *item)
} }
bool Item_field::is_json_type()
{
if (!field->check_constraint ||
field->check_constraint->expr->type() != FUNC_ITEM)
return FALSE;
Item_func *f= (Item_func *) field->check_constraint->expr;
return f->functype() == Item_func::JSON_VALID_FUNC;
}
void Item_field::set_field(Field *field_par) void Item_field::set_field(Field *field_par)
{ {
field=result_field=field_par; // for easy coding with fields field=result_field=field_par; // for easy coding with fields
......
...@@ -3389,6 +3389,7 @@ class Item_field :public Item_ident, ...@@ -3389,6 +3389,7 @@ class Item_field :public Item_ident,
my_decimal *val_decimal_result(my_decimal *); my_decimal *val_decimal_result(my_decimal *);
bool val_bool_result(); bool val_bool_result();
bool is_null_result(); bool is_null_result();
bool is_json_type();
bool send(Protocol *protocol, st_value *buffer); bool send(Protocol *protocol, st_value *buffer);
Load_data_outvar *get_load_data_outvar() Load_data_outvar *get_load_data_outvar()
{ {
......
...@@ -76,7 +76,7 @@ class Item_func :public Item_func_or_sum, ...@@ -76,7 +76,7 @@ class Item_func :public Item_func_or_sum,
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC, SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC, EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC,
NEG_FUNC, GSYSVAR_FUNC, IN_OPTIMIZER_FUNC, DYNCOL_FUNC, NEG_FUNC, GSYSVAR_FUNC, IN_OPTIMIZER_FUNC, DYNCOL_FUNC,
JSON_EXTRACT_FUNC, JSON_EXTRACT_FUNC, JSON_VALID_FUNC,
CASE_SEARCHED_FUNC, // Used by ColumnStore/Spider CASE_SEARCHED_FUNC, // Used by ColumnStore/Spider
CASE_SIMPLE_FUNC // Used by ColumnStore/spider CASE_SIMPLE_FUNC // Used by ColumnStore/spider
}; };
......
...@@ -91,6 +91,7 @@ class Item_func_json_valid: public Item_bool_func ...@@ -91,6 +91,7 @@ class Item_func_json_valid: public Item_bool_func
} }
Item *get_copy(THD *thd) Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_json_valid>(thd, this); } { return get_item_copy<Item_func_json_valid>(thd, this); }
enum Functype functype() const { return JSON_VALID_FUNC; }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment