Skip to content

A cross-row aggregation into a summary entity

When you need this

"Count / sum / average many rows on a schedule and store the result." A nightly inventory reconciliation, per-asset maintenance-cost totals, seats-used per licence. Zero Java — one entity_aggregation_config row run by engine-entity.aggregation-sweep.

The file

metadata/seed-data/office-equipment-aggregation-configs.json (real file):

json
{
  "entity": "entity_aggregation_config",
  "keyFields": ["sweep_code"],
  "source": "office-equipment",
  "rows": [
    {
      "sweep_code": "equipment-status-reconciliation",
      "source_entity": "oeq_equipment",
      "aggregation": "count",
      "group_by_field": "status",
      "target_entity": "oeq_reconciliation",
      "target_key_field": "metric_key",
      "target_key_prefix": "equipment_status:",
      "target_value_field": "metric_value",
      "target_timestamp_field": "last_reconciled_at",
      "active": true
    }
  ]
}

Result: one oeq_reconciliation row per status, keyed equipment_status:AVAILABLE, equipment_status:ASSIGNED, … with the count in metric_value.

Variants

  • sum / avg / min / max — add agg_field (the numeric column).
  • Write onto the parent row instead of a summary entity — set target_key_field: "id", leave target_key_prefix blank; the group_by_field values are the parent's primary keys. (E.g. sum line-item cost onto the maintenance record's own synced_cost.)
  • Filter first — add status_field + when_status_in.

Also ship

  • metadata/entities/oeq_reconciliation.json (the summary entity), and the shared entity_aggregation_config.json (additive).
  • metadata/rules/ensure_aggregation_sweep_job_registered.json — an AFTER_CREATE EXECUTE_SERVICE rule calling ensureEntityAggregationSweepJobRegistered (this job does not self-register from a platform rule — you ship it).