-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: convert_array_to_scalar_vec respects null elements #17891
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
base: main
Are you sure you want to change the base?
feat: convert_array_to_scalar_vec respects null elements #17891
Conversation
9c6db36
to
b1bb29c
Compare
} else { | ||
partition_values.push(vec![].into()); | ||
} |
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'm not sure about this one! With the other changes, the group_by slt tests fail without this change. It is because in merge_ordered_arrays
we require that partition_values
and partition_ordering_values
have the same length (see code snippet below). But that seems weird since we now only do partition_ordering_values.push(ordering_value)
if the element in orderings
is Some
.
datafusion/datafusion/functions-aggregate-common/src/merge_arrays.rs
Lines 125 to 133 in 71512e6
if values.len() != ordering_values.len() | |
|| values | |
.iter() | |
.zip(ordering_values.iter()) | |
.any(|(vals, ordering_vals)| vals.len() != ordering_vals.len()) | |
{ | |
return exec_err!( | |
"Expects values arguments and/or ordering_values arguments to have same size" | |
); |
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.
There's also an exact same change done in nth_values.rs
.iter() | ||
.zip(ordering_values.iter()) | ||
.any(|(vals, ordering_vals)| vals.len() != ordering_vals.len()) | ||
if values.len() != ordering_values.len() { |
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 don't exactly feel strongly about these changes, but since these two conditions are different I liked the error message telling me which was the case.
217287c
to
35358d6
Compare
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.
Thanks @vegarsti I would love to see if there any performance degradations, you can find benches in the project.
Maybe we can have a separate test for this issues?
Good call, I will do both. Thanks! |
Benchmark results cc @comphead
|
35358d6
to
e232719
Compare
// 4: Offsets + Values looks like this: [[1, 2], [], [5]] | ||
// But with NullBuffer it's like this: [[1, 2], NULL, [5]] | ||
// The converted result is: [[1, 2], None, [5]] | ||
let array4 = ListArray::new( | ||
Field::new_list_field(DataType::Int64, true).into(), | ||
OffsetBuffer::new(vec![0, 2, 2, 5].into()), | ||
Arc::new(Int64Array::from(vec![1, 2, 3, 4, 5, 6])), | ||
Some(NullBuffer::from(vec![true, false, true])), | ||
); | ||
let converted = ScalarValue::convert_array_to_scalar_vec(&array4).unwrap(); | ||
assert_eq!( | ||
converted, | ||
vec![ | ||
Some(vec![ | ||
ScalarValue::Int64(Some(1)), | ||
ScalarValue::Int64(Some(2)) | ||
]), | ||
None, | ||
Some(vec![ | ||
ScalarValue::Int64(Some(3)), | ||
ScalarValue::Int64(Some(4)), | ||
ScalarValue::Int64(Some(5)), | ||
]), | ||
] | ||
); |
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.
On main the middle element here would be an empty vec, not None
.
// 5: Offsets + Values looks like this: [[1, 2], [], [5]] | ||
// Same as 4, but the middle array is not null, so after conversion it's empty. | ||
let array5 = ListArray::new( | ||
Field::new_list_field(DataType::Int64, true).into(), | ||
OffsetBuffer::new(vec![0, 2, 2, 5].into()), | ||
Arc::new(Int64Array::from(vec![1, 2, 3, 4, 5, 6])), | ||
Some(NullBuffer::from(vec![true, true, true])), | ||
); | ||
let converted = ScalarValue::convert_array_to_scalar_vec(&array5).unwrap(); | ||
assert_eq!( | ||
converted, | ||
vec![ | ||
Some(vec![ | ||
ScalarValue::Int64(Some(1)), | ||
ScalarValue::Int64(Some(2)) | ||
]), | ||
Some(vec![]), | ||
Some(vec![ | ||
ScalarValue::Int64(Some(3)), | ||
ScalarValue::Int64(Some(4)), | ||
ScalarValue::Int64(Some(5)), | ||
]), | ||
] |
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.
On main the middle element here would also be an empty vec, not None
.
I added two test cases to show the change in this PR. On main these both return an empty vector, but with this PR the nullability is preserved, so in the first one (4) it's |
Which issue does this PR close?
ScalarValue::convert_array_to_scalar_vec
doesn't respect null list elements #17749.What changes are included in this PR?
Makes
convert_array_to_scalar_vec
returnNone
instead of the empty list when list elements are null.Are these changes tested?
Covered by existing tests.
Are there any user-facing changes?
I don't think so?