-
Notifications
You must be signed in to change notification settings - Fork 1.9k
make array_union/array_except/array_intersect handle empty/null arrays rightly
#8269
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
Signed-off-by: veeupup <code@tanweime.com>
|
@jayzhan211 maybe you can check the behavior for these functions now cc @alamb |
Signed-off-by: veeupup <code@tanweime.com>
array_union handle empty/null arrays rightlyarray_union/array_except/array_intersect handle empty/null arrays rightly
Signed-off-by: veeupup <code@tanweime.com>
9ed1fca to
c08d6cb
Compare
jayzhan211
left a comment
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.
I think we need to fix here.
if data_types.is_empty() {
// ListArray[NullArray(0)], the same as `make_array()`.
let array = new_null_array(&DataType::Null, 0);
let array = Arc::new(array_into_list_array(array));
Ok(lit(ScalarValue::List(array)))
} else if data_types.len() > 1 {
Update: I found we can easily reuse MakeArray for sql_array_literal Ok(Expr::ScalarFunction(ScalarFunction::new(
BuiltinScalarFunction::MakeArray,
values,
))) |
|
@jayzhan211 Thanks for your constructive comments!I suppose we make it in a right way : ) |
Signed-off-by: veeupup <code@tanweime.com>
a76beaa to
be32301
Compare
|
We can move |
7fa005b to
e154ead
Compare
alamb
left a comment
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.
Thank you very much @Veeupup and @jayzhan211 - this looks really nice and exactly correct 🙏
| BuiltinScalarFunction::ArrayIntersect => Ok(input_expr_types[0].clone()), | ||
| BuiltinScalarFunction::ArrayUnion => Ok(input_expr_types[0].clone()), | ||
| BuiltinScalarFunction::ArrayUnion | BuiltinScalarFunction::ArrayIntersect => { | ||
| match (input_expr_types[0].clone(), input_expr_types[1].clone()) { |
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!
| SELECT ARRAY_AGG([]) | ||
| ---- | ||
| [] | ||
| [[]] |
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.
👍
| { | ||
| if !args.iter().all(|arg| { | ||
| arg.data_type().equals_datatype(data_type) | ||
| || arg.data_type().equals_datatype(&DataType::Null) |
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.
@Veeupup Why do we need Null checking here, which function failed without 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.
when it comes to handle multi arrays functions,their input types maybe like null, List(Int32).... Then, but we should handle null type in function body rather than return error here.
Which issue does this PR close?
Closes #8181.
for
array_union:for
array_except:for
array_intersect:Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?