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 #13056

Merged
merged 12 commits into from
Oct 30, 2023

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?

As title.

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 jsonb operators:

jsonb @> jsonb → boolean
Does the first JSON value contain the second? (See [Section 8.14.3](https://www.postgresql.org/docs/current/datatype-json.html#JSON-CONTAINMENT) for details about containment.)
'{"a":1, "b":2}'::jsonb @> '{"b":2}'::jsonb → t

jsonb <@ jsonb → boolean
Is the first JSON value contained in the second?
'{"b":2}'::jsonb <@ '{"a":1, "b":2}'::jsonb → t

jsonb ? text → boolean
Does the text string exist as a top-level key or array element within the JSON value?
'{"a":1, "b":2}'::jsonb ? 'b' → t
'["a", "b", "c"]'::jsonb ? 'b' → t

jsonb ?| text[] → boolean
Do any of the strings in the text array exist as top-level keys or array elements?
'{"a":1, "b":2, "c":3}'::jsonb ?| array['b', 'd'] → t

jsonb ?& text[] → boolean
Do all of the strings in the text array exist as top-level keys or array elements?
'["a", "b", "c"]'::jsonb ?& array['a', 'b'] → t

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

codecov bot commented Oct 25, 2023

Codecov Report

Merging #13056 (403dcc9) into main (9a5e2b8) will decrease coverage by 0.03%.
The diff coverage is 9.89%.

@@            Coverage Diff             @@
##             main   #13056      +/-   ##
==========================================
- Coverage   68.27%   68.25%   -0.03%     
==========================================
  Files        1499     1500       +1     
  Lines      252602   252691      +89     
==========================================
+ Hits       172459   172467       +8     
- Misses      80143    80224      +81     
Flag Coverage Δ
rust 68.25% <9.89%> (-0.03%) ⬇️

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.63% <100.00%> (+0.09%) ⬆️
src/frontend/src/expr/pure.rs 87.69% <ø> (ø)
src/frontend/src/binder/expr/binary_op.rs 71.87% <0.00%> (-3.95%) ⬇️
src/sqlparser/src/ast/operator.rs 84.93% <0.00%> (-6.25%) ⬇️
src/sqlparser/src/parser.rs 87.39% <16.66%> (-0.14%) ⬇️
src/sqlparser/src/tokenizer.rs 92.67% <20.00%> (-0.94%) ⬇️
src/expr/impl/src/scalar/jsonb_contains.rs 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes

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

@@ -164,6 +164,16 @@ pub enum Token {
HashArrow,
/// `#>>`, extract JSON sub-object at the specified path as text in PostgreSQL
HashLongArrow,
/// `@>`, does the left JSON value contain the right JSON path/value entries at the top level
Copy link
Contributor

Choose a reason for hiding this comment

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

Just fyi since you may be interested:

To align with PostgreSQL user-defined operator, these builtin pg-specific operators can also be refactored to be recognized in binder with a lookup table (pg_operator). so that there is no need to modified tokenizer + parser for each operator. The tokenizing rule is actually this.

It seems to be an overkill right now, so I am not giving it a high priority.

src/expr/impl/src/scalar/jsonb_contains.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/jsonb_contains.rs Outdated Show resolved Hide resolved
src/expr/impl/src/scalar/jsonb_contains.rs Outdated Show resolved Hide resolved
@wangrunji0408 wangrunji0408 mentioned this pull request Oct 27, 2023
23 tasks
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@gitguardian
Copy link

gitguardian bot commented Oct 30, 2023

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
7648795 Generic CLI Secret 5b164e8 integration_tests/iceberg-cdc/docker-compose.yml View secret
7648795 Generic CLI Secret 5b164e8 integration_tests/iceberg-cdc/run_test.sh View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
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