Skip to main content

AggregateFunctionSetBuilder

Struct AggregateFunctionSetBuilder 

Source
pub struct AggregateFunctionSetBuilder { /* private fields */ }
Expand description

Builder for registering a DuckDB aggregate function set (multiple overloads).

Use this when your function accepts a variable number of arguments by registering N overloads (one per arity) under a single name.

§ADR-2: Function sets for variadic signatures

DuckDB does not support true varargs for aggregate functions. For functions that accept 2–32 boolean conditions, register 31 overloads.

§Pitfall L6: Name must be set on each member

This builder calls duckdb_aggregate_function_set_name on EVERY individual function before adding it to the set. If you forget this call, DuckDB silently rejects the registration. Discovery of this bug required reading DuckDB’s own C++ test code at test/api/capi/test_capi_aggregate_functions.cpp.

§Example

use quack_rs::aggregate::AggregateFunctionSetBuilder;
use quack_rs::types::{LogicalType, TypeId};
use libduckdb_sys::duckdb_connection;

// fn register_retention(con: duckdb_connection) -> Result<(), quack_rs::error::ExtensionError> {
//     AggregateFunctionSetBuilder::new("retention")
//         .returns_logical(LogicalType::list(TypeId::Boolean))
//         .overloads(2..=32, |_n, builder| {
//             builder
//                 .state_size(state_size)
//                 .init(state_init)
//                 .update(update)
//                 .combine(combine)
//                 .finalize(finalize)
//                 .destructor(destroy)
//         })
//         .register(con)
// }

Implementations§

Source§

impl AggregateFunctionSetBuilder

Source

pub fn new(name: &str) -> Self

Creates a new builder for a function set with the given name.

§Panics

Panics if name contains an interior null byte.

Source

pub fn try_new(name: &str) -> Result<Self, ExtensionError>

Creates a new builder with function name validation.

§Errors

Returns ExtensionError if the name is invalid. See validate_function_name for the full set of rules.

Source

pub fn name(&self) -> &str

Returns the function set name.

Useful for introspection and for MockRegistrar.

Source

pub const fn returns(self, type_id: TypeId) -> Self

Sets the return type for all overloads in this function set.

For complex return types like LIST(BIGINT), use returns_logical instead.

Source

pub fn returns_logical(self, logical_type: LogicalType) -> Self

Sets the return type to a complex LogicalType for all overloads.

Use this for parameterized return types that TypeId cannot express, such as LIST(BOOLEAN), LIST(TIMESTAMP), MAP(VARCHAR, INTEGER), etc.

If both returns and returns_logical are called, the logical type takes precedence.

§Example
use quack_rs::aggregate::AggregateFunctionSetBuilder;
use quack_rs::types::{LogicalType, TypeId};

// AggregateFunctionSetBuilder::new("retention")
//     .returns_logical(LogicalType::list(TypeId::Boolean))
//     .overloads(2..=32, |n, builder| {
//         (0..n).fold(builder, |b, _| b.param(TypeId::Boolean))
//             .state_size(my_state_size)
//             .init(my_init)
//             .update(my_update)
//             .combine(my_combine)
//             .finalize(my_finalize)
//     });
Source

pub fn overloads<F>(self, range: RangeInclusive<usize>, f: F) -> Self

Adds overloads for each arity in range, using the given builder closure.

The closure receives:

  • n: the number of parameters for this overload
  • A fresh OverloadBuilder for configuring callbacks
§Example
use quack_rs::aggregate::AggregateFunctionSetBuilder;
use quack_rs::types::TypeId;

// AggregateFunctionSetBuilder::new("retention")
//     .returns(TypeId::BigInt)
//     .overloads(2..=32, |n, builder| {
//         let builder = builder
//             .state_size(my_state_size)
//             .init(my_init)
//             .update(my_update)
//             .combine(my_combine)
//             .finalize(my_finalize);
//         // `n` booleans as params
//         (0..n).fold(builder, |b, _| b.param(TypeId::Boolean))
//     });
Source

pub unsafe fn register( self, con: duckdb_connection, ) -> Result<(), ExtensionError>

Registers the function set on the given connection.

§Pitfall L6

This method calls duckdb_aggregate_function_set_name on EVERY individual function in the set. Omitting this call causes silent registration failure.

§Errors

Returns ExtensionError if:

  • Return type was not set.
  • Any overload is missing required callbacks.
  • DuckDB reports registration failure.
§Safety

con must be a valid, open duckdb_connection.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.