mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-09 06:42:57 +00:00
* fix: handle flow inserts with default values * test: sqlness * chore: typo * chore: newline * feat(WIP): impure default filler * feat: fill impure default values * test: add test for default fill impure * feat: check for impure * fix: also handle stmt to region * refactor: per review * refactor: per review * chore: rebase fix * chore: clippy * chore: per review
42 lines
824 B
SQL
42 lines
824 B
SQL
CREATE TABLE bytes_log (
|
|
byte INT,
|
|
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
-- event time
|
|
TIME INDEX(ts)
|
|
);
|
|
|
|
CREATE TABLE approx_rate (
|
|
rate DOUBLE,
|
|
time_window TIMESTAMP,
|
|
update_at TIMESTAMP,
|
|
TIME INDEX(time_window)
|
|
);
|
|
|
|
CREATE FLOW find_approx_rate SINK TO approx_rate AS
|
|
SELECT
|
|
(max(byte) - min(byte)) / 30.0 as rate,
|
|
date_bin(INTERVAL '30 second', ts) as time_window
|
|
from
|
|
bytes_log
|
|
GROUP BY
|
|
time_window;
|
|
|
|
INSERT INTO
|
|
bytes_log (byte)
|
|
VALUES
|
|
(NULL),
|
|
(300);
|
|
|
|
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
|
|
ADMIN FLUSH_FLOW('find_approx_rate');
|
|
|
|
-- since ts is default to now(), omit it when querying
|
|
SELECT
|
|
rate
|
|
FROM
|
|
approx_rate;
|
|
|
|
DROP FLOW find_approx_rate;
|
|
DROP TABLE bytes_log;
|
|
DROP TABLE approx_rate;
|