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
impl AggregateFunctionSetBuilder
Sourcepub fn new(name: &str) -> Self
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.
Sourcepub fn try_new(name: &str) -> Result<Self, ExtensionError>
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.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the function set name.
Useful for introspection and for MockRegistrar.
Sourcepub const fn returns(self, type_id: TypeId) -> Self
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.
Sourcepub fn returns_logical(self, logical_type: LogicalType) -> Self
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)
// });Sourcepub fn overloads<F>(self, range: RangeInclusive<usize>, f: F) -> Self
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
OverloadBuilderfor 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))
// });Sourcepub unsafe fn register(
self,
con: duckdb_connection,
) -> Result<(), ExtensionError>
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.
DuckDBreports registration failure.
§Safety
con must be a valid, open duckdb_connection.