-
Notifications
You must be signed in to change notification settings - Fork 570
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(sink): support encode jsonb data as dynamic json type in sink #17693
Conversation
CustomJsonType::None => match config.encode_jsonb_mode { | ||
EncodeJsonbMode::String => { | ||
json!(jsonb_ref.to_string()) |
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.
Core logic
let encode_jsonb_obj_config = JsonEncoderConfig { | ||
time_handling_mode: TimeHandlingMode::Milli, | ||
date_handling_mode: DateHandlingMode::String, | ||
timestamp_handling_mode: TimestampHandlingMode::String, | ||
timestamptz_handling_mode: TimestamptzHandlingMode::UtcString, |
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.
Some test
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.
Can we move this refactor to its own PR?
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.
Sure
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.
stacked on #17706
/// How the jsonb type is encoded. | ||
/// | ||
/// - `string`: encode jsonb as string. `[1, true, "foo"] -> "[1, true, \"foo\"]"` | ||
/// - `object`: encode jsonb as json object. `[1, true, "foo"] -> [1, true, "foo"]` |
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.
This is not accurate. [1, true, "foo"]
is a json array rather than a json object. This is why the original issue calls it dynamic type: it may be one of json null
/ boolean
/ number
/ string
/ array
/ object
.
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.
So rename it to dynamic?
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
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.
Okay. I use object
bc the function name is datum_to_json_object()
`
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.
Because the top level json returned by this function is always an object containing multiple fields, corresponding to a table row containing multiple columns.
We didn't have timestamptz.handling.mode or |
|
f3e7d61
to
95a153c
Compare
Currently it uses default behavior that is encode jsonb as string. It's my understanding users usually create a table with 1 column to store raw data from json file. And create more tables from the source table. It makes more sense to encode RW as dynamic json type. But snowflake user can handle string by
We can do this later. |
I don't think there is any type mapping setup for every column is by default handled/interpreted at |
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.
Rest LGTM. Thank you!
@@ -628,11 +639,12 @@ mod tests { | |||
assert_eq!(date_value, json!(719163)); | |||
|
|||
let from_epoch_config = JsonEncoderConfig { | |||
time_handling_mode: TimeHandlingMode::Milli, | |||
time_handling_mode: TimeHandlingMode::String, |
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.
Irrelevant change?
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.
Ah some merge issue. But this test is for date_handling_mode
sotime_handling_mode
won't matter.
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
close #11699
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Add a option for
ENCODE JSON
inWITH
clause .jsonb.handling.mode
can be set to eitherstring
ordynamic
string
: encode thejsonb
type as a string. example:{"k": 2} -> "{\"k\": 2}"
. Here a json objectjsonb
was encoded to a string.dynamic
: dynamically encode thejsonb
type as json type. example:{"k": 2} -> {"k": 2}
. Here a json objectjsonb
was encoded to a json object.Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.