From 0a1ad3f509c9109c56f56e2fe9e02dfa3801e037 Mon Sep 17 00:00:00 2001 From: Smitty Date: Tue, 6 Dec 2022 09:33:03 -0500 Subject: [PATCH] Add another test for timeline_agg --- docs/state_agg.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/state_agg.md b/docs/state_agg.md index 82551e83b..5ab877ce1 100644 --- a/docs/state_agg.md +++ b/docs/state_agg.md @@ -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 @@ -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") +```