feat: json_merge expression and sql function
Description
This add a new json_merge expression which takes two or more arguments to merge into a single json structure. It also added the corresponding SQL function. This is useful for transforming data in druid, for instance I use it for flattening arrays of objects using fold, e.g. fold((a, acc) -> json_merge(acc, json_object(json_value(a, '$.key'), json_value(a, '$.value'))), arrayofkv, json_object())
Fixed the bug ...
Renamed the class ...
Added a forbidden-apis entry ...
Release note
Key changed/added classes in this PR
-
json_mergeexpression function -
json_mergesql function
This PR has:
- [x] been self-reviewed.
- [ ] using the concurrency checklist (Remove this item if the PR doesn't have any relation to concurrency.)
- [x] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in licenses.yaml
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
- [ ] added integration tests.
- [x] been tested in a test Druid cluster.
btw have you looked at https://github.com/apache/druid/pull/15521 (flatting arrays of objects using UNNEST and JSON_QUERY_ARRAY) ?
btw have you looked at #15521 (flatting arrays of objects using UNNEST and JSON_QUERY_ARRAY) ?
That looks great, but it's the other way I'm going. Using that example I would end up with {"Honda":"civic","Toyota":"prius"....} and all type and weight being overwritten by the right-most value. It's a specific use-case alright, but json_merge has many other applications of course.
You are right. This function has broader usage. I think when you say "arrays of objects", you don't mean arrays in a single record but rather multiple records. Since fold is an aggregator.
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.
This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.
I've rebased this so we can revive now
@lkm - are you going to revive this PR?
@abhishekagarwal87 I don't think I have the permissions to do that. I been running this in prod for a while and happy with the functionality
You might have to open a separate PR since I can't figure out a way to re-open it myself.
FWIW the PR looks good to me in the current shape so we should be able to merge your PR pretty quick.
Thanks. I've created a new one here: https://github.com/apache/druid/pull/17081