Skip to main content

Module aggregation

Module aggregation 

Source
Expand description

Aggregation Execution Plan Module

This module generates execution plans for GROUP BY queries with aggregations.

§Execution Plan Flow

GraphQL Query
     ↓
AggregationRequest (parsed)
     ↓
AggregationPlan (validated, optimized)
     ↓
SQL Generation (database-specific)
     ↓
Query Execution

§Example

query {
  sales_aggregate(
    where: { customer_id: { _eq: "uuid-123" } }
    groupBy: { category: true, occurred_at_day: true }
    having: { revenue_sum_gt: 1000 }
  ) {
    category
    occurred_at_day
    count
    revenue_sum
    revenue_avg
  }
}

Generates:

SELECT
  data->>'category' AS category,
  DATE_TRUNC('day', occurred_at) AS occurred_at_day,
  COUNT(*) AS count,
  SUM(revenue) AS revenue_sum,
  AVG(revenue) AS revenue_avg
FROM tf_sales
WHERE customer_id = $1
GROUP BY data->>'category', DATE_TRUNC('day', occurred_at)
HAVING SUM(revenue) > $2

Structs§

AggregationPlan
Validated and optimized aggregation execution plan
AggregationPlanner
Aggregation plan generator
AggregationRequest
Aggregation request from GraphQL query
HavingCondition
HAVING condition (post-aggregation filter)
OrderByClause
ORDER BY clause
ValidatedHavingCondition
Validated HAVING condition

Enums§

AggregateExpression
Validated aggregate expression
AggregateSelection
Aggregate selection (what to compute)
GroupByExpression
Validated GROUP BY expression
GroupBySelection
GROUP BY selection
OrderDirection
Sort direction