Skip to main content

Module having

Module having 

Source
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, so HAVING 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 or ORDER 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§

HavingAggregate
Aggregate operand for the left side of a HavingClause. See HavingAggregateFunction for the per-function field requirements (empty only for COUNT(*)).
HavingClause
Single HAVING <aggregate> <op> <right> clause.
HavingRanking
Cross-group ranking operand: kind plus an optional n (only meaningful for HavingRankingKind::Top / HavingRankingKind::Bottom).

Enums§

HavingAggregateFunction
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.
HavingOperator
Comparison operator for a HavingClause. Mirrors crate::query::WhereOperator minus STARTS_WITH (prefix matching has no natural meaning against a scalar aggregate result, even a string-typed one). BETWEEN* operand semantics match WhereOperator: a 2-element list [lower, upper]; IN expects a list of candidate values (or a cross-group ranking set via HavingRightOperand::Ranking).
HavingRankingKind
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 by GROUP BY), not over the raw rows — so HAVING COUNT(*) EQ MAX selects groups whose count equals the maximum count across all groups.
HavingRightOperand
Right-side operand of a HavingClause. Either a concrete value (literal scalar or list-shaped operand for BETWEEN*/IN) or a cross-group ranking reference (HavingRanking).