Expand description
HAVING clause types for the v1 getDocuments count surface.
HAVING differs from WHERE in two structural ways the type system needs to reflect:
- The left operand is a per-group aggregate (
COUNT(*),SUM(field),AVG(field)) rather than a raw row field. - The right operand is either a concrete value (
> 5,BETWEEN 5 AND 10,IN (5, 10, 15)) or a cross-group ranking (EQ MAX,IN TOP(5),> MIN). The ranking right-operands (MIN/MAX/TOP(N)/BOTTOM(N)) are meta-aggregates computed over the set of group results, soHAVING COUNT(*) IN TOP(5)reads as “this group’s count is among the five largest group counts” — a concise way to express top-N/bottom-N selection without window functions orORDER BY+LIMIT.
The operator set matches crate::query::WhereOperator minus
STARTS_WITH (prefix matching has no meaning on a scalar
aggregate result, even one that’s a string): scalar comparison,
IN, and all four BETWEEN* variants all carry through.
Multi-clause HAVING (HAVING COUNT(*) > 5 AND SUM(amount) > 100)
is expressed by repeating HavingClause at the request
level — implicit AND, same shape as multiple where_clauses
entries.
These types are shared between the wire-decoding layer
(rs-drive-abci/src/query/document_query/v1/conversions.rs)
and the SDK’s request builder
(rs-sdk/src/platform/documents/document_query.rs) so the
drive-side struct is the single source of truth for the shape.
The server currently rejects any non-empty having with
QuerySyntaxError::Unsupported("HAVING clause is not yet implemented") — the types exist so the wire surface is stable
when execution lands.
Structs§
- Having
Aggregate - Aggregate operand for the left side of a
HavingClause. SeeHavingAggregateFunctionfor the per-functionfieldrequirements (empty only forCOUNT(*)). - Having
Clause - Single
HAVING <aggregate> <op> <right>clause. - Having
Ranking - Cross-group ranking operand:
kindplus an optionaln(only meaningful forHavingRankingKind::Top/HavingRankingKind::Bottom).
Enums§
- Having
Aggregate Function - Aggregate function applied to a group on the left side of a
HavingClause. These are the per-group aggregates whose result is the scalar / numeric value the right-side operand compares against. - Having
Operator - Comparison operator for a
HavingClause. Mirrorscrate::query::WhereOperatorminusSTARTS_WITH(prefix matching has no natural meaning against a scalar aggregate result, even a string-typed one).BETWEEN*operand semantics matchWhereOperator: a 2-element list[lower, upper];INexpects a list of candidate values (or a cross-group ranking set viaHavingRightOperand::Ranking). - Having
Ranking Kind - Cross-group ranking primitive on the right side of a
HavingClause. The ranking is computed over the set of group results (one per row produced byGROUP BY), not over the raw rows — soHAVING COUNT(*) EQ MAXselects groups whose count equals the maximum count across all groups. - Having
Right Operand - Right-side operand of a
HavingClause. Either a concrete value (literal scalar or list-shaped operand forBETWEEN*/IN) or a cross-group ranking reference (HavingRanking).