-
Notifications
You must be signed in to change notification settings - Fork 633
feat(expr): implement array_flatten
#21640
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
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Pull Request Overview
This PR implements an array_flatten function for RisingWave, adding native support for flattening one level of nesting in arrays. The key changes include:
- Updating optimizer and expression visitors to handle ARRAY_FLATTEN.
- Adding a new builtin scalar function in the binder for array_flatten.
- Implementing the array_flatten logic in a new scalar module and updating type handling and proto definitions accordingly.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/frontend/src/optimizer/plan_expr_visitor/strong.rs | Added ARRAY_FLATTEN support in the strong visitor. |
src/frontend/src/expr/pure.rs | Added ARRAY_FLATTEN into the impure analyzer’s type list. |
src/frontend/src/binder/expr/function/builtin_scalar.rs | Introduced the array_flatten function with appropriate type checks and error messages. |
src/expr/impl/src/scalar/mod.rs | Included the new array_flatten module. |
src/expr/impl/src/scalar/array_flatten.rs | New implementation for array_flatten following Snowflake/DuckDB behavior. |
src/common/src/types/mod.rs | Added a new conversion method into_list_element_type for type consistency. |
proto/expr.proto | Extended the enum to include ARRAY_FLATTEN. |
Comments suppressed due to low confidence (1)
src/common/src/types/mod.rs:513
- Consider renaming the 'as_list' method or updating its usage so that the naming is consistent with 'into_list_element_type' elsewhere in the code, which would improve clarity for the list element extraction methods.
/// TODO(rc): rename to `as_list_element_type`
Hi, there. 📝 Telemetry Reminder:
|
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.
LGTM
/// | ||
/// ```slt | ||
/// query T | ||
/// select array_flatten(array[array[1, 2], array[3, 4]]); |
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.
Just realized array_flatten(arr)
is equivalent to genuine_array_concat(VARIADIC arr)
. However:
- This hypothetical
genuine_array_concat
is different from PostgreSQL/RisingWavearray_cat
, which has a wired behavior on >= 2d array due to its weak array typing (int[][]
is same asint[]
) - #14753 implements
VARIADIC
as separate exprs but in PostgreSQL there is a singleconcat_ws
/jsonb_extract_path
Just sharing some related ideas. Nothing to change in this PR.
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Signed-off-by: Richard Chien <[email protected]>
Many query engines/databases have builtin function
array_flatten
orflatten
to flatten an array of arrays. And it is also requested by our user. This PR adds it for RisingWave.For the sake of simplicity and clarity, we implement this function following Snowflake, Trino, DuckDB, which means, this function works in a non-recursive way, only flattening one level of nesting.
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
Checklist
Documentation
Release note