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

AggregationCanonical syntaxDefault result key
Total / SumDISTILL FROM staff TOTAL age"total"
Sum (alias)DISTILL FROM staff SUM age"sum"
AverageDISTILL FROM staff AVERAGE age"average"
Average (short)DISTILL FROM staff AVG age"avg"
MinimumDISTILL FROM staff MIN age"min"
MaximumDISTILL 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 age

Returns 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 age

Returns: {"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 age

Returns: {"min": 24, "max": 35, "spread": 11}.