diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 716ae78a35c..cc87a935a85 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1221,3 +1221,14 @@ SELECT JSON_ARRAYAGG(a) FROM t1; JSON_ARRAYAGG(a) NULL DROP TABLE t1; +# +# MDEV-21915 Server crashes in copy_fields,Item_func_group_concat::add +while using json_arrayagg() as a window function +# +select json_arrayagg(a) over () from (select 1 a) t; +ERROR 42000: This version of MariaDB doesn't yet support 'JSON_ARRAYAGG() aggregate as window function' +select json_objectagg(a, b) over () from (select 1 a, 2 b) t; +ERROR 42000: This version of MariaDB doesn't yet support 'JSON_OBJECTAGG() aggregate as window function' +# +# End of 10.5 tests +# diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index 2c5dbfbd42c..216d51b4c36 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -740,3 +740,19 @@ DROP TABLE t1; CREATE TABLE t1 (a INT); SELECT JSON_ARRAYAGG(a) FROM t1; DROP TABLE t1; + +-- echo # +-- echo # MDEV-21915 Server crashes in copy_fields,Item_func_group_concat::add +-- echo while using json_arrayagg() as a window function +-- echo # + +--error ER_NOT_SUPPORTED_YET +select json_arrayagg(a) over () from (select 1 a) t; + +--error ER_NOT_SUPPORTED_YET +select json_objectagg(a, b) over () from (select 1 a, 2 b) t; + +--echo # +--echo # End of 10.5 tests +--echo # + diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h index 44f9e8146c2..f1afaf6cc31 100644 --- a/sql/item_jsonfunc.h +++ b/sql/item_jsonfunc.h @@ -579,7 +579,7 @@ public: bool is_json_type() { return true; } void cleanup(); - enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;} + enum Sumfunctype sum_func () const {return JSON_OBJECTAGG_FUNC;} const char *func_name() const { return "json_objectagg("; } const Type_handler *type_handler() const { diff --git a/sql/item_sum.h b/sql/item_sum.h index e221d04397d..77d1809d7bf 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -355,7 +355,8 @@ public: ROW_NUMBER_FUNC, RANK_FUNC, DENSE_RANK_FUNC, PERCENT_RANK_FUNC, CUME_DIST_FUNC, NTILE_FUNC, FIRST_VALUE_FUNC, LAST_VALUE_FUNC, NTH_VALUE_FUNC, LEAD_FUNC, LAG_FUNC, PERCENTILE_CONT_FUNC, - PERCENTILE_DISC_FUNC, SP_AGGREGATE_FUNC, JSON_ARRAYAGG_FUNC + PERCENTILE_DISC_FUNC, SP_AGGREGATE_FUNC, JSON_ARRAYAGG_FUNC, + JSON_OBJECTAGG_FUNC }; Item **ref_by; /* pointer to a ref to the object used to register it */ diff --git a/sql/sql_window.cc b/sql/sql_window.cc index a9a1dccf9f6..9e6ef6468e0 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -2936,6 +2936,14 @@ bool Window_func_runner::add_function_to_run(Item_window_func *win_func) my_error(ER_NOT_SUPPORTED_YET, MYF(0), "COUNT(DISTINCT) aggregate as window function"); return true; + case Item_sum::JSON_ARRAYAGG_FUNC: + my_error(ER_NOT_SUPPORTED_YET, MYF(0), + "JSON_ARRAYAGG() aggregate as window function"); + return true; + case Item_sum::JSON_OBJECTAGG_FUNC: + my_error(ER_NOT_SUPPORTED_YET, MYF(0), + "JSON_OBJECTAGG() aggregate as window function"); + return true; default: break; }