/ crates / arroyo-sql-testing / src / test / queries / reinvoke_window_function.sql
reinvoke_window_function.sql
 1  CREATE TABLE cars(
 2    timestamp TIMESTAMP,
 3    driver_id BIGINT,
 4    event_type TEXT,
 5    location TEXT
 6  ) WITH (
 7    connector = 'single_file',
 8    path = '$input_dir/cars.json',
 9    format = 'json',
10    type = 'source',
11    event_time_field = 'timestamp'
12  );
13  
14  CREATE TABLE output WITH (
15      connector = 'single_file',
16      path = '$output_path',
17      format = 'json',
18      type = 'sink'
19  );
20  INSERT INTO output 
21  SELECT window.start as start, window.end as end, drivers
22  FROM (
23  SELECT tumble(interval '1 hour') as window, count(distinct driver_id) as drivers
24  
25  FROM (
26      SELECT driver_id, count(*) as pickups
27      FROM cars where event_type = 'pickup'
28      GROUP BY 1,tumble(interval '1 hour') 
29  ) WHERE pickups > 2
30  GROUP BY 1);
31