You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "joroKr21 (via GitHub)" <gi...@apache.org> on 2024/07/22 08:35:58 UTC
[PR] Add NullState::is_valid and NullState::is_null [datafusion]
joroKr21 opened a new pull request, #11592:
URL: https://github.com/apache/datafusion/pull/11592
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #11591.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Provide more flexibility for implementing `GroupsAccumulator` which often make use of `NullState`.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Adds two new public methods - `NullState::is_valid` and `NullState::is_null` (similar API to `NullBuffer`).
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Yes, extended existing tests.
## Are there any user-facing changes?
Yes, adds two new public methods to `NullState`.
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2243667468
Yeah good point, I converted it to a draft. I'm not sure what to do. Adding a boolean flag to the callback is not great either...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1687564010
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/prim_op.rs:
##########
@@ -102,9 +102,13 @@ where
values,
opt_filter,
total_num_groups,
- |group_index, new_value| {
- let value = &mut self.values[group_index];
- (self.prim_fn)(value, new_value);
+ |group_index, was_valid, new_value| {
Review Comment:
I don't think the existing implementation have to change, or do they?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2243686252
@alamb I implemented the version with an additional callback parameter, LMK what you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1686448252
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/accumulate.rs:
##########
@@ -324,6 +324,18 @@ impl NullState {
}
}
+ /// Check if the accumulated value for the group at the given `index` is valid,
+ /// meaning that there was at least one value passing the filter for this group.
+ pub fn is_valid(&self, index: usize) -> bool {
+ self.seen_values.get_bit(index)
+ }
Review Comment:
Ahh I can't use it in `accumulate` due to mutable vs immutable borrow. This API is pretty difficult to use.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1687065841
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/accumulate.rs:
##########
@@ -132,7 +132,7 @@ impl NullState {
mut value_fn: F,
) where
T: ArrowPrimitiveType + Send,
- F: FnMut(usize, T::Native) + Send,
+ F: FnMut(usize, bool, T::Native) + Send,
Review Comment:
Can we please update the documentation to reflect this new argument and explains what it means
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/prim_op.rs:
##########
@@ -102,9 +102,13 @@ where
values,
opt_filter,
total_num_groups,
- |group_index, new_value| {
- let value = &mut self.values[group_index];
- (self.prim_fn)(value, new_value);
+ |group_index, was_valid, new_value| {
Review Comment:
It would be nice to add a test that covered this, if possible
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1686483705
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/accumulate.rs:
##########
@@ -324,6 +324,18 @@ impl NullState {
}
}
+ /// Check if the accumulated value for the group at the given `index` is valid,
+ /// meaning that there was at least one value passing the filter for this group.
+ pub fn is_valid(&self, index: usize) -> bool {
+ self.seen_values.get_bit(index)
+ }
Review Comment:
This is the signature of `accumulate`:
```rust
pub fn accumulate<T, F>(
&mut self,
group_indices: &[usize],
values: &PrimitiveArray<T>,
opt_filter: Option<&BooleanArray>,
total_num_groups: usize,
mut value_fn: F,
) where
T: ArrowPrimitiveType + Send,
F: FnMut(usize, T::Native) + Send
```
But I can't use `is_null` inside `value_fn` because the `NullState` is already borrowed as mutable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1686495035
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/accumulate.rs:
##########
@@ -324,6 +324,18 @@ impl NullState {
}
}
+ /// Check if the accumulated value for the group at the given `index` is valid,
+ /// meaning that there was at least one value passing the filter for this group.
+ pub fn is_valid(&self, index: usize) -> bool {
+ self.seen_values.get_bit(index)
+ }
Review Comment:
Ideally `BooleanBufferBuilder::set_bit` should return the previous value and we can pass it along to the callback. That's in arrow I guess.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1687603952
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/prim_op.rs:
##########
@@ -102,9 +102,13 @@ where
values,
opt_filter,
total_num_groups,
- |group_index, new_value| {
- let value = &mut self.values[group_index];
- (self.prim_fn)(value, new_value);
+ |group_index, was_valid, new_value| {
Review Comment:
Perhaps not, although conceptually an accumulator is just a map-reduce-map via some monoid or semigroup. The current implementation supports only monoids (need an empty value) but it doesn't support semigroups (no empty value). We could use this for something like `FirstValue` or `AnyValue` but I guess we could also implement it specifically for that use case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2247302876
> @alamb the benchmark didn't trigger on comment
That support has been dropped (as it was a potential security risk and wasn't super reliable).
https://github.com/apache/datafusion/pull/11165
Can you run the benchmarks and post the results here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2312676697
I don't like this API at all
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2244358083
/benchmark
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1687604948
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/prim_op.rs:
##########
@@ -102,9 +102,13 @@ where
values,
opt_filter,
total_num_groups,
- |group_index, new_value| {
- let value = &mut self.values[group_index];
- (self.prim_fn)(value, new_value);
+ |group_index, was_valid, new_value| {
Review Comment:
We could even drop the initial value parameter since it doesn't matter in this case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1686483705
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/accumulate.rs:
##########
@@ -324,6 +324,18 @@ impl NullState {
}
}
+ /// Check if the accumulated value for the group at the given `index` is valid,
+ /// meaning that there was at least one value passing the filter for this group.
+ pub fn is_valid(&self, index: usize) -> bool {
+ self.seen_values.get_bit(index)
+ }
Review Comment:
This is the signature of `accumulate`:
```rust
pub fn accumulate<T, F>(
&mut self,
group_indices: &[usize],
values: &PrimitiveArray<T>,
opt_filter: Option<&BooleanArray>,
total_num_groups: usize,
mut value_fn: F,
) where
T: ArrowPrimitiveType + Send,
F: FnMut(usize, bool, T::Native) + Send
```
But I can't use `is_null` inside `value_fn` because the `NullState` is already borrowed as mutable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2247513997
> Can you run the benchmarks and post the results here?
Sure, it might be some time until I do that though
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add NullState::is_valid and NullState::is_null [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#discussion_r1686464191
##########
datafusion/physical-expr-common/src/aggregate/groups_accumulator/accumulate.rs:
##########
@@ -324,6 +324,18 @@ impl NullState {
}
}
+ /// Check if the accumulated value for the group at the given `index` is valid,
+ /// meaning that there was at least one value passing the filter for this group.
+ pub fn is_valid(&self, index: usize) -> bool {
+ self.seen_values.get_bit(index)
+ }
Review Comment:
I don't understand this comment 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 commented on PR #11592:
URL: https://github.com/apache/datafusion/pull/11592#issuecomment-2247161635
@alamb the benchmark didn't trigger on comment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Add was_valid parameter to NullState callbacks [datafusion]
Posted by "joroKr21 (via GitHub)" <gi...@apache.org>.
joroKr21 closed pull request #11592: Add was_valid parameter to NullState callbacks
URL: https://github.com/apache/datafusion/pull/11592
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org