Struct 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(AccumulatorArgs<'_>) -> Result<Box<dyn Accumulator>, 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(AccumulatorArgs<'_>) -> Result<Box<dyn Accumulator>, 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,
acc_args: AccumulatorArgs<'_>,
) -> Result<Box<dyn Accumulator>, DataFusionError>
pub fn accumulator( &self, acc_args: AccumulatorArgs<'_>, ) -> Result<Box<dyn Accumulator>, DataFusionError>
Return an accumulator the given aggregate, given its return datatype
sourcepub fn state_fields(
&self,
args: StateFieldsArgs<'_>,
) -> Result<Vec<Field>, DataFusionError>
pub fn state_fields( &self, args: StateFieldsArgs<'_>, ) -> Result<Vec<Field>, DataFusionError>
Return the fields used to store the intermediate state for this aggregator, given
the name of the aggregate, value type and ordering fields. See AggregateUDFImpl::state_fields
for more details.
This is used to support multi-phase aggregations
sourcepub fn groups_accumulator_supported(&self, args: AccumulatorArgs<'_>) -> bool
pub fn groups_accumulator_supported(&self, args: AccumulatorArgs<'_>) -> bool
See AggregateUDFImpl::groups_accumulator_supported
for more details.
sourcepub fn create_groups_accumulator(
&self,
args: AccumulatorArgs<'_>,
) -> Result<Box<dyn GroupsAccumulator>, DataFusionError>
pub fn create_groups_accumulator( &self, args: AccumulatorArgs<'_>, ) -> Result<Box<dyn GroupsAccumulator>, DataFusionError>
See AggregateUDFImpl::create_groups_accumulator
for more details.
pub fn create_sliding_accumulator( &self, args: AccumulatorArgs<'_>, ) -> Result<Box<dyn Accumulator>, DataFusionError>
pub fn coerce_types( &self, arg_types: &[DataType], ) -> Result<Vec<DataType>, DataFusionError>
sourcepub fn with_beneficial_ordering(
self,
beneficial_ordering: bool,
) -> Result<Option<AggregateUDF>, DataFusionError>
pub fn with_beneficial_ordering( self, beneficial_ordering: bool, ) -> Result<Option<AggregateUDF>, DataFusionError>
See AggregateUDFImpl::with_beneficial_ordering
for more details.
sourcepub fn order_sensitivity(&self) -> AggregateOrderSensitivity
pub fn order_sensitivity(&self) -> AggregateOrderSensitivity
Gets the order sensitivity of the UDF. See AggregateOrderSensitivity
for possible options.
sourcepub fn reverse_udf(&self) -> ReversedUDAF
pub fn reverse_udf(&self) -> ReversedUDAF
Reserves the AggregateUDF
(e.g. returns the AggregateUDF
that will
generate same result with this AggregateUDF
when iterated in reverse
order, and None
if there is no such AggregateUDF
).
sourcepub fn simplify(
&self,
) -> Option<Box<dyn Fn(AggregateFunction, &dyn SimplifyInfo) -> Result<Expr, DataFusionError>>>
pub fn simplify( &self, ) -> Option<Box<dyn Fn(AggregateFunction, &dyn SimplifyInfo) -> Result<Expr, DataFusionError>>>
Do the function rewrite
See AggregateUDFImpl::simplify
for more details.
sourcepub fn is_descending(&self) -> Option<bool>
pub fn is_descending(&self) -> Option<bool>
Returns true if the function is max, false if the function is min None in all other cases, used in certain optimizations or or aggregate
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 Display for AggregateUDF
impl Display 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
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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> 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