From 74b5e19fa5ffbb2104fa02813f9adc2ed6c3414c Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Thu, 30 Apr 2020 18:39:09 +0300 Subject: [PATCH] Added test. --- .../0_stateless/01268_mv_scalars.reference | 21 +++++++++++++++ .../queries/0_stateless/01268_mv_scalars.sql | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/queries/0_stateless/01268_mv_scalars.reference create mode 100644 tests/queries/0_stateless/01268_mv_scalars.sql diff --git a/tests/queries/0_stateless/01268_mv_scalars.reference b/tests/queries/0_stateless/01268_mv_scalars.reference new file mode 100644 index 00000000000..0fcc52d0024 --- /dev/null +++ b/tests/queries/0_stateless/01268_mv_scalars.reference @@ -0,0 +1,21 @@ +0 2 +1 2 +0 2 +1 2 +0 2 +1 2 +the rows get inserted +2020-01-01 0 0 +2020-01-01 0 2 +2020-01-01 0 4 +no new rows +2020-01-01 0 0 +2020-01-01 0 2 +2020-01-01 0 4 +the rows get inserted +2020-01-01 0 0 +2020-01-01 0 2 +2020-01-01 0 4 +2020-01-06 5 0 +2020-01-06 5 2 +2020-01-06 5 4 diff --git a/tests/queries/0_stateless/01268_mv_scalars.sql b/tests/queries/0_stateless/01268_mv_scalars.sql new file mode 100644 index 00000000000..a94a1cf1920 --- /dev/null +++ b/tests/queries/0_stateless/01268_mv_scalars.sql @@ -0,0 +1,26 @@ +create table src_table Engine=Memory as system.numbers; +CREATE MATERIALIZED VIEW dst_mv Engine=Memory as select *, (SELECT count() FROM src_table) AS cnt FROM src_table; +insert into src_table select * from numbers(2); +insert into src_table select * from numbers(2); +insert into src_table select * from numbers(2); +select * from dst_mv; + +CREATE TABLE dest_table (`Date` Date, `Id` UInt64, `Units` Float32) ENGINE = Memory; +create table left_table as dest_table; +create table right_table as dest_table; +insert into right_table select toDate('2020-01-01') + number, number, number / 2 from numbers(10); + +CREATE MATERIALIZED VIEW dest_table_mv TO dest_table as select * FROM (SELECT * FROM left_table) AS t1 INNER JOIN (WITH (SELECT DISTINCT Date FROM left_table LIMIT 1) AS dt SELECT * FROM right_table WHERE Date = dt) AS t2 USING (Date, Id); + +insert into left_table select toDate('2020-01-01'), 0, number * 2 from numbers(3); +select 'the rows get inserted'; +select * from dest_table; + +insert into left_table select toDate('2020-01-01'), 5, number * 2 from numbers(3); +select 'no new rows'; +select * from dest_table; + +truncate table left_table; +insert into left_table select toDate('2020-01-01') + 5, 5, number * 2 from numbers(3); +select 'the rows get inserted'; +select * from dest_table;