Skip to content

Commit 7cdac33

Browse files
authored
Aggregate UDF cleanup (#16628)
* Allow cloning AccumulatorArgs Otherwise, consumers need to destructure and clone individual fields. * Collocate name and aliases in code These are tightly related, it makes sense to have them next to each other.
1 parent df9f096 commit 7cdac33

4 files changed

Lines changed: 35 additions & 35 deletions

File tree

‎datafusion/expr/src/udaf.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ impl AggregateUDF {
170170
self.inner.name()
171171
}
172172

173+
/// Returns the aliases for this function.
174+
pub fn aliases(&self) -> &[String] {
175+
self.inner.aliases()
176+
}
177+
173178
/// See [`AggregateUDFImpl::schema_name`] for more details.
174179
pub fn schema_name(&self, params: &AggregateFunctionParams) -> Result<String> {
175180
self.inner.schema_name(params)
@@ -205,11 +210,6 @@ impl AggregateUDF {
205210
self.inner.is_nullable()
206211
}
207212

208-
/// Returns the aliases for this function.
209-
pub fn aliases(&self) -> &[String] {
210-
self.inner.aliases()
211-
}
212-
213213
/// Returns this function's signature (what input types are accepted)
214214
///
215215
/// See [`AggregateUDFImpl::signature`] for more details.
@@ -435,6 +435,14 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
435435
/// Returns this function's name
436436
fn name(&self) -> &str;
437437

438+
/// Returns any aliases (alternate names) for this function.
439+
///
440+
/// Note: `aliases` should only include names other than [`Self::name`].
441+
/// Defaults to `[]` (no aliases)
442+
fn aliases(&self) -> &[String] {
443+
&[]
444+
}
445+
438446
/// Returns the name of the column this expression would create
439447
///
440448
/// See [`Expr::schema_name`] for details
@@ -788,14 +796,6 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
788796
not_impl_err!("GroupsAccumulator hasn't been implemented for {self:?} yet")
789797
}
790798

791-
/// Returns any aliases (alternate names) for this function.
792-
///
793-
/// Note: `aliases` should only include names other than [`Self::name`].
794-
/// Defaults to `[]` (no aliases)
795-
fn aliases(&self) -> &[String] {
796-
&[]
797-
}
798-
799799
/// Sliding accumulator is an alternative accumulator that can be used for
800800
/// window functions. It has retract method to revert the previous update.
801801
///

‎datafusion/expr/src/udf.rs‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
420420
/// Returns this function's name
421421
fn name(&self) -> &str;
422422

423+
/// Returns any aliases (alternate names) for this function.
424+
///
425+
/// Aliases can be used to invoke the same function using different names.
426+
/// For example in some databases `now()` and `current_timestamp()` are
427+
/// aliases for the same function. This behavior can be obtained by
428+
/// returning `current_timestamp` as an alias for the `now` function.
429+
///
430+
/// Note: `aliases` should only include names other than [`Self::name`].
431+
/// Defaults to `[]` (no aliases)
432+
fn aliases(&self) -> &[String] {
433+
&[]
434+
}
435+
423436
/// Returns the user-defined display name of function, given the arguments
424437
///
425438
/// This can be used to customize the output column name generated by this
@@ -543,19 +556,6 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
543556
/// to arrays, which will likely be simpler code, but be slower.
544557
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue>;
545558

546-
/// Returns any aliases (alternate names) for this function.
547-
///
548-
/// Aliases can be used to invoke the same function using different names.
549-
/// For example in some databases `now()` and `current_timestamp()` are
550-
/// aliases for the same function. This behavior can be obtained by
551-
/// returning `current_timestamp` as an alias for the `now` function.
552-
///
553-
/// Note: `aliases` should only include names other than [`Self::name`].
554-
/// Defaults to `[]` (no aliases)
555-
fn aliases(&self) -> &[String] {
556-
&[]
557-
}
558-
559559
/// Optionally apply per-UDF simplification / rewrite rules.
560560
///
561561
/// This can be used to apply function specific simplification rules during

‎datafusion/expr/src/udwf.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,14 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
313313
/// Returns this function's name
314314
fn name(&self) -> &str;
315315

316+
/// Returns any aliases (alternate names) for this function.
317+
///
318+
/// Note: `aliases` should only include names other than [`Self::name`].
319+
/// Defaults to `[]` (no aliases)
320+
fn aliases(&self) -> &[String] {
321+
&[]
322+
}
323+
316324
/// Returns the function's [`Signature`] for information about what input
317325
/// types are accepted and the function's Volatility.
318326
fn signature(&self) -> &Signature;
@@ -328,14 +336,6 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
328336
partition_evaluator_args: PartitionEvaluatorArgs,
329337
) -> Result<Box<dyn PartitionEvaluator>>;
330338

331-
/// Returns any aliases (alternate names) for this function.
332-
///
333-
/// Note: `aliases` should only include names other than [`Self::name`].
334-
/// Defaults to `[]` (no aliases)
335-
fn aliases(&self) -> &[String] {
336-
&[]
337-
}
338-
339339
/// Optionally apply per-UDWF simplification / rewrite rules.
340340
///
341341
/// This can be used to apply function specific simplification rules during

‎datafusion/functions-aggregate-common/src/accumulator.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::sync::Arc;
2525
/// [`AccumulatorArgs`] contains information about how an aggregate
2626
/// function was called, including the types of its arguments and any optional
2727
/// ordering expressions.
28-
#[derive(Debug)]
28+
#[derive(Debug, Clone)]
2929
pub struct AccumulatorArgs<'a> {
3030
/// The return field of the aggregate function.
3131
pub return_field: FieldRef,

0 commit comments

Comments
 (0)