Getting Started
Tutorial: Building with CleaveDB
Filtering with WHERE
You often need to compute aggregate statistics over a subset of documents rather than an entire bucket. In CleaveQL, the WHERE clause accepts comparison operators (=, !=, >, <, >=, <=) connected with AND and OR.
Flexible WHERE positioning
In DISTILL queries, the WHERE clause can be positioned immediately after the bucket or placed at the end of the query:
CleaveQLExample · WHERE positioned after bucket
DISTILL FROM staff WHERE dept = "Eng" TOTAL ageOr placed after the aggregation function:
CleaveQLExample · WHERE positioned at the end
DISTILL FROM staff COUNT WHERE status = "active"Both styles execute identically in CleaveDB's AST compiler.
Numeric comparison filters
Filter numeric ranges before tallying or computing totals:
CleaveQLExample · Numeric filter
DISTILL FROM staff WHERE age > 25 COUNTThis counts only staff members whose age strictly exceeds 25.
Compound boolean logic (AND / OR)
Combine multiple criteria using standard boolean operators:
CleaveQLExample · Conjunctive condition with AND
DISTILL FROM staff WHERE dept = "Eng" AND age > 30 COUNTYou can also combine conditions using OR alongside aliases:
CleaveQLExample · Disjunctive condition with OR
DISTILL FROM staff WHERE dept = "Eng" OR age < 5 TALLY AS nThis tallies all qualifying documents and assigns the output key to "n".
