Skip to content

Apache DataFusion SQL Query Engine

Aggregate UDF cleanup (#16628)

Piotr Findeisen7cdac33dabbc
diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rs
index d1bf45ce2f..bc617097f0 100644
--- a/datafusion/expr/src/udaf.rs
+++ b/datafusion/expr/src/udaf.rs
@@ -170,6 +170,11 @@ impl AggregateUDF {
self.inner.name()
}
+ /// Returns the aliases for this function.
+ pub fn aliases(&self) -> &[String] {
+ self.inner.aliases()
+ }
+
/// See [`AggregateUDFImpl::schema_name`] for more details.
pub fn schema_name(&self, params: &AggregateFunctionParams) -> Result<String> {
self.inner.schema_name(params)
@@ -205,11 +210,6 @@ impl AggregateUDF {
self.inner.is_nullable()
}
- /// Returns the aliases for this function.
- pub fn aliases(&self) -> &[String] {
- self.inner.aliases()
- }
-
/// Returns this function's signature (what input types are accepted)
///
/// See [`AggregateUDFImpl::signature`] for more details.
@@ -435,6 +435,14 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
/// Returns this function's name
fn name(&self) -> &str;
+ /// Returns any aliases (alternate names) for this function.
+ ///
+ /// Note: `aliases` should only include names other than [`Self::name`].
+ /// Defaults to `[]` (no aliases)
+ fn aliases(&self) -> &[String] {
+ &[]
+ }
+
/// Returns the name of the column this expression would create
///
/// See [`Expr::schema_name`] for details
@@ -788,14 +796,6 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
not_impl_err!("GroupsAccumulator hasn't been implemented for {self:?} yet")
}
- /// Returns any aliases (alternate names) for this function.
- ///
- /// Note: `aliases` should only include names other than [`Self::name`].
- /// Defaults to `[]` (no aliases)
- fn aliases(&self) -> &[String] {
- &[]
- }
-
/// Sliding accumulator is an alternative accumulator that can be used for
/// window functions. It has retract method to revert the previous update.
///
diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs
index 8b6ffba04f..81865a836d 100644
--- a/datafusion/expr/src/udf.rs
+++ b/datafusion/expr/src/udf.rs
@@ -420,6 +420,19 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
/// Returns this function's name
fn name(&self) -> &str;
+ /// Returns any aliases (alternate names) for this function.
+ ///
+ /// Aliases can be used to invoke the same function using different names.
+ /// For example in some databases `now()` and `current_timestamp()` are
+ /// aliases for the same function. This behavior can be obtained by
+ /// returning `current_timestamp` as an alias for the `now` function.
+ ///
+ /// Note: `aliases` should only include names other than [`Self::name`].
+ /// Defaults to `[]` (no aliases)
+ fn aliases(&self) -> &[String] {
+ &[]
+ }
+
/// Returns the user-defined display name of function, given the arguments
///
/// This can be used to customize the output column name generated by this
@@ -543,19 +556,6 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
/// to arrays, which will likely be simpler code, but be slower.
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue>;
- /// Returns any aliases (alternate names) for this function.
- ///
- /// Aliases can be used to invoke the same function using different names.
- /// For example in some databases `now()` and `current_timestamp()` are
- /// aliases for the same function. This behavior can be obtained by
- /// returning `current_timestamp` as an alias for the `now` function.
- ///
- /// Note: `aliases` should only include names other than [`Self::name`].
- /// Defaults to `[]` (no aliases)
- fn aliases(&self) -> &[String] {
- &[]
- }
-
/// Optionally apply per-UDF simplification / rewrite rules.
///
/// This can be used to apply function specific simplification rules during
diff --git a/datafusion/expr/src/udwf.rs b/datafusion/expr/src/udwf.rs
index 155de23228..f5ab78e0c1 100644
--- a/datafusion/expr/src/udwf.rs
+++ b/datafusion/expr/src/udwf.rs
@@ -313,6 +313,14 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
/// Returns this function's name
fn name(&self) -> &str;
+ /// Returns any aliases (alternate names) for this function.
+ ///
+ /// Note: `aliases` should only include names other than [`Self::name`].
+ /// Defaults to `[]` (no aliases)
+ fn aliases(&self) -> &[String] {
+ &[]
+ }
+
/// Returns the function's [`Signature`] for information about what input
/// types are accepted and the function's Volatility.
fn signature(&self) -> &Signature;
@@ -328,14 +336,6 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
partition_evaluator_args: PartitionEvaluatorArgs,
) -> Result<Box<dyn PartitionEvaluator>>;
- /// Returns any aliases (alternate names) for this function.
- ///
- /// Note: `aliases` should only include names other than [`Self::name`].
- /// Defaults to `[]` (no aliases)
- fn aliases(&self) -> &[String] {
- &[]
- }
-
/// Optionally apply per-UDWF simplification / rewrite rules.
///
/// This can be used to apply function specific simplification rules during
diff --git a/datafusion/functions-aggregate-common/src/accumulator.rs b/datafusion/functions-aggregate-common/src/accumulator.rs
index 39303889f0..e0f7af1fb3 100644
--- a/datafusion/functions-aggregate-common/src/accumulator.rs
+++ b/datafusion/functions-aggregate-common/src/accumulator.rs
@@ -25,7 +25,7 @@ use std::sync::Arc;
/// [`AccumulatorArgs`] contains information about how an aggregate
/// function was called, including the types of its arguments and any optional
/// ordering expressions.
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct AccumulatorArgs<'a> {
/// The return field of the aggregate function.
pub return_field: FieldRef,