Files
greptimedb/tests/cases/standalone/common/flow/flow_null.sql
Weny Xu 60852af5f8 chore: bump version to 0.13.2 (#5837)
* fix: mysql prepare bool value (#5732)

* fix: mysql prepare limit&offset param (#5734)

* fix: prepare limit&offset param

* test: sqlness

* chore: per review

* chore: per review

* fix: wrap table name with `` (#5748)

* fix: wrap table name with quotes

* fix: minor fix

* fix: handle nullable default value (#5747)

* fix: handle nullable default value

* chore: update sqlness

* fix: properly give placeholder types (#5760)

* fix: properly give placeholder types

* chore: update sqlness

* fix: support __name__ matcher in label values (#5773)

* fix: typo variadic (#5800)

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* fix: close issue #3902 since upstream fixed (#5801)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>

* fix: correct error status code (#5802)

* fix: interval cast expression can't work in range query, #5805 (#5813)

* fix: interval cast expression can't work in range query, #5805

* fix: nested cast

* test: make vector test stable

* feat: introduce poison mechanism for procedure  (#5822)

* feat: introduce poison for procedure

* tests: add unit tests

* refactor: minor refactor

* fix: unit tests

* chore: fix unit tests

* chore: apply suggestions from CR

* chore: apply suggestions from CR

* chore: update comments

* chore: introduce `ProcedureStatus::Poisoned`

* chore: upgrade greptime-proto to `2be0f`

* chore: apply suggestions from CR

* fix: throw errors instead of ignoring (#5792)

* fix: throw errors instead of ignoring

* fix: fix unit tests

* refactor: remove schema version check

* fix: fix clippy

* chore: remove unused error

* refactor: remove schema version check

* feat: handle mutliple results

* feat: introduce consistency guard

* fix: release consistency guard on datanode operation completion

* test: add tests

* chore: remove schema version

* refactor: rename

* test: add more tests

* chore: print all error

* tests: query table after alteration

* log ignored request

* refine fuzz test

* chore: fix clippy and log mailbox message

* chore: close prepared statement after execution

* chore: add comment

* chore: remove log

* chore: rename to `ConsistencyPoison`

* chore: remove unused error

* fix: fix unit tests

* chore: apply suggestions from CR

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: discord9 <55937128+discord9@users.noreply.github.com>
Co-authored-by: Yohan Wal <profsyb@gmail.com>
Co-authored-by: Yingwen <realevenyag@gmail.com>
Co-authored-by: Ruihang Xia <waynestxia@gmail.com>
Co-authored-by: yihong <zouzou0208@gmail.com>
Co-authored-by: dennis zhuang <killme2008@gmail.com>
2025-04-08 14:16:40 +08:00

192 lines
4.0 KiB
SQL

-- test null handling in flow
-- test null handling in value part of key-value pair
CREATE TABLE requests (
service_name STRING,
service_ip STRING,
val INT,
ts TIMESTAMP TIME INDEX
);
CREATE TABLE sum_val_in_reqs (
sum_val INT64,
ts TIMESTAMP TIME INDEX
);
CREATE FLOW requests_long_term SINK TO sum_val_in_reqs AS
SELECT
sum(val) as sum_val,
date_bin(INTERVAL '30 seconds', ts) as time_window,
FROM
requests
GROUP BY
time_window;
INSERT INTO
requests
VALUES
(NULL, "10.0.0.1", NULL, "2024-10-18 19:00:00"),
("svc1", "10.0.0.2", 100, "2024-10-18 19:00:00"),
(NULL, "10.0.0.1", NULL, "2024-10-18 19:00:30"),
("svc1", "10.0.0.2", 200, "2024-10-18 19:00:30"),
(NULL, "10.0.0.1", 300, "2024-10-18 19:01:00"),
(NULL, "10.0.0.2", NULL, "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");
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('requests_long_term');
SELECT
*
FROM
sum_val_in_reqs;
-- Test if FLOWS table works, but don't care about the result since it vary from runs
SELECT
count(CASE WHEN state_size > 0 THEN 1 ELSE 0 END) as active_flows,
FROM
INFORMATION_SCHEMA.FLOWS;
DROP FLOW requests_long_term;
DROP TABLE sum_val_in_reqs;
DROP TABLE requests;
-- test null handling in key part of key-value pair
CREATE TABLE ngx_access_log (
client STRING,
country STRING,
access_time TIMESTAMP TIME INDEX
);
CREATE FLOW calc_ngx_country SINK TO ngx_country AS
SELECT
client,
country as 'country',
count(1) as country_count,
date_bin(INTERVAL '1 hour', access_time) as time_window,
FROM
ngx_access_log
GROUP BY
client,
country,
time_window;
INSERT INTO
ngx_access_log
VALUES
("cli1", null, 0),
("cli1", null, 0),
("cli2", null, 0),
("cli2", null, 1),
("cli1", "b", 0),
("cli1", "c", 0);
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_ngx_country');
SELECT
client,
country,
country_count,
time_window
FROM
ngx_country;
-- making sure distinct is working
INSERT INTO
ngx_access_log
VALUES
("cli1", "b", 1);
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_ngx_country');
SELECT
client,
country,
country_count,
time_window
FROM
ngx_country;
INSERT INTO
ngx_access_log
VALUES
("cli1", "c", 2);
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_ngx_country');
SELECT
client,
country,
country_count,
time_window
FROM
ngx_country;
DROP FLOW calc_ngx_country;
DROP TABLE ngx_access_log;
DROP TABLE ngx_country;
-- test nullable pk with no default value
CREATE TABLE nullable_pk (
pid INT NULL,
client STRING,
ts TIMESTAMP TIME INDEX,
PRIMARY KEY (pid)
) WITH (
append_mode = 'true'
);
CREATE TABLE out_nullable_pk (
pid INT NULL,
client STRING,
ts TIMESTAMP TIME INDEX,
PRIMARY KEY (pid, client)
);
CREATE FLOW calc_nullable_pk SINK TO out_nullable_pk AS
SELECT
pid,
client,
ts
FROM
nullable_pk;
INSERT INTO
nullable_pk
VALUES
(1, "name1", "2024-10-18 19:00:00"),
(2, "name2", "2024-10-18 19:00:00"),
(3, "name3", "2024-10-18 19:00:00");
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_nullable_pk');
SELECT * FROM out_nullable_pk;
-- pk is nullable
INSERT INTO
nullable_pk (client, ts)
VALUES
("name1", "2024-10-18 19:00:00"),
("name2", "2024-10-18 19:00:00"),
("name3", "2024-10-18 19:00:00");
-- SQLNESS REPLACE (ADMIN\sFLUSH_FLOW\('\w+'\)\s+\|\n\+-+\+\n\|\s+)[0-9]+\s+\| $1 FLOW_FLUSHED |
ADMIN FLUSH_FLOW('calc_nullable_pk');
SELECT * FROM out_nullable_pk;
DROP FLOW calc_nullable_pk;
DROP TABLE nullable_pk;
DROP TABLE out_nullable_pk;