Skip to main content

Module aggregate

Module aggregate 

Source
Expand description

Builders for registering DuckDB aggregate functions.

This module provides two builder types:

§Pitfalls solved

  • L6 (Problem 2): 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 handles 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;

Modules§

builder
Builder types for registering DuckDB aggregate functions.
callbacks
Type aliases for the five required DuckDB aggregate callback signatures.
info
Ergonomic wrapper around duckdb_function_info for aggregate function callbacks.
state
Generic FfiState<T> wrapper for safe aggregate state management.