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

fix(expr): array_to_string should handle multidimensional array recursively #10469

Merged
merged 1 commit into from
Jul 3, 2023

Conversation

xiangjinwu
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?

Fixes #8680. See #3811 (comment) for rationale.

This is consistent with unnest and cardinality (and array_replace in the future).

Note the following (with ::text[] rather than ::text[][]) is still different from PostgreSQL:

select array_to_string(array[array['one', 'two'], array['three', 'four']]::text[], ',');

This is not related to the array_to_string function. In PostgreSQL, ::text[] still returns a 2d array with 4 elements, while we return a 1d array with 2 elements, first of which is a result of array['one', 'two']::text. This is intentional.

We do not guarantee backward compatibility of experimental multidimensional array.

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.)

Documentation

  • My PR contains user-facing changes.
Click here for Documentation

Types of user-facing changes

Please keep the types that apply to your changes, and remove the others.

  • Installation and deployment
  • Connector (sources & sinks)
  • SQL commands, functions, and operators
  • RisingWave cluster configuration changes
  • Other (please specify in the release note below)

Release note

Comment on lines +114 to +115
for element in array.flatten() {
let Some(element) = element else { continue };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old .iter().flatten() means to iter 1 layer, then remove nulls.

The new .flatten() means to flatten (unnest) recursively. Nulls are removed via let-else.

The 2 flatten are completely different, one on Iterator<Item=Option<T>> while the other on ListRef

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Merging #10469 (9f2e694) into main (43458ef) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main   #10469      +/-   ##
==========================================
- Coverage   70.51%   70.50%   -0.01%     
==========================================
  Files        1260     1260              
  Lines      215075   215076       +1     
==========================================
- Hits       151651   151649       -2     
- Misses      63424    63427       +3     
Flag Coverage Δ
rust 70.50% <0.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
src/expr/src/expr/expr_array_to_string.rs 2.63% <0.00%> (-0.04%) ⬇️

... and 4 files with indirect coverage changes

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

Copy link
Contributor

@st1page st1page left a comment

Choose a reason for hiding this comment

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

LGTM

@st1page
Copy link
Contributor

st1page commented Jun 25, 2023

So have we decided to be compatible with PG's behavior for those function with the same name?

@xiangjinwu
Copy link
Contributor Author

So have we decided to be compatible with PG's behavior for those function with the same name?

Yes. To elaborate:

  • It is okay for a query to work in PG but report an error in RW. This is an unsupported feature that may be supported later.
  • It is also okay for a query to report an error in PG but work in RW. This is an extension.
  • It is better avoided that the same query output different results silently in PG and RW. This is the issue being fixed here.

@xiangjinwu xiangjinwu added this pull request to the merge queue Jul 3, 2023
Merged via the queue into main with commit 0bfb15e Jul 3, 2023
@xiangjinwu xiangjinwu deleted the fix-expr-array-to-string-recursive branch July 3, 2023 07:35
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.

array_to_string gives extra parenthesis when double arrays are passed
3 participants