Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions website/src/pages/en/subgraphs/cookbook/timeseries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Timeseries and aggregations reduce data processing overhead and accelerate queri

## How to Implement Timeseries and Aggregations

### Prerequisites

You need `spec version 1.1.0` for this feature.

### Defining Timeseries Entities

A timeseries entity represents raw data points collected over time. It is defined with the `@entity(timeseries: true)` annotation. Key requirements:
Expand All @@ -51,7 +55,7 @@ Example:
type Data @entity(timeseries: true) {
id: Int8!
timestamp: Timestamp!
price: BigDecimal!
amount: BigDecimal!
}
```

Expand All @@ -68,11 +72,11 @@ Example:
type Stats @aggregation(intervals: ["hour", "day"], source: "Data") {
id: Int8!
timestamp: Timestamp!
sum: BigDecimal! @aggregate(fn: "sum", arg: "price")
sum: BigDecimal! @aggregate(fn: "sum", arg: "amount")
}
```

In this example, Stats aggregates the price field from Data over hourly and daily intervals, computing the sum.
In this example, Stats aggregates the amount field from Data over hourly and daily intervals, computing the sum.

### Querying Aggregated Data

Expand Down
Loading