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_build_array/object function #13198

Merged
merged 9 commits into from
Nov 6, 2023

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented Nov 1, 2023

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

What's changed and what's your intention?

resolve #13016

This PR implements jsonb_build_array and jsonb_build_object function. But the VARIADIC keyword before arguments are not supported.

This PR also adds more data type support for jsonb_agg and jsonb_object_agg.

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)

Add jsonb_build_array and jsonb_build_object function:

jsonb_build_array ( VARIADIC "any" ) → jsonb
Builds a possibly-heterogeneously-typed JSON array out of a variadic argument list. Each argument is converted as per to_jsonb.
jsonb_build_array(1, 2, 'foo', 4, 5) → [1, 2, "foo", 4, 5]

jsonb_build_object ( VARIADIC "any" ) → jsonb
Builds a JSON object out of a variadic argument list. By convention, the argument list consists of alternating keys and values. Key arguments are coerced to text; value arguments are converted as per to_jsonb.
jsonb_build_object('foo', 1, 2, row(3,'bar')) → {"foo" : 1, "2" : {"f1":3,"f2":"bar"}}

Limitation: calling with VARIADIC keyword is not supported yet. e.g.

jsonb_build_array(VARIADIC array[1, 2] :: int[]) 
jsonb_build_object(VARIADIC array[1, 2] :: varchar[]) 
  • jsonb_agg now accept any type except array and struct.
  • jsonb_object_agg now accept any type except array and struct as value. keys are still limited to varchar.

@wangrunji0408 wangrunji0408 marked this pull request as draft November 1, 2023 09:37
@wangrunji0408 wangrunji0408 force-pushed the wrj/build-jsonb-array-object branch from cb35a8e to be0679f Compare November 3, 2023 09:55
@wangrunji0408 wangrunji0408 changed the title feat(expr): partially support jsonb_build_array/object function feat(expr): add jsonb_build_array/object function Nov 3, 2023
@wangrunji0408 wangrunji0408 marked this pull request as ready for review November 3, 2023 10:08
Copy link
Contributor

@KeXiangWang KeXiangWang left a comment

Choose a reason for hiding this comment

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

Great refactoring. Thanks!

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/frontend/src/expr/type_inference/func.rs Outdated Show resolved Hide resolved
src/expr/impl/src/aggregate/jsonb_agg.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/jsonb_build.rs Show resolved Hide resolved
Signed-off-by: Runji Wang <[email protected]>
@wangrunji0408 wangrunji0408 added this pull request to the merge queue Nov 6, 2023
Copy link

codecov bot commented Nov 6, 2023

Codecov Report

Merging #13198 (94648b6) into main (fff5de4) will decrease coverage by 0.01%.
Report is 18 commits behind head on main.
The diff coverage is 1.17%.

@@            Coverage Diff             @@
##             main   #13198      +/-   ##
==========================================
- Coverage   68.11%   68.10%   -0.01%     
==========================================
  Files        1517     1518       +1     
  Lines      257380   257405      +25     
==========================================
  Hits       175302   175302              
- Misses      82078    82103      +25     
Flag Coverage Δ
rust 68.10% <1.17%> (-0.01%) ⬇️

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.33% <100.00%> (+0.03%) ⬆️
src/frontend/src/expr/pure.rs 87.69% <ø> (ø)
src/frontend/src/expr/type_inference/func.rs 84.71% <0.00%> (-0.86%) ⬇️
src/expr/impl/src/aggregate/jsonb_agg.rs 0.00% <0.00%> (ø)
src/expr/impl/src/scalar/jsonb_build.rs 0.00% <0.00%> (ø)
src/expr/impl/src/scalar/to_jsonb.rs 0.00% <0.00%> (ø)

... and 6 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 6, 2023
@wangrunji0408 wangrunji0408 added this pull request to the merge queue Nov 6, 2023
Merged via the queue into main with commit 526a68a Nov 6, 2023
8 of 9 checks passed
@wangrunji0408 wangrunji0408 deleted the wrj/build-jsonb-array-object branch November 6, 2023 10:08
@fuyufjh fuyufjh added the user-facing-changes Contains changes that are visible to users label Nov 17, 2023
@fuyufjh
Copy link
Member

fuyufjh commented Nov 17, 2023

Being asked by a user today. Please remember to tag as user-facing.

@wangrunji0408
Copy link
Contributor Author

wangrunji0408 commented Nov 17, 2023

Thanks for reminding. I didn't click the checkbox of documentation initially, but clicked it later by editing. Looks like it didn't trigger the bot to automatically add the tag. (

@fuyufjh

This comment was marked as off-topic.

@fuyufjh
Copy link
Member

fuyufjh commented Nov 20, 2023

Sorry my fault. @wangrunji0408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support jsonb_build_array / jsonb_build_object
4 participants