Skip to main content

compute_aggregate_mode_and_check_limit

Function compute_aggregate_mode_and_check_limit 

Source
pub fn compute_aggregate_mode_and_check_limit(
    select: &SelectProjection,
    group_by: &[String],
    where_clauses: &[WhereClause],
    order_by: &[OrderClause],
    limit: Option<u32>,
    having: &[HavingClause],
    function_name: &str,
    platform_version: &PlatformVersion,
) -> Result<AggregateRouting, Error>
Expand description

Decide how a SELECT COUNT / SUM / AVG request executes.

All three aggregate functions share the same SQL-shape contract (empty group_by → Aggregate; one-field group_by → GroupByIn or GroupByRange depending on whether the field is In-bound or range-bound; two-field group_by (in_field, range_field) → GroupByCompound). The function_name arg (“COUNT” / “SUM” / “AVG”) is woven into rejection messages for clarity.

On the grouped path it also runs the accepts_limit() check: Aggregate and GroupByIn can’t honor a caller-supplied limit and reject with QuerySyntaxError::InvalidLimit if one is set. The ranked path deliberately does not check limit here — on that path limit is the ranking’s k, and drive owns both its mandatoriness and its 1 ..= 100 bound; duplicating those rules at the routing layer would mean two error messages for one contract.

Routes through platform_version.drive_abci.query.document_query_helpers.compute_aggregate_mode_and_check_limit.