Struct deltalake::datafusion::logical_expr::AggregateUDF
source · pub struct AggregateUDF { /* private fields */ }
Expand description
Logical representation of a user-defined aggregate function (UDAF).
An aggregate function combines the values from multiple input rows
into a single output “aggregate” (summary) row. It is different
from a scalar function because it is stateful across batches. User
defined aggregate functions can be used as normal SQL aggregate
functions (GROUP BY
clause) as well as window functions (OVER
clause).
AggregateUDF
provides DataFusion the information needed to plan and call
aggregate functions, including name, type information, and a factory
function to create an Accumulator
instance, to perform the actual
aggregation.
For more information, please see the examples:
-
For simple use cases, use
create_udaf
(examples insimple_udaf.rs
). -
For advanced use cases, use
AggregateUDFImpl
which provides full API access (examples inadvanced_udaf.rs
).
§API Note
This is a separate struct from AggregateUDFImpl
to maintain backwards
compatibility with the older API.
Implementations§
source§impl AggregateUDF
impl AggregateUDF
sourcepub fn new(
name: &str,
signature: &Signature,
return_type: &Arc<dyn Fn(&[DataType]) -> Result<Arc<DataType>, DataFusionError> + Sync + Send>,
accumulator: &Arc<dyn Fn(&DataType) -> Result<Box<dyn Accumulator>, DataFusionError> + Sync + Send>,
state_type: &Arc<dyn Fn(&DataType) -> Result<Arc<Vec<DataType>>, DataFusionError> + Sync + Send>
) -> AggregateUDF
👎Deprecated since 34.0.0: please implement AggregateUDFImpl instead
pub fn new( name: &str, signature: &Signature, return_type: &Arc<dyn Fn(&[DataType]) -> Result<Arc<DataType>, DataFusionError> + Sync + Send>, accumulator: &Arc<dyn Fn(&DataType) -> Result<Box<dyn Accumulator>, DataFusionError> + Sync + Send>, state_type: &Arc<dyn Fn(&DataType) -> Result<Arc<Vec<DataType>>, DataFusionError> + Sync + Send> ) -> AggregateUDF
Create a new AggregateUDF
See AggregateUDFImpl
for a more convenient way to create a
AggregateUDF
using trait objects
sourcepub fn new_from_impl<F>(fun: F) -> AggregateUDFwhere
F: AggregateUDFImpl + 'static,
pub fn new_from_impl<F>(fun: F) -> AggregateUDFwhere
F: AggregateUDFImpl + 'static,
Create a new AggregateUDF
from a [AggregateUDFImpl]
trait object
Note this is the same as using the From
impl (AggregateUDF::from
)
sourcepub fn inner(&self) -> Arc<dyn AggregateUDFImpl>
pub fn inner(&self) -> Arc<dyn AggregateUDFImpl>
Return the underlying AggregateUDFImpl
trait object for this function
sourcepub fn with_aliases(
self,
aliases: impl IntoIterator<Item = &'static str>
) -> AggregateUDF
pub fn with_aliases( self, aliases: impl IntoIterator<Item = &'static str> ) -> AggregateUDF
Adds additional names that can be used to invoke this function, in
addition to name
If you implement AggregateUDFImpl
directly you should return aliases directly.
sourcepub fn call(&self, args: Vec<Expr>) -> Expr
pub fn call(&self, args: Vec<Expr>) -> Expr
creates an Expr
that calls the aggregate function.
This utility allows using the UDAF without requiring access to the registry, such as with the DataFrame API.
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns this function’s name
See AggregateUDFImpl::name
for more details.
sourcepub fn signature(&self) -> &Signature
pub fn signature(&self) -> &Signature
Returns this function’s signature (what input types are accepted)
See AggregateUDFImpl::signature
for more details.
sourcepub fn return_type(
&self,
args: &[DataType]
) -> Result<DataType, DataFusionError>
pub fn return_type( &self, args: &[DataType] ) -> Result<DataType, DataFusionError>
Return the type of the function given its input types
See AggregateUDFImpl::return_type
for more details.
sourcepub fn accumulator(
&self,
return_type: &DataType
) -> Result<Box<dyn Accumulator>, DataFusionError>
pub fn accumulator( &self, return_type: &DataType ) -> Result<Box<dyn Accumulator>, DataFusionError>
Return an accumulator the given aggregate, given its return datatype.
sourcepub fn state_type(
&self,
return_type: &DataType
) -> Result<Vec<DataType>, DataFusionError>
pub fn state_type( &self, return_type: &DataType ) -> Result<Vec<DataType>, DataFusionError>
Return the type of the intermediate state used by this aggregator, given its return datatype. Supports multi-phase aggregations
sourcepub fn groups_accumulator_supported(&self) -> bool
pub fn groups_accumulator_supported(&self) -> bool
See AggregateUDFImpl::groups_accumulator_supported
for more details.
sourcepub fn create_groups_accumulator(
&self
) -> Result<Box<dyn GroupsAccumulator>, DataFusionError>
pub fn create_groups_accumulator( &self ) -> Result<Box<dyn GroupsAccumulator>, DataFusionError>
See AggregateUDFImpl::create_groups_accumulator
for more details.
Trait Implementations§
source§impl Clone for AggregateUDF
impl Clone for AggregateUDF
source§fn clone(&self) -> AggregateUDF
fn clone(&self) -> AggregateUDF
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for AggregateUDF
impl Debug for AggregateUDF
source§impl<F> From<F> for AggregateUDF
impl<F> From<F> for AggregateUDF
source§fn from(fun: F) -> AggregateUDF
fn from(fun: F) -> AggregateUDF
source§impl Hash for AggregateUDF
impl Hash for AggregateUDF
source§impl PartialEq for AggregateUDF
impl PartialEq for AggregateUDF
source§fn eq(&self, other: &AggregateUDF) -> bool
fn eq(&self, other: &AggregateUDF) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for AggregateUDF
Auto Trait Implementations§
impl Freeze for AggregateUDF
impl !RefUnwindSafe for AggregateUDF
impl Send for AggregateUDF
impl Sync for AggregateUDF
impl Unpin for AggregateUDF
impl !UnwindSafe for AggregateUDF
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more