/ crates / arroyo-sql-testing / src / test / queries / most_active_driver_last_hour_unaligned.sql
most_active_driver_last_hour_unaligned.sql
 1  --fail=Error during planning: hop() width 3600s currently must be a multiple of slide 2400s
 2  CREATE TABLE cars (
 3    timestamp TIMESTAMP,
 4    driver_id BIGINT,
 5    event_type TEXT,
 6    location TEXT
 7  ) WITH (
 8    connector = 'single_file',
 9    path = '$input_dir/cars.json',
10    format = 'json',
11    type = 'source',
12    event_time_field = 'timestamp'
13  );
14  CREATE TABLE most_active_driver (
15    driver_id BIGINT,
16    count BIGINT,
17    start TIMESTAMP,
18    end TIMESTAMP,
19    row_number BIGINT
20  ) WITH (
21    connector = 'single_file',
22    path = '$output_path',
23    format = 'json',
24    type = 'sink'
25  );
26  INSERT INTO most_active_driver
27  SELECT driver_id, count, window.start, window.end, row_number FROM (
28    SELECT *, ROW_NUMBER()  OVER (
29      PARTITION BY window
30      ORDER BY count DESC, driver_id desc) as row_number
31    FROM (
32        SELECT driver_id, count, window FROM (
33    SELECT driver_id,
34    hop(INTERVAL '40' minute, INTERVAL '1' hour ) as window,
35           count(*) as count
36           FROM cars
37           GROUP BY 1,2)) ) where row_number = 1