Skip to main content

Aggregation Queries

Aggregation queries compute summary values (averages, totals, extremes) across time-series data points instead of returning individual rows. Use these when you need calculated metrics rather than raw data — for example, the average voltage over the last hour or the total energy produced per machine.

OctoMesh supports two aggregation query types:

  • Aggregation Query — computes aggregated values across all matching data points
  • Grouped Aggregation Query — computes aggregated values grouped by one or more columns (similar to SQL GROUP BY)

Aggregation Types​

TypeDescriptionExample
AVGAverage valueAverage voltage over a time range
MINMinimum valueLowest temperature reading
MAXMaximum valuePeak power consumption
COUNTNumber of data pointsNumber of measurements recorded
SUMSum of valuesTotal energy produced

Aggregation Query​

The aggregation query computes a single aggregated result across all matching data points. Use the transientStreamDataAggregationQuery field.

Basic Usage​

query {
streamData {
transientStreamDataAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG },
{ attributePath: "voltage", aggregationType: MIN },
{ attributePath: "voltage", aggregationType: MAX }
]
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Response:

{
"data": {
"streamData": {
"transientStreamDataAggregationQuery": {
"totalCount": 1,
"items": [
{
"cells": {
"items": [
{ "attributePath": "Avg_voltage", "value": 230.4 },
{ "attributePath": "Min_voltage", "value": 218.7 },
{ "attributePath": "Max_voltage", "value": 242.1 }
]
}
}
]
}
}
}
}

The result contains a single row with one cell per aggregation column. The attributePath in the response is prefixed with the aggregation type (e.g., Avg_voltage, Min_voltage).

Parameters​

ParameterTypeRequiredDescription
ckIdString!YesThe CK type to query
columnPaths[StreamDataQueryColumnInput!]!YesColumns with aggregation type
argStreamDataArgumentsNoTime range and limit overrides
fieldFilter[FieldFilter]NoField-level comparison filters
rtIds[OctoObjectId]NoScope to specific runtime entity IDs
firstIntNoMaximum number of items to return
afterStringNoPagination cursor

StreamDataQueryColumnInput​

Each column specifies the attribute to aggregate and the aggregation function to apply:

FieldTypeRequiredDescription
attributePathString!YesThe data stream attribute to aggregate
aggregationTypeAggregationType!YesAVG, MIN, MAX, COUNT, or SUM

With Time Range and Entity Filter​

query {
streamData {
transientStreamDataAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG },
{ attributePath: "power", aggregationType: SUM }
]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
}
rtIds: ["65dc6d24cc529cdc46c84fcc"]
) {
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Counting Data Points​

Use COUNT to determine how many data points exist for a given attribute:

query {
streamData {
transientStreamDataAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: [
{ attributePath: "voltage", aggregationType: COUNT }
]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
}
) {
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Grouped Aggregation Query​

A grouped aggregation query computes aggregated values grouped by one or more columns — equivalent to a SQL GROUP BY clause. Use the transientStreamDataGroupedAggregationQuery field.

Basic Usage​

This example computes the average voltage per entity:

query {
streamData {
transientStreamDataGroupedAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
groupByColumnPaths: ["rtId"]
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG },
{ attributePath: "power", aggregationType: MAX }
]
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

Response:

{
"data": {
"streamData": {
"transientStreamDataGroupedAggregationQuery": {
"totalCount": 3,
"items": [
{
"cells": {
"items": [
{ "attributePath": "rtId", "value": "65dc6d24cc529cdc46c84fcc" },
{ "attributePath": "Avg_voltage", "value": 230.4 },
{ "attributePath": "Max_power", "value": 1580.0 }
]
}
},
{
"cells": {
"items": [
{ "attributePath": "rtId", "value": "65dc6d24cc529cdc46c84fcd" },
{ "attributePath": "Avg_voltage", "value": 228.9 },
{ "attributePath": "Max_power", "value": 1620.5 }
]
}
},
{
"cells": {
"items": [
{ "attributePath": "rtId", "value": "65dc6d24cc529cdc46c84fce" },
{ "attributePath": "Avg_voltage", "value": 231.2 },
{ "attributePath": "Max_power", "value": 1490.3 }
]
}
}
]
}
}
}
}

Each row in the result represents one group. The grouping column values appear in the cells alongside the aggregated values.

Parameters​

ParameterTypeRequiredDescription
ckIdString!YesThe CK type to query
groupByColumnPaths[String!]!YesAttribute paths to group by
columnPaths[StreamDataQueryColumnInput!]!YesColumns with aggregation type
argStreamDataArgumentsNoTime range and limit overrides
fieldFilter[FieldFilter]NoField-level comparison filters
rtIds[OctoObjectId]NoScope to specific runtime entity IDs
firstIntNoMaximum number of items to return
afterStringNoPagination cursor

Grouping by Multiple Columns​

You can group by more than one column. This example groups by both entity and CK type:

query {
streamData {
transientStreamDataGroupedAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
groupByColumnPaths: ["rtId", "ckTypeId"]
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG }
]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
}
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

With Filters​

Filters are applied before aggregation, limiting which data points are included in the calculation:

query {
streamData {
transientStreamDataGroupedAggregationQuery(
ckId: "Industry.Energy/EnergyMeter"
groupByColumnPaths: ["rtId"]
columnPaths: [
{ attributePath: "voltage", aggregationType: AVG }
]
fieldFilter: [
{ attributePath: "voltage", operator: GREATER_THAN, comparisonValue: 0 }
]
) {
totalCount
items {
cells {
items {
attributePath
value
}
}
}
}
}
}

This computes the average voltage per entity, but only considering data points where the voltage is greater than zero.


Use Cases​

ScenarioQuery TypeExample
Overall average for a KPI widgetAggregationAverage temperature across all sensors
Per-machine production totalsGrouped AggregationTotal output grouped by rtId
Data quality checkAggregation with COUNTCount of readings in a time range
Comparison dashboardGrouped AggregationMin/max/avg per entity for side-by-side display