Expand description
A query to compute the average of an integer property across
documents using CountSumTree / ProvableCountProvableSumTree
(PCPS) elements. Averages are NOT computed server-side; the
response carries a (count, sum) pair (atomic per group) and the
client divides. See book/src/drive/average-index-examples.md for
the worked example contract.
DriveDocumentAverageQuery — Drive’s average-query surface.
Parallels crate::query::drive_document_sum_query for the
averaging surface. Averages are NOT computed server-side: every
response carries a (count, sum) pair (atomic per group), and the
client divides to obtain the average. This preserves full
precision and lets callers pick their own representation
(integer-truncated, floating-point, decimal); pre-dividing on the
server would force a choice that loses information.
The grovedb primitive backing this is AggregateCountAndSumOnRange
(added in grovedb PR 670 alongside the ProvableCountProvableSumTree
/ PCPS element variant) — one root-hash-committed traversal returns
both metrics together. See
book/src/drive/average-index-examples.md
for the design and the grades-contract worked example.
Wired end-to-end: the dispatcher routes prove-true requests to the
PCPS / primary-key proof executors, and prove-false requests to the
joint single-walk count-and-sum dispatcher at
crate::query::drive_document_count_and_sum_query. Both paths
read (count, sum) from each visited count-sum-bearing element in
a single grovedb walk — see the
drive_dispatcher module docstring for the
routing details and
crate::query::drive_document_count_and_sum_query for the
no-prove perf / atomicity contract.
Modules§
- drive_
dispatcher - Average-query dispatcher entry point.
Structs§
- Average
Entry - A single per-key average entry. Carries BOTH count and sum so the client can divide; the server intentionally doesn’t pre-divide (see the module docstring).
- Document
Average Request - Server-side request input for the average dispatcher. Mirrors
crate::query::drive_document_sum_query::DocumentSumRequest— same fields, same semantics; the response carries(count, sum)pairs instead of a single sum.
Enums§
- Average
Mode - What kind of average-query the dispatcher should run. Parallels
crate::query::drive_document_sum_query::SumMode. - Document
Average Response - Server-side response from the average dispatcher. Parallels
crate::query::drive_document_sum_query::DocumentSumResponse— same outer shape; theAggregateandEntriespayloads carry(count, sum)instead of justsum.