Install and load
Run these commands in a Haybarn SQL session. The extension is available from the community repository.
INSTALL behavioral FROM community;
LOAD behavioral FROM community;
Using upstream DuckDB? Follow the maintainer’s installation instructions.
Usage example
Funnel: how far did each user get through view -> cart -> buy within 1 hour?
-- Funnel: how far did each user get through view -> cart -> buy within 1 hour?
SELECT user_id,
window_funnel(INTERVAL '1 hour', ts, e = 'view', e = 'cart', e = 'buy') AS furthest_step
FROM (VALUES (1, TIMESTAMP '2024-01-01 10:00', 'view'), (1, TIMESTAMP '2024-01-01 10:05', 'cart'),
(1, TIMESTAMP '2024-01-01 10:20', 'buy'), (2, TIMESTAMP '2024-01-01 11:00', 'view'),
(2, TIMESTAMP '2024-01-01 15:00', 'cart')) t(user_id, ts, e)
GROUP BY user_id ORDER BY user_id;
-- Sessions: a new session after 30 minutes of inactivity
SELECT ts, sessionize(ts, INTERVAL '30 minutes') OVER (ORDER BY ts) AS session_id
FROM (VALUES (TIMESTAMP '2024-01-01 10:00'), (TIMESTAMP '2024-01-01 10:10'),
(TIMESTAMP '2024-01-01 11:00')) t(ts);
Provided by tomtom215. Not yet verified on Haybarn 2.0.0.
Sample data & setupAbout this extension
Behavioral analytics functions for DuckDB, following ClickHouse's parametric behavioral functions (differentially tested against ClickHouse 26.10):
Up to 32 event conditions per call. Invalid configuration (unknown modes, malformed patterns, month-based intervals) raises descriptive SQL errors. Built on DuckDB's stable C API; pure Rust, with no unsafe code outside the FFI layer.
Project overview from the community descriptor.
Documentation and resources
Project and build details
- Repository
- tomtom215/duckdb-behavioral
- License
- MIT
- Maintainers
- tomtom215
- Written in
- Rust
- Build source
69f96cb7d30a- Build definition
- Community descriptor