1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MIT
// Copyright 2026 Tom F. <https://github.com/tomtom215/>
// My way of giving something small back to the open source community
// and encouraging more Rust development!
//! 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 via
//! [`param_logical`][AggregateFunctionBuilder::param_logical] and complex
//! return types via [`returns_logical`][AggregateFunctionBuilder::returns_logical].
//! - [`AggregateFunctionSetBuilder`]: Register a function set (multiple overloads
//! under one name) for functions with variadic signatures. Supports complex
//! return types via [`returns_logical`][AggregateFunctionSetBuilder::returns_logical]
//! and per-overload complex parameters via `OverloadBuilder::param_logical`.
//!
//! # Pitfalls solved
//!
//! - **L6** ([Problem 2][super]): The builder enforces that every function in a
//! function set has its name set individually. Without this, `DuckDB` silently
//! returns `DuckDBError` when you call `duckdb_register_aggregate_function_set`,
//! and the function is never registered.
//! - **L7**: [`LogicalType`][crate::types::LogicalType] handles memory management
//! for all type handles.
//!
//! # Example: Single function
//!
//! ```rust,no_run
//! 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");
//! // }
//! ```
pub use ;
pub use AggregateFunctionInfo;
pub use ;