Skip to main content

drive/query/drive_document_having_query/mode_detection/
mod.rs

1//! Request-shape validation for the having-range query, and the versioned
2//! `(select, group_by, having, order_by, limit)` → [`DocumentHavingMode`]
3//! resolution — including the operator → inclusive-bounds translation
4//! that turns a `HAVING <agg> <op> <value>` clause into an
5//! [`AxisRangeBounds`].
6//!
7//! Pure functions on the request shape — no Drive, no contract, no
8//! indexes. Available under `server` and `verify` for the same reason as
9//! [`super::super::drive_document_ranked_query::mode_detection`]: both
10//! sides must agree on which requests are well-formed and on the exact
11//! bounds a well-formed one resolves to, because the verifier rebuilds
12//! the bounded traversal from those bounds and re-executes the proof
13//! against it.
14//!
15//! Versioned through
16//! `platform_version.drive.methods.document.query.detect_having_mode` —
17//! the accepted grammar is a consensus-adjacent contract on the query
18//! surface, so relaxing it later (multi-clause `HAVING`, `IN`, a
19//! pagination cursor) lands behind a method-version bump.
20
21use super::super::drive_document_ranked_query::RankedPaginationInputs;
22use super::{AxisRangeBounds, DocumentHavingMode, MAX_HAVING_LIMIT};
23use crate::error::query::QuerySyntaxError;
24use crate::error::Error;
25use crate::query::having::HavingClause;
26use crate::query::projection::SelectProjection;
27use crate::query::{OrderClause, WhereClause};
28use dpp::version::PlatformVersion;
29
30/// Versioned entry point. Routes through
31/// `platform_version.drive.methods.document.query.detect_having_mode`;
32/// today only `0` is defined and maps to [`detect_having_mode_v0`]
33/// verbatim.
34#[allow(clippy::too_many_arguments)]
35pub fn detect_having_mode(
36    select: &SelectProjection,
37    group_by: &[String],
38    having: &[HavingClause],
39    order_by: &[OrderClause],
40    where_clauses: &[WhereClause],
41    pagination: RankedPaginationInputs,
42    platform_version: &PlatformVersion,
43) -> Result<DocumentHavingMode, Error> {
44    match platform_version
45        .drive
46        .methods
47        .document
48        .query
49        .detect_having_mode
50    {
51        0 => detect_having_mode_v0(
52            select,
53            group_by,
54            having,
55            order_by,
56            where_clauses,
57            pagination,
58        ),
59        version => Err(Error::Query(QuerySyntaxError::Unsupported(format!(
60            "detect_having_mode: unknown method version {version}; only 0 is supported"
61        )))),
62    }
63}
64
65mod v0;
66// Re-exported so the dispatcher's callers (`drive_dispatcher`, the
67// test suites) keep addressing the frozen grammar by its old path.
68pub use v0::detect_having_mode_v0;