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): support jsonb - and #- operator #13118

Merged
merged 6 commits into from
Oct 30, 2023
Merged

Conversation

wangrunji0408
Copy link
Contributor

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

What's changed and what's your intention?

Add the following functions:

jsonb - text → jsonb
jsonb - text[] → jsonb
jsonb - integer → jsonb
jsonb #- text[] → jsonb

we reuse the Subtract expr type for the - operator.

This PR also bumps jsonbb version for a new API contains_key.

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)

Support the following operators:

jsonb - text → jsonb
Deletes a key (and its value) from a JSON object, or matching string value(s) from a JSON array.
'{"a": "b", "c": "d"}'::jsonb - 'a' → {"c": "d"}
'["a", "b", "c", "b"]'::jsonb - 'b' → ["a", "c"]

jsonb - text[] → jsonb
Deletes all matching keys or array elements from the left operand.
'{"a": "b", "c": "d"}'::jsonb - '{a,c}'::text[] → {}

jsonb - integer → jsonb
Deletes the array element with specified index (negative integers count from the end). Throws an error if JSON value is not an array.
'["a", "b"]'::jsonb - 1 → ["a"]

jsonb #- text[] → jsonb
Deletes the field or array element at the specified path, where path elements can be either field keys or array indexes.
'["a", {"b":1}]'::jsonb #- '{1,b}' → ["a", {}]

@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Merging #13118 (d9f1758) into main (e392db0) will increase coverage by 0.02%.
The diff coverage is 1.19%.

@@            Coverage Diff             @@
##             main   #13118      +/-   ##
==========================================
+ Coverage   68.24%   68.27%   +0.02%     
==========================================
  Files        1500     1501       +1     
  Lines      252692   252860     +168     
==========================================
+ Hits       172448   172637     +189     
+ Misses      80244    80223      -21     
Flag Coverage Δ
rust 68.27% <1.19%> (+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.67% <100.00%> (+0.03%) ⬆️
src/frontend/src/expr/pure.rs 87.69% <ø> (ø)
src/frontend/src/binder/expr/binary_op.rs 69.69% <0.00%> (-0.72%) ⬇️
src/sqlparser/src/ast/operator.rs 83.78% <0.00%> (-1.15%) ⬇️
src/sqlparser/src/parser.rs 87.36% <0.00%> (-0.03%) ⬇️
src/sqlparser/src/tokenizer.rs 92.52% <0.00%> (-0.16%) ⬇️
src/common/src/types/jsonb.rs 33.69% <0.00%> (-0.50%) ⬇️
src/expr/impl/src/scalar/jsonb_delete.rs 0.00% <0.00%> (ø)

... and 20 files with indirect coverage changes

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

@wangrunji0408 wangrunji0408 mentioned this pull request Oct 30, 2023
23 tasks
src/expr/impl/src/scalar/jsonb_remove.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/jsonb_remove.rs Outdated Show resolved Hide resolved
@wangrunji0408 wangrunji0408 added this pull request to the merge queue Oct 30, 2023
Merged via the queue into main with commit c0ab3ca Oct 30, 2023
9 of 10 checks passed
@wangrunji0408 wangrunji0408 deleted the wrj/jsonb-remove branch October 30, 2023 10:21
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.

3 participants