-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Change Accumulator::evaluate
and Accumulator::state
to take &mut self
#8925
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
70ffb2f
Change `Accumulator::evaluate` and `Accumulator::state` to take `&mut…
alamb 8f98507
improve docs
alamb d2d50f8
Merge remote-tracking branch 'apache/main' into alamb/state_mut
alamb aadde16
fix signature
alamb 63f1c9e
Merge remote-tracking branch 'apache/main' into alamb/state_mut
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,11 +56,18 @@ pub trait Accumulator: Send + Sync + Debug { | |
/// running sum. | ||
fn update_batch(&mut self, values: &[ArrayRef]) -> Result<()>; | ||
|
||
/// Returns the final aggregate value. | ||
/// Returns the final aggregate value, consuming the internal state. | ||
/// | ||
/// For example, the `SUM` accumulator maintains a running sum, | ||
/// and `evaluate` will produce that running sum as its output. | ||
fn evaluate(&self) -> Result<ScalarValue>; | ||
/// | ||
/// After this call, the accumulator's internal state should be | ||
/// equivalent to when it was first created. | ||
/// | ||
/// This function gets `&mut self` to allow for the accumulator to build | ||
/// arrow compatible internal state that can be returned without copying | ||
/// when possible (for example distinct strings) | ||
fn evaluate(&mut self) -> Result<ScalarValue>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the core change in this PR -- make This is technically possible today (with "inner mutability", for example a |
||
|
||
/// Returns the allocated size required for this accumulator, in | ||
/// bytes, including `Self`. | ||
|
@@ -72,7 +79,15 @@ pub trait Accumulator: Send + Sync + Debug { | |
/// the `capacity` should be used not the `len`. | ||
fn size(&self) -> usize; | ||
|
||
/// Returns the intermediate state of the accumulator. | ||
/// Returns the intermediate state of the accumulator, consuming the | ||
/// intermediate state. | ||
/// | ||
/// After this call, the accumulator's internal state should be | ||
/// equivalent to when it was first created. | ||
/// | ||
/// This function gets `&mut self` to allow for the accumulator to build | ||
/// arrow compatible internal state that can be returned without copying | ||
/// when possible (for example distinct strings). | ||
/// | ||
/// Intermediate state is used for "multi-phase" grouping in | ||
/// DataFusion, where an aggregate is computed in parallel with | ||
|
@@ -129,7 +144,7 @@ pub trait Accumulator: Send + Sync + Debug { | |
/// Note that [`ScalarValue::List`] can be used to pass multiple | ||
/// values if the number of intermediate values is not known at | ||
/// planning time (e.g. for `MEDIAN`) | ||
fn state(&self) -> Result<Vec<ScalarValue>>; | ||
fn state(&mut self) -> Result<Vec<ScalarValue>>; | ||
|
||
/// Updates the accumulator's state from an `Array` containing one | ||
/// or more intermediate values. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is an example of what DataFusion users have to do if this PR is merged -- they have to change the signatures to take
mut