-
Notifications
You must be signed in to change notification settings - Fork 564
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 table functions #9977
Conversation
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>
ec25dd6
to
a9b8f3c
Compare
e2e_test/batch/types/jsonb.slt.part
Outdated
query T | ||
select jsonb_each('{"a":"foo", "b":"bar"}'::jsonb); | ||
---- | ||
(a,"""foo""") | ||
(b,"""bar""") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a problem in string formatting in struct. cc @xiangjinwu
[Diff] (-expected|+actual)
- (a,"""foo""")
- (b,"""bar""")
+ (a,"foo")
+ (b,"bar")
The quote "
is escaped to \"
in array, but ""
in record.
postgres=# select row(1, '"str"');
row
---------------
(1,"""str""")
postgres=# select array['"str"'];
array
-------------
{"\"str\""}
Is there any documents for this behavior? How should we handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is buggy right now: #4769
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is buggy right now: #4967
Seems not related. Wrong issue number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. Updated to #4769
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Then I'd like to change the test result to fit the current format and leave this issue for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that works. Alternatively, we can write the tests without relying on the display of struct:
select (st).key, (st).value from (select jsonb_each('{"a":"foo", "b":"bar"}'::jsonb)) as t(st);
----
a "foo"
b "bar"
Codecov Report
@@ Coverage Diff @@
## main #9977 +/- ##
==========================================
- Coverage 70.93% 70.91% -0.03%
==========================================
Files 1233 1234 +1
Lines 210884 210990 +106
==========================================
+ Hits 149600 149625 +25
- Misses 61284 61365 +81
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM!
/// To make sure there is `as_scalar_ref` for all scalar ref types. | ||
pub trait SelfAsScalarRef { | ||
fn as_scalar_ref(&self) -> Self; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose is to allow both owned type and reference type as function return value. (e.g. -> &str
and -> Box<str>
). So we want both types have a method .as_scalar_ref() -> &str
so that we can call it to convert owned type into reference and keep reference type unchanged in the macro. Currently this method exists in the Scalar
trait. At first I added this method to the ScalarRef
trait, but it leads to conflicts for those types that share both traits (e.g. primitive types: i32, i64...). Therefore I created this trait to add as_scalar_ref
for types which impl ScalarRef
but not impl Scalar
. Maybe a better solution is to extract an AsScalarRef
trait. But it's too hard for me to do type exercise. 🤪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s == "record" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What format is the str
in? Is it SQL representation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is almost auto-generated by Copilot from the above Display code. 😄
Signed-off-by: Runji Wang <wangrunji0408@163.com> Co-authored-by: xxchan <xxchan22f@gmail.com>
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Based on #9949, this PR adds the following jsonb table functions:
Checklist For Contributors
#[function]
macro #10010)./risedev check
(or alias,./risedev c
)Checklist For Reviewers
Documentation
Click here for Documentation
Types of user-facing changes
Please keep the types that apply to your changes, and remove the others.
Release note
Add jsonb table functions:
https://www.postgresql.org/docs/15/functions-json.html