1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

MDEV-16620: Add JSON_ARRAYAGG function

The JSON_ARRAYAGG function extends the GROUP_CONCAT function and provides
a method of aggregating JSON results. The current implementation supports
DISTINCT and LIMIT but not ORDER BY (Oracle supports GROUP BY).

Adding GROUP BY support is possible but it requires some extra work as the
grouping appears to be done inside a temporary table that complicates
matters.

Added test cases that covert aggregation of all JSON types and JSON
validation for the generated results.
This commit is contained in:
Markus Mäkelä
2019-07-04 13:12:08 +03:00
parent 4d6a90942c
commit d0fc07c85f
8 changed files with 354 additions and 5 deletions

View File

@@ -3621,3 +3621,25 @@ int Arg_comparator::compare_e_json_str_basic(Item *j, Item *s)
return MY_TEST(sortcmp(res1, res2, compare_collation()) == 0);
}
String* Item_func_json_arrayagg::convert_to_json(Item *item, String *res)
{
String tmp;
res->length(0);
append_json_value(res, item, &tmp);
return res;
}
String* Item_func_json_arrayagg::val_str(String *str)
{
str= Item_func_group_concat::val_str(str);
String s;
s.append('[');
s.swap(*str);
str->append(s);
str->append(']');
return str;
}