-
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
Update documentation for creating User Defined Aggregates (AggregateUDF) #6729
Conversation
//! uses [Apache Arrow] as its in-memory format. DataFusion's [use | ||
//! cases] include building very fast database and analytic systems, | ||
//! customized to particular workloads. | ||
//! uses [Apache Arrow] as its in-memory format. DataFusion's many [use |
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 was a drive by cleanup as I pretended to be a new user navigating to the AggregateUDF page
/// other partial states from different instances of this | ||
/// accumulator (that ran on different partitions, for | ||
/// example). | ||
/// Updates the accumulator's state from its input. |
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.
The trait is the same -- I did reorderd the methods to be better grouped together by use, but the actual methods are the same
@@ -42,7 +42,7 @@ pub type ReturnTypeFunction = | |||
|
|||
/// Factory that returns an accumulator for the given aggregate, given | |||
/// its return datatype. | |||
pub type AccumulatorFunctionImplementation = | |||
pub type AccumulatorFactoryFunction = |
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 was just misleading, so I changed the name
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.
Totally agree – this name is much clearer
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.
These are great improvements, thank you!
/// | ||
/// # Example | ||
/// | ||
/// For example, given the following input partition | ||
/// | ||
/// ```text | ||
/// │ current │ | ||
/// window | ||
/// │ │ | ||
/// ┌────┬────┬────┬────┬────┬────┬────┬────┬────┐ | ||
/// Input │ A │ B │ C │ D │ E │ F │ G │ H │ I │ | ||
/// partition └────┴────┴────┴────┼────┴────┴────┴────┼────┘ | ||
/// | ||
/// │ next │ | ||
/// window | ||
/// ``` | ||
/// | ||
/// First, [`Self::evaluate`] will be called to produce the output | ||
/// for the current window. | ||
/// | ||
/// Then, to advance to the next window: | ||
/// | ||
/// First, [`Self::retract_batch`] will be called with the values | ||
/// that are leaving the window, `[B, C, D]` and then | ||
/// [`Self::update_batch`] will be called with the values that are | ||
/// entering the window, `[F, G, H]`. |
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.
Very clear explanation 💯
/// time (e.g. median) | ||
/// 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>>; |
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 updated documentation is fantastic, thank you @alamb
@@ -42,7 +42,7 @@ pub type ReturnTypeFunction = | |||
|
|||
/// Factory that returns an accumulator for the given aggregate, given | |||
/// its return datatype. | |||
pub type AccumulatorFunctionImplementation = | |||
pub type AccumulatorFactoryFunction = |
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.
Totally agree – this name is much clearer
Which issue does this PR close?
related to #6611
Rationale for this change
@stuartcarnie had some questions about how this API should work, and so I wanted to encode the answers into documentation for others as well
What changes are included in this PR?
AggregateUDF
Accumulator
AccumulatorFunctionImplementation
toAccumulatorFactoryFunction
to better describe what it doesAre these changes tested?
Yes (existing tests + doc tests)
Are there any user-facing changes?
AccumulatorFunctionImplementation
toAccumulatorFactoryFunction
)