Skip to content

Commit

Permalink
Add another test for timeline_agg
Browse files Browse the repository at this point in the history
  • Loading branch information
syvb committed Dec 6, 2022
1 parent da065bb commit 1aa764b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/state_agg.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ INSERT INTO states_test_4 VALUES
('2020-01-01 00:01:00+00', 2),
('2020-01-01 00:01:03+00', 51351),
('2020-01-01 00:02:00+00', -9);
CREATE TABLE states_test_5(ts TIMESTAMPTZ, state BIGINT);
INSERT INTO states_test_5 VALUES
('2020-01-01 00:00:00+00', 4),
('2020-01-01 00:00:11+00', 51351),
('2020-01-01 00:01:00+00', 2),
('2020-01-01 00:02:03+00', 51351),
('2020-01-01 00:02:05+00', -9);
```

## Functions
Expand Down Expand Up @@ -418,3 +425,23 @@ FROM buckets;
(OK,"2020-01-01 00:00:11+00","2020-01-01 00:02:00+00")
(STOP,"2020-01-01 00:02:00+00","2020-01-01 00:02:00+00")
```

```SQL
WITH buckets AS (SELECT
date_trunc('minute', ts) as dt,
toolkit_experimental.timeline_agg(ts, state) AS sa
FROM states_test_5
GROUP BY date_trunc('minute', ts)
HAVING date_trunc('minute', ts) != '2020-01-01 00:01:00+00'::timestamptz)
SELECT toolkit_experimental.state_int_timeline(
toolkit_experimental.rollup(buckets.sa)
)
FROM buckets;
```
```output
state_timeline
-----------------------------------------------------------
(4,"2020-01-01 00:00:00+00","2020-01-01 00:00:11+00")
(51351,"2020-01-01 00:00:11+00","2020-01-01 00:02:05+00")
(-9,"2020-01-01 00:02:05+00","2020-01-01 00:02:05+00")
```

0 comments on commit 1aa764b

Please sign in to comment.