Added basic framework for json_merge_aggr #17339
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #17284
Description
This PR adds a new function JSON_MERGE_AGGR(,<JSON 1>, <JSON 2> .... ) which performs the aggregation when the leaf elements have the same key.
Currently only two aggregators are added - ADD & MULTIPLY
For Array, it retains the functionality of JSON_MERGE function.
Example
JSON_MERGE_AGGR('ADD', {"key": 2}, {"key":3}) -> {"key":5}
JSON_MERGE_AGGR('MULTIPLY', {"key": {"k2": 2}}, {"key":{"k2":3}}) -> {"key":{"k2":6}}
Retained JSON_MERGE functionality
JSON_MERGE_AGGR('ADD', {"key": [1,2,3]}, {"key":[4,5]}) -> {"key":[1,2,3,4,5]}
JSON_MERGE_AGGR('ADD', {"key": [1,2]}, {"key":3}) -> {"key":3}
JSON_MERGE_AGGR('ADD', [1,2,3], [4,5]) -> [1,2,3,4,5]
Key changed/added classes in this PR
json_merge_aggr
expression functionjson_merge_aggr
sql functionThis PR has: