Getting Started
Tutorial: Building with CleaveDB
Sum, Avg, Min, Max & Spread
The DISTILL command provides built-in statistical and mathematical reduction functions that operate directly across numeric fields stored in a bucket.
Supported mathematical functions
| Aggregation | Canonical syntax | Default result key |
|---|---|---|
| Total / Sum | DISTILL FROM staff TOTAL age | "total" |
| Sum (alias) | DISTILL FROM staff SUM age | "sum" |
| Average | DISTILL FROM staff AVERAGE age | "average" |
| Average (short) | DISTILL FROM staff AVG age | "avg" |
| Minimum | DISTILL FROM staff MIN age | "min" |
| Maximum | DISTILL FROM staff MAX age | "max" |
| Spread (max − min) | DISTILL FROM staff SPREAD age | "spread" |
Total and Sum examples
Both TOTAL and SUM sum numeric values. The key returned in the output JSON matches the keyword you invoked:
CleaveQLExample · Compute total sum
DISTILL FROM staff TOTAL ageReturns a single JSON object: {"total": 119.0}.
Average calculations
CleaveDB supports conversational forms (AVERAGE OF age, AVERAGE age) or the concise AVG age:
CleaveQLExample · Compute arithmetic mean
DISTILL FROM staff AVERAGE OF ageReturns: {"average": 29.75}.
Minimum, Maximum, and Spread
SPREAD calculates the difference between the highest and lowest values (max − min) in a single pass:
CleaveQLExample · Extremes and spread
DISTILL FROM staff MIN age, MAX age, SPREAD ageReturns: {"min": 24, "max": 35, "spread": 11}.
