summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2020-06-15 23:21:29 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2020-06-15 23:21:29 +0400
commite290e5a75d0c2b12133c2ed118e3bc9bd26a266d (patch)
treeb78ba5f70ad319cffe8b61f1824bacfe892c5659
parent6c573a9146caa76807db1190e0747f5befb5b170 (diff)
downloadmariadb-git-e290e5a75d0c2b12133c2ed118e3bc9bd26a266d.tar.gz
MDEV-22837 JSON_ARRAYAGG and JSON_OBJECTAGG treat JSON arguments as text.
Item_field::is_json_value() implemented.
-rw-r--r--mysql-test/main/func_json.result7
-rw-r--r--mysql-test/main/func_json.test6
-rw-r--r--sql/item.cc11
-rw-r--r--sql/item.h1
-rw-r--r--sql/item_func.h2
-rw-r--r--sql/item_jsonfunc.h1
6 files changed, 27 insertions, 1 deletions
diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result
index 1151d9761ea..b3d7a1d2ed1 100644
--- a/mysql-test/main/func_json.result
+++ b/mysql-test/main/func_json.result
@@ -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
#
diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test
index 1c6c940af0c..531f6cd758d 100644
--- a/mysql-test/main/func_json.test
+++ b/mysql-test/main/func_json.test
@@ -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 #
diff --git a/sql/item.cc b/sql/item.cc
index 6ec4fdc6546..9b321103e07 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -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
diff --git a/sql/item.h b/sql/item.h
index 7a16ed02c6b..8118b079ca1 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -3389,6 +3389,7 @@ public:
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()
{
diff --git a/sql/item_func.h b/sql/item_func.h
index cd49496eb23..4922d20bd0c 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -76,7 +76,7 @@ public:
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
};
diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h
index eb9a0b1187d..0408b3ad72f 100644
--- a/sql/item_jsonfunc.h
+++ b/sql/item_jsonfunc.h
@@ -91,6 +91,7 @@ public:
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_json_valid>(thd, this); }
+ enum Functype functype() const { return JSON_VALID_FUNC; }
};