Skip to content
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

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jun 20, 2023

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?

  1. Update docs for AggregateUDF
  2. Update docs for Accumulator
  3. Rename AccumulatorFunctionImplementation to AccumulatorFactoryFunction to better describe what it does

Are these changes tested?

Yes (existing tests + doc tests)

Are there any user-facing changes?

  1. Better docs
  2. Different type alias name (AccumulatorFunctionImplementation to AccumulatorFactoryFunction)

@alamb alamb added the api change Changes the API exposed to users of the crate label Jun 20, 2023
@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions labels Jun 20, 2023
@github-actions github-actions bot added the optimizer Optimizer rules label Jun 20, 2023
//! 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
Copy link
Contributor Author

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.
Copy link
Contributor Author

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 =
Copy link
Contributor Author

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

Copy link
Contributor

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

@alamb alamb self-assigned this Jun 20, 2023
Copy link
Contributor

@stuartcarnie stuartcarnie left a 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!

Comment on lines +153 to +178
///
/// # 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]`.
Copy link
Contributor

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>>;
Copy link
Contributor

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 =
Copy link
Contributor

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

@alamb alamb merged commit eb290a0 into apache:main Jun 22, 2023
@alamb alamb deleted the alamb/accumulator_docs branch June 22, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate core Core DataFusion crate logical-expr Logical plan and expressions optimizer Optimizer rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants