Skip to content

Commit

Permalink
Add analytics tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmp85 committed May 15, 2024
1 parent 8d27e83 commit e11ca55
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
32 changes: 30 additions & 2 deletions test/expected/basic_usage.out
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,15 @@ SELECT COUNT(*) < 10 AS fewer_partitions FROM ts_part_info;
CREATE TABLE events (
user_id bigint,
event_id bigint,
event_time timestamptz,
event_time timestamptz NOT NULL,
value float
);
) PARTITION BY RANGE (event_time);
SELECT enable_ts_table('events');
enable_ts_table
-----------------

(1 row)

COPY events FROM STDIN WITH (FORMAT 'csv');
SELECT first(value, event_time), user_id FROM events GROUP BY user_id;
first | user_id
Expand Down Expand Up @@ -172,3 +178,25 @@ SELECT last(event_id, event_time), user_id FROM events GROUP BY user_id;
6 | 1
(2 rows)

SELECT last(user_id, value) top_performer,
locf(avg(value)) OVER (ORDER BY event_time),
event_time
FROM date_bin_table(NULL::events, '1 minute',
'[2020-11-04 15:50:00-08, 2020-11-04 16:00:00-08]')
GROUP BY 3
ORDER BY 3;
top_performer | locf | event_time
---------------+--------------------+------------------------------
| | Wed Nov 04 15:50:00 2020 PST
2 | 1.4 | Wed Nov 04 15:51:00 2020 PST
| 1.4 | Wed Nov 04 15:52:00 2020 PST
2 | 1.5 | Wed Nov 04 15:53:00 2020 PST
| 1.5 | Wed Nov 04 15:54:00 2020 PST
2 | 1.6 | Wed Nov 04 15:55:00 2020 PST
| 1.6 | Wed Nov 04 15:56:00 2020 PST
2 | 1.7 | Wed Nov 04 15:57:00 2020 PST
2 | 1.8 | Wed Nov 04 15:58:00 2020 PST
2 | 1.9000000000000001 | Wed Nov 04 15:59:00 2020 PST
| 1.9000000000000001 | Wed Nov 04 16:00:00 2020 PST
(11 rows)

25 changes: 17 additions & 8 deletions test/sql/basic_usage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,21 @@ SELECT COUNT(*) < 10 AS fewer_partitions FROM ts_part_info;
CREATE TABLE events (
user_id bigint,
event_id bigint,
event_time timestamptz,
event_time timestamptz NOT NULL,
value float
);
) PARTITION BY RANGE (event_time);
SELECT enable_ts_table('events');

COPY events FROM STDIN WITH (FORMAT 'csv');
1,1,"2020-11-04 15:54:02.226999-08",1.1
1,2,"2020-11-04 15:55:02.226999-08",1.2
1,3,"2020-11-04 15:56:02.226999-08",1.3
1,1,"2020-11-04 15:51:02.226999-08",1.1
1,2,"2020-11-04 15:53:02.226999-08",1.2
1,3,"2020-11-04 15:55:02.226999-08",1.3
1,4,"2020-11-04 15:57:02.226999-08",1.4
1,5,"2020-11-04 15:58:02.226999-08",1.5
1,6,"2020-11-04 15:59:02.226999-08",1.6
2,7,"2020-11-04 15:54:02.226999-08",1.7
2,8,"2020-11-04 15:55:02.226999-08",1.8
2,9,"2020-11-04 15:56:02.226999-08",1.9
2,7,"2020-11-04 15:51:02.226999-08",1.7
2,8,"2020-11-04 15:53:02.226999-08",1.8
2,9,"2020-11-04 15:55:02.226999-08",1.9
2,10,"2020-11-04 15:57:02.226999-08",2.0
2,11,"2020-11-04 15:58:02.226999-08",2.1
2,12,"2020-11-04 15:59:02.226999-08",2.2
Expand All @@ -78,3 +79,11 @@ SELECT last(value, event_time), user_id FROM events GROUP BY user_id;
SELECT first(event_id, event_time), user_id FROM events GROUP BY user_id;

SELECT last(event_id, event_time), user_id FROM events GROUP BY user_id;

SELECT last(user_id, value) top_performer,
locf(avg(value)) OVER (ORDER BY event_time),
event_time
FROM date_bin_table(NULL::events, '1 minute',
'[2020-11-04 15:50:00-08, 2020-11-04 16:00:00-08]')
GROUP BY 3
ORDER BY 3;

0 comments on commit e11ca55

Please sign in to comment.