diff options
author | Markus Mäkelä <markus456@gmail.com> | 2019-07-04 13:12:08 +0300 |
---|---|---|
committer | Markus Mäkelä <markus456@gmail.com> | 2019-07-04 13:12:08 +0300 |
commit | d0fc07c85f1b01291c78a9ea42525d57df7b66b7 (patch) | |
tree | fdfd6704c3b68b2a4986e5b365698cdde81562b0 /sql/item_sum.h | |
parent | 4d6a90942c231a5a6628fe8e0b9bd9e8d4509d26 (diff) | |
download | mariadb-git-d0fc07c85f1b01291c78a9ea42525d57df7b66b7.tar.gz |
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.
Diffstat (limited to 'sql/item_sum.h')
-rw-r--r-- | sql/item_sum.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/sql/item_sum.h b/sql/item_sum.h index dbcb617ce51..1f8195f2eb4 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -355,7 +355,7 @@ 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 + PERCENTILE_DISC_FUNC, SP_AGGREGATE_FUNC, JSON_ARRAYAGG_FUNC }; Item **ref_by; /* pointer to a ref to the object used to register it */ @@ -428,6 +428,7 @@ public: case SUM_BIT_FUNC: case UDF_SUM_FUNC: case GROUP_CONCAT_FUNC: + case JSON_ARRAYAGG_FUNC: return true; default: return false; @@ -1794,6 +1795,7 @@ C_MODE_END class Item_func_group_concat : public Item_sum { +protected: TMP_TABLE_PARAM *tmp_table_param; String result; String *separator; @@ -1839,6 +1841,12 @@ class Item_func_group_concat : public Item_sum */ Item_func_group_concat *original; + /* + Used by Item_func_group_concat and Item_func_json_arrayagg. The latter + needs null values but the former doesn't. + */ + bool add(bool exclude_nulls); + friend int group_concat_key_cmp_with_distinct(void* arg, const void* key1, const void* key2); friend int group_concat_key_cmp_with_order(void* arg, const void* key1, @@ -1876,7 +1884,10 @@ public: return &type_handler_varchar; } void clear(); - bool add(); + bool add() + { + return add(true); + } void reset_field() { DBUG_ASSERT(0); } // not used void update_field() { DBUG_ASSERT(0); } // not used bool fix_fields(THD *,Item **); |