-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathq11.sql
30 lines (27 loc) · 1.19 KB
/
q11.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- -------------------------------------------------------------------------------------------------
-- Query 11: User Sessions (Not in original suite)
-- -------------------------------------------------------------------------------------------------
-- How many bids did a user make in each session they were active? Illustrates session windows.
--
-- Group bids by the same user into sessions with max session gap.
-- Emit the number of bids per session.
-- -------------------------------------------------------------------------------------------------
-- A feasible implementation of this query would be to classify each bidder's information in the
-- source function, then create individual sessions, and then invoke the worker function to do
-- query processing on each session.
CREATE TABLE discard_sink (
bidder BIGINT,
bid_count BIGINT,
starttime TIMESTAMP(3),
endtime TIMESTAMP(3)
) WITH (
'connector' = 'blackhole'
);
INSERT INTO discard_sink
SELECT
B.bidder,
count(*) as bid_count,
SESSION_START(B.dateTime, INTERVAL '10' SECOND) as starttime,
SESSION_END(B.dateTime, INTERVAL '10' SECOND) as endtime
FROM bid B
GROUP BY B.bidder, SESSION(B.dateTime, INTERVAL '10' SECOND);