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(udf): support JSONB in UDF #9103

Merged
merged 12 commits into from
Apr 12, 2023
Merged

feat(udf): support JSONB in UDF #9103

merged 12 commits into from
Apr 12, 2023

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented Apr 11, 2023

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

What's changed and what's your intention?

This PR adds support for using JSONB type as a parameter and return value in UDFs. resolves #8801

Example:

@udf(input_types=['JSONB[]'], result_type='JSONB')
def jsonb_concat(list: List[Any]) -> Any:
    return list
dev=> select jsonb_concat(ARRAY['null', '1', '"str"', '{}'] :: jsonb[]);
     jsonb_concat     
----------------------
 [null, 1, "str", {}]

As Arrow doesn't support JSONB type, we have chosen to use LargeUtf8 to represent JSONB on the Arrow side. A JSONB value is transmitted as a string in Arrow LargeStringArray. The Python SDK decodes the string into Python object and passes it into user functions. When returning a JSONB value, the SDK encodes the Python object into a string and then the CN parses it back to a JsonbVal. It's worth noting that parsing the string may raise an error if it is an invalid json. So this PR changes the conversion from Arrow Array to Risingwave Array to be fallible.

Checklist For Contributors

  • 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).
  • I have demonstrated that backward compatibility is not broken by breaking changes and created issues to track deprecated features to be removed in the future. (Please refer to the issue)
  • All checks passed in ./risedev check (or alias, ./risedev c)

Checklist For Reviewers

  • I have requested macro/micro-benchmarks as this PR can affect performance substantially, and the results are shown.

Documentation

Click here for Documentation

Types of user-facing changes

  • SQL commands, functions, and operators

Release note

Support JSONB type in UDFs.

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>
@github-actions github-actions bot added type/feature user-facing-changes Contains changes that are visible to users labels Apr 11, 2023
@codecov
Copy link

codecov bot commented Apr 11, 2023

Codecov Report

Merging #9103 (ed80890) into main (99b39c2) will increase coverage by 0.03%.
The diff coverage is 72.94%.

@@            Coverage Diff             @@
##             main    #9103      +/-   ##
==========================================
+ Coverage   70.85%   70.88%   +0.03%     
==========================================
  Files        1198     1198              
  Lines      199577   199628      +51     
==========================================
+ Hits       141405   141512     +107     
+ Misses      58172    58116      -56     
Flag Coverage Δ
rust 70.88% <72.94%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/common/src/array/error.rs 0.00% <0.00%> (ø)
src/common/src/lib.rs 100.00% <ø> (ø)
src/expr/src/expr/expr_udf.rs 0.00% <0.00%> (ø)
src/expr/src/table_function/user_defined.rs 0.00% <0.00%> (ø)
src/common/src/array/jsonb_array.rs 44.76% <66.66%> (+19.44%) ⬆️
src/common/src/array/arrow.rs 66.11% <77.46%> (+2.44%) ⬆️
src/sqlparser/src/parser.rs 87.78% <100.00%> (ø)

... and 5 files with indirect coverage changes

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

src/sqlparser/src/parser.rs Show resolved Hide resolved
src/common/src/array/jsonb_array.rs Outdated Show resolved Hide resolved
src/common/src/array/arrow.rs Show resolved Hide resolved
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>
@wangrunji0408 wangrunji0408 enabled auto-merge April 12, 2023 10:03
@wangrunji0408 wangrunji0408 added this pull request to the merge queue Apr 12, 2023
Merged via the queue into main with commit 264cdd7 Apr 12, 2023
@wangrunji0408 wangrunji0408 deleted the wrj/udf-jsonb branch April 12, 2023 10:34
@CharlieSYH CharlieSYH added the 📖✓ Covered or will be covered in the user docs. label Apr 19, 2023
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 📖✓ Covered or will be covered in the user docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

udf: support jsonb type
4 participants