Expand description
Builders for registering DuckDB aggregate functions.
This module provides two builder types:
AggregateFunctionBuilder: Register a single aggregate function with one fixed signature. Supports complex parameter types viaparam_logicaland complex return types viareturns_logical.AggregateFunctionSetBuilder: Register a function set — several overloads under one name, differing in arity (the variadic case, sinceDuckDBhas no aggregate varargs), in parameter types, or in return type.DuckDBresolves an overload from its parameter types and arity alone, so each may return something different. Set it per overload withAggregateOverloadBuilder::returns/returns_logical, or once on the set as a default viaAggregateFunctionSetBuilder::returns_logical. Complex parameter types go throughAggregateOverloadBuilder::param_logical.
§Pitfalls solved
- L6 (Problem 2): The builder enforces that every function in a
function set has its name set individually. Without this,
DuckDBsilently returnsDuckDBErrorwhen you callduckdb_register_aggregate_function_set, and the function is never registered. - L7:
LogicalTypehandles memory management for all type handles.
§Example: Single function
use quack_rs::aggregate::AggregateFunctionBuilder;
use quack_rs::types::TypeId;
use libduckdb_sys::{duckdb_connection, duckdb_function_info, duckdb_aggregate_state,
duckdb_data_chunk, duckdb_vector, idx_t};
// Define your callbacks
unsafe extern "C" fn state_size(_: duckdb_function_info) -> idx_t { 8 }
unsafe extern "C" fn state_init(_: duckdb_function_info, _: duckdb_aggregate_state) {}
unsafe extern "C" fn update(_: duckdb_function_info, _: duckdb_data_chunk, _: duckdb_aggregate_state) {}
unsafe extern "C" fn combine(_: duckdb_function_info, _: duckdb_aggregate_state, _: duckdb_aggregate_state, _: idx_t) {}
unsafe extern "C" fn finalize(_: duckdb_function_info, _: duckdb_aggregate_state, _: duckdb_vector, _: idx_t, _: idx_t) {}
// fn register(con: duckdb_connection) {
// AggregateFunctionBuilder::new("my_count")
// .param(TypeId::BigInt)
// .returns(TypeId::BigInt)
// .state_size(state_size)
// .init(state_init)
// .update(update)
// .combine(combine)
// .finalize(finalize)
// .register(con)
// .expect("registration failed");
// }Re-exports§
pub use builder::AggregateFunctionBuilder;pub use builder::AggregateFunctionSetBuilder;pub use builder::AggregateOverloadBuilder;pub use callbacks::CombineFn;pub use callbacks::DestroyFn;pub use callbacks::FinalizeFn;pub use callbacks::StateInitFn;pub use callbacks::StateSizeFn;pub use callbacks::UpdateFn;pub use info::AggregateFunctionInfo;pub use state::AggregateState;pub use state::FfiState;