Skip to main content

Statistics Query

Evidence status: API and intent-order review only. No current provider-backed result records totals, grouping/null behavior, numeric types, or an execution plan for this recipe.

Problem

Produce a dashboard count or distribution without loading rows and aggregating them in application memory.

Java Path

For a simple count:

Q.orders()
.filterByMerchant(ctx.getMerchant())
.count()
.comment("Count merchant orders")
.purpose("Display the order total on the dashboard")
.executeForList(ctx);

For a grouped distribution, use the group method generated for the field:

Q.orders()
.filterByMerchant(ctx.getMerchant())
.count()
.groupByOrderStatus()
.comment("Count merchant orders by status")
.purpose("Display the order status distribution")
.executeForList(ctx);

Verify exact count/group methods in generated source.

Verification

  • Seed a small dataset whose expected totals can be calculated by hand.
  • Confirm tenant, permission, date, and soft-delete constraints match the list page being summarized.
  • Test null or missing group values.
  • Confirm numeric types and rounding for sum/average operations.
  • Compare the generated statistic with a trusted database result during test.
  • Check execution plan and indexes for production-sized datasets.

When Not to Use This Shape

Use a reporting-specific path when the query requires database-specific features, large analytical scans, or a separately governed warehouse. Keep its scope, parameters, audit intent, and verification explicit.

References