Files
greptimedb/tests/cases/standalone/common/flow/flow_blog.sql
discord9 35898f0b2e test: more sqlness tests for flow (#4988)
* tests: more flow testcase

* tests(WIP): more tests

* tests: more flow tests

* test: wired regex for sqlness

* refactor: put blog&example to two files
2024-11-14 07:40:14 +00:00

65 lines
1.3 KiB
SQL

-- blog usecase
CREATE TABLE velocity (
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
left_wheel FLOAT,
right_wheel FLOAT,
TIME INDEX(ts)
);
CREATE TABLE avg_speed (
avg_speed DOUBLE,
start_window TIMESTAMP TIME INDEX,
end_window TIMESTAMP,
update_at TIMESTAMP,
);
CREATE FLOW calc_avg_speed SINK TO avg_speed AS
SELECT
avg((left_wheel + right_wheel) / 2)
FROM
velocity
WHERE
left_wheel > 0.5
AND right_wheel > 0.5
AND left_wheel < 60
AND right_wheel < 60
GROUP BY
tumble(ts, '5 second');
INSERT INTO
velocity
VALUES
("2021-07-01 00:00:00.200", 0.0, 0.7),
("2021-07-01 00:00:00.200", 0.0, 61.0),
("2021-07-01 00:00:02.500", 2.0, 1.0,);
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_avg_speed');
SELECT
avg_speed,
start_window
FROM
avg_speed;
INSERT INTO
velocity
VALUES
("2021-07-01 00:00:05.100", 5.0, 4.0),
("2021-07-01 00:00:09.600", 2.3, 2.1);
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_avg_speed');
SELECT
avg_speed,
start_window
FROM
avg_speed;
DROP FLOW calc_avg_speed;
DROP TABLE velocity;
DROP TABLE avg_speed;