Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(expr): add jsonb_object function #13036

Merged
merged 5 commits into from
Oct 27, 2023
Merged

feat(expr): add jsonb_object function #13036

merged 5 commits into from
Oct 27, 2023

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented Oct 24, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

As title.
Due to the bug in parsing array literals, some test cases are not enabled.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

Support the following functions:

jsonb_object ( text[] ) → jsonb
# Builds a JSON object out of a text array. The array must have exactly one dimension with an even number of members, in which case they are taken as alternating key/value pairs. All values are converted to JSON strings.
Example: jsonb_object('{a, 1, b, def, c, 3.5}') → {"a" : "1", "b" : "def", "c" : "3.5"}

jsonb_object ( text[][] ) → jsonb
# Builds a JSON object out of a text array. The array must have two dimensions such that each inner array has exactly two elements, which are taken as a key/value pair. All values are converted to JSON strings.
Example: jsonb_object('{{a, 1}, {b, def}, {c, 3.5}}') → {"a" : "1", "b" : "def", "c" : "3.5"}

jsonb_object ( keys text[], values text[] ) → jsonb
# This form of jsonb_object takes keys and values pairwise from separate text arrays. Otherwise it is identical to the one-argument form.
Example: jsonb_object('{a,b}', '{1,2}') → {"a": "1", "b": "2"}

Reference: https://www.postgresql.org/docs/16/functions-json.html#FUNCTIONS-JSON-CREATION-TABLE

@wangrunji0408 wangrunji0408 force-pushed the wrj/jsonb-functions branch 2 times, most recently from b02635c to 12b1d30 Compare October 25, 2023 05:48
Base automatically changed from wrj/flat-json to main October 25, 2023 09:08
@buildkite buildkite bot requested a review from a team as a code owner October 25, 2023 09:08
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 removed the request for review from a team October 25, 2023 09:35
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@codecov
Copy link

codecov bot commented Oct 25, 2023

Codecov Report

Merging #13036 (c6a98a4) into main (31d6dc0) will decrease coverage by 0.02%.
Report is 1 commits behind head on main.
The diff coverage is 1.31%.

@@            Coverage Diff             @@
##             main   #13036      +/-   ##
==========================================
- Coverage   68.26%   68.24%   -0.02%     
==========================================
  Files        1498     1499       +1     
  Lines      252574   252650      +76     
==========================================
+ Hits       172411   172421      +10     
- Misses      80163    80229      +66     
Flag Coverage Δ
rust 68.24% <1.31%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/frontend/src/binder/expr/function.rs 78.54% <100.00%> (+0.01%) ⬆️
src/frontend/src/expr/pure.rs 87.69% <ø> (ø)
src/expr/impl/src/scalar/jsonb_object.rs 0.00% <0.00%> (ø)

... and 9 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest lgtm

src/expr/impl/src/scalar/jsonb_object.rs Outdated Show resolved Hide resolved
@wangrunji0408 wangrunji0408 mentioned this pull request Oct 27, 2023
23 tasks
@wangrunji0408
Copy link
Contributor Author

@xiangjinwu By the way, do we plan to be consistent with postgres on array types? i.e. ignore multi-dimensions in the type declaration. In postgres, both one dimension and two dimension input share the same signature jsonb_object ( text[] ) → jsonb.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@xiangjinwu
Copy link
Contributor

@xiangjinwu By the way, do we plan to be consistent with postgres on array types? i.e. ignore multi-dimensions in the type declaration. In postgres, both one dimension and two dimension input share the same signature jsonb_object ( text[] ) → jsonb.

#3811 (comment)

No. And in this case, separating {a,b,c,d,e,f} from {{a,b},{c,d},{e,f}} is clearer.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 added this pull request to the merge queue Oct 27, 2023
Merged via the queue into main with commit 72d9765 Oct 27, 2023
8 of 9 checks passed
@wangrunji0408 wangrunji0408 deleted the wrj/jsonb-functions branch October 27, 2023 10:31
@neverchanje
Copy link
Contributor

@wangrunji0408 This function lacks the sqllogictests.

@BugenZhao
Copy link
Member

@wangrunji0408 This function lacks the sqllogictests.

#5246

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants