Skip to content

Commit

Permalink
MDEV-22837 JSON_ARRAYAGG and JSON_OBJECTAGG treat JSON arguments as t…
Browse files Browse the repository at this point in the history
…ext.

Item_field::is_json_value() implemented.
  • Loading branch information
Alexey Botchkov committed Jun 15, 2020
1 parent 6c573a9 commit e290e5a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions mysql-test/main/func_json.result
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,13 @@ Warnings:
Warning 1260 Row 1 was cut by JSON_ARRAYAGG()
drop table t1;
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
#
6 changes: 6 additions & 0 deletions mysql-test/main/func_json.test
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,12 @@ select json_arrayagg(a) from t1;
drop table t1;
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 # End of 10.5 tests
--echo #
Expand Down
11 changes: 11 additions & 0 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
field=result_field=field_par; // for easy coding with fields
Expand Down
1 change: 1 addition & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -3389,6 +3389,7 @@ class Item_field :public Item_ident,
my_decimal *val_decimal_result(my_decimal *);
bool val_bool_result();
bool is_null_result();
bool is_json_type();
bool send(Protocol *protocol, st_value *buffer);
Load_data_outvar *get_load_data_outvar()
{
Expand Down
2 changes: 1 addition & 1 deletion sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Item_func :public Item_func_or_sum,
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_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_SIMPLE_FUNC // Used by ColumnStore/spider
};
Expand Down
1 change: 1 addition & 0 deletions sql/item_jsonfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Item_func_json_valid: public Item_bool_func
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_json_valid>(thd, this); }
enum Functype functype() const { return JSON_VALID_FUNC; }
};


Expand Down

0 comments on commit e290e5a

Please sign in to comment.