mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-06-01 04:40:39 +00:00
chore: better column schema check for flow (#4855)
* chore: better column schema check for flow * chore: better msg * tests: clean up after tests * chore: better msg * chore: per review * tests: sqlness
This commit is contained in:
@@ -79,6 +79,7 @@ admin flush_flow('test_distinct_basic');
|
||||
INSERT INTO
|
||||
distinct_basic
|
||||
VALUES
|
||||
(20, "2021-07-01 00:00:00.200"),
|
||||
(20, "2021-07-01 00:00:00.200"),
|
||||
(22, "2021-07-01 00:00:00.600");
|
||||
|
||||
@@ -405,14 +406,15 @@ CREATE TABLE ngx_distribution (
|
||||
bucket_size INT,
|
||||
total_logs BIGINT,
|
||||
time_window TIMESTAMP TIME INDEX,
|
||||
update_at TIMESTAMP, -- auto generated column by flow engine
|
||||
-- auto generated column by flow engine
|
||||
update_at TIMESTAMP,
|
||||
PRIMARY KEY(stat, bucket_size)
|
||||
);
|
||||
|
||||
CREATE FLOW calc_ngx_distribution SINK TO ngx_distribution AS
|
||||
SELECT
|
||||
stat,
|
||||
trunc(size, -1)::INT as bucket_size,
|
||||
trunc(size, -1) :: INT as bucket_size,
|
||||
count(client) AS total_logs,
|
||||
date_bin(INTERVAL '1 minutes', access_time) as time_window,
|
||||
FROM
|
||||
@@ -461,3 +463,49 @@ DROP FLOW calc_ngx_distribution;
|
||||
DROP TABLE ngx_access_log;
|
||||
|
||||
DROP TABLE ngx_distribution;
|
||||
|
||||
CREATE TABLE requests (
|
||||
service_name STRING,
|
||||
service_ip STRING,
|
||||
val INT,
|
||||
ts TIMESTAMP TIME INDEX
|
||||
);
|
||||
|
||||
CREATE TABLE requests_without_ip (
|
||||
service_name STRING,
|
||||
val INT,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
);
|
||||
|
||||
CREATE FLOW requests_long_term SINK TO requests_without_ip AS
|
||||
SELECT
|
||||
service_name,
|
||||
val,
|
||||
ts
|
||||
FROM
|
||||
requests;
|
||||
|
||||
INSERT INTO
|
||||
requests
|
||||
VALUES
|
||||
("svc1", "10.0.0.1", 100, "2024-10-18 19:00:00"),
|
||||
("svc1", "10.0.0.2", 100, "2024-10-18 19:00:00"),
|
||||
("svc1", "10.0.0.1", 200, "2024-10-18 19:00:30"),
|
||||
("svc1", "10.0.0.2", 200, "2024-10-18 19:00:30"),
|
||||
("svc1", "10.0.0.1", 300, "2024-10-18 19:01:00"),
|
||||
("svc1", "10.0.0.2", 100, "2024-10-18 19:01:01"),
|
||||
("svc1", "10.0.0.1", 400, "2024-10-18 19:01:30"),
|
||||
("svc1", "10.0.0.2", 200, "2024-10-18 19:01:31");
|
||||
|
||||
admin flush_flow('requests_long_term');
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
requests_without_ip;
|
||||
|
||||
DROP FLOW requests_long_term;
|
||||
|
||||
DROP TABLE requests_without_ip;
|
||||
|
||||
DROP TABLE requests;
|
||||
Reference in New Issue
Block a user