pub fn resolve_time_range_bucket_clause(
field: &str,
selector: TimeRangeSelector,
grid: Option<TimeRangeGridSpec>,
document_type: DocumentTypeRef<'_>,
block_time_ms: u64,
) -> Result<(WhereClause, ResolvedTimeRange), Error>Expand description
Resolves a time-range selection on field into a concrete equality
WhereClause on the bucketed source field, using the named grid’s
timeRange transform and an authoritative block_time_ms.
For the relative selectors the server supplies block_time_ms from
current block time and the verifier re-derives it from the quorum-signed
response metadata time_ms, so both produce the identical concrete
equality query — the existing index/count proofs apply unchanged and the
engine never needs a dedicated time-range operator. A
TimeRangeSelector::ByStart selection reads its start from the query
itself (validated to lie on the grid) and consults block_time_ms only
to reject windows past a declared ttl’s horizon — a window that may be
mid-drainage must not serve a truncated answer, and since drainage only
touches expired buckets, every window this resolver admits is complete.
grid selects among several time-range indexes on the same field: None
is accepted only while exactly one grid buckets the field (the common
case); with two or more grids the caller must name one, and naming a grid
no index declares is an error either way.
What comes back is an ordinary equality clause, byte-identical to one a
client could have written by hand against a raw timestamp, plus the
ResolvedTimeRange provenance callers must record on the query (see
DriveDocumentQuery::resolved_time_ranges), which
DriveDocumentQuery::find_best_index and the aggregate index pickers
consume through index_admissible_for_resolved_time_range to pin
selection to the grid’s index — and to keep raw queries off it.