From d180e412304651b3f23311d83305866161041d54 Mon Sep 17 00:00:00 2001 From: WU Jingdi Date: Tue, 19 Dec 2023 10:35:14 +0800 Subject: [PATCH] fix: change range query time slot to `[align_ts, align_ts + range)` (#2938) --- src/query/src/range_select/plan.rs | 89 +++++++------------ tests/cases/standalone/common/range/by.result | 2 +- tests/cases/standalone/common/range/by.sql | 2 +- .../standalone/common/range/calculate.result | 60 ++++++------- .../standalone/common/range/calculate.sql | 8 +- .../standalone/common/range/interval.result | 24 ++--- .../standalone/common/range/interval.sql | 16 ++-- tests/cases/standalone/common/range/to.result | 52 +++++------ tests/cases/standalone/common/range/to.sql | 16 ++-- 9 files changed, 123 insertions(+), 146 deletions(-) diff --git a/src/query/src/range_select/plan.rs b/src/query/src/range_select/plan.rs index b687b6d93c65..e2af9b654d9e 100644 --- a/src/query/src/range_select/plan.rs +++ b/src/query/src/range_select/plan.rs @@ -786,14 +786,14 @@ fn produce_align_time( // make modify_map for range_fn[i] for (row, hash) in by_columns_hash.iter().enumerate() { let ts = ts_column.value(row); - let ith_slot = (ts - align_to).div_ceil(align); + let ith_slot = (ts - align_to).div_floor(align); let mut align_ts = ith_slot * align + align_to; - while align_ts - range < ts && ts <= align_ts { + while align_ts <= ts && ts < align_ts + range { modify_map .entry((*hash, align_ts)) .or_default() .push(row as u32); - align_ts += align; + align_ts -= align; } } } @@ -1232,18 +1232,18 @@ mod test { "+------------+------------+---------------------+-------+\ \n| MIN(value) | MAX(value) | timestamp | host |\ \n+------------+------------+---------------------+-------+\ + \n| 0.0 | | 1969-12-31T23:59:55 | host1 |\ \n| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |\ - \n| 0.0 | | 1970-01-01T00:00:05 | host1 |\ + \n| 1.0 | | 1970-01-01T00:00:05 | host1 |\ \n| 1.0 | 1.0 | 1970-01-01T00:00:10 | host1 |\ - \n| 1.0 | | 1970-01-01T00:00:15 | host1 |\ + \n| 2.0 | | 1970-01-01T00:00:15 | host1 |\ \n| 2.0 | 2.0 | 1970-01-01T00:00:20 | host1 |\ - \n| 2.0 | | 1970-01-01T00:00:25 | host1 |\ + \n| 3.0 | | 1969-12-31T23:59:55 | host2 |\ \n| 3.0 | 3.0 | 1970-01-01T00:00:00 | host2 |\ - \n| 3.0 | | 1970-01-01T00:00:05 | host2 |\ + \n| 4.0 | | 1970-01-01T00:00:05 | host2 |\ \n| 4.0 | 4.0 | 1970-01-01T00:00:10 | host2 |\ - \n| 4.0 | | 1970-01-01T00:00:15 | host2 |\ + \n| 5.0 | | 1970-01-01T00:00:15 | host2 |\ \n| 5.0 | 5.0 | 1970-01-01T00:00:20 | host2 |\ - \n| 5.0 | | 1970-01-01T00:00:25 | host2 |\ \n+------------+------------+---------------------+-------+", ); do_range_select_test(10_000, 5_000, 5_000, Fill::Null, true, expected).await; @@ -1255,18 +1255,18 @@ mod test { "+------------+------------+---------------------+-------+\ \n| MIN(value) | MAX(value) | timestamp | host |\ \n+------------+------------+---------------------+-------+\ + \n| 0.0 | | 1969-12-31T23:59:55 | host1 |\ \n| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |\ - \n| 0.0 | 0.0 | 1970-01-01T00:00:05 | host1 |\ + \n| 1.0 | 0.0 | 1970-01-01T00:00:05 | host1 |\ \n| 1.0 | 1.0 | 1970-01-01T00:00:10 | host1 |\ - \n| 1.0 | 1.0 | 1970-01-01T00:00:15 | host1 |\ + \n| 2.0 | 1.0 | 1970-01-01T00:00:15 | host1 |\ \n| 2.0 | 2.0 | 1970-01-01T00:00:20 | host1 |\ - \n| 2.0 | 2.0 | 1970-01-01T00:00:25 | host1 |\ + \n| 3.0 | | 1969-12-31T23:59:55 | host2 |\ \n| 3.0 | 3.0 | 1970-01-01T00:00:00 | host2 |\ - \n| 3.0 | 3.0 | 1970-01-01T00:00:05 | host2 |\ + \n| 4.0 | 3.0 | 1970-01-01T00:00:05 | host2 |\ \n| 4.0 | 4.0 | 1970-01-01T00:00:10 | host2 |\ - \n| 4.0 | 4.0 | 1970-01-01T00:00:15 | host2 |\ + \n| 5.0 | 4.0 | 1970-01-01T00:00:15 | host2 |\ \n| 5.0 | 5.0 | 1970-01-01T00:00:20 | host2 |\ - \n| 5.0 | 5.0 | 1970-01-01T00:00:25 | host2 |\ \n+------------+------------+---------------------+-------+", ); do_range_select_test(10_000, 5_000, 5_000, Fill::Prev, true, expected).await; @@ -1278,64 +1278,41 @@ mod test { "+------------+------------+---------------------+-------+\ \n| MIN(value) | MAX(value) | timestamp | host |\ \n+------------+------------+---------------------+-------+\ + \n| 0.0 | -0.5 | 1969-12-31T23:59:55 | host1 |\ \n| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |\ - \n| 0.0 | 0.5 | 1970-01-01T00:00:05 | host1 |\ + \n| 1.0 | 0.5 | 1970-01-01T00:00:05 | host1 |\ \n| 1.0 | 1.0 | 1970-01-01T00:00:10 | host1 |\ - \n| 1.0 | 1.5 | 1970-01-01T00:00:15 | host1 |\ + \n| 2.0 | 1.5 | 1970-01-01T00:00:15 | host1 |\ \n| 2.0 | 2.0 | 1970-01-01T00:00:20 | host1 |\ - \n| 2.0 | 2.5 | 1970-01-01T00:00:25 | host1 |\ + \n| 3.0 | 2.5 | 1969-12-31T23:59:55 | host2 |\ \n| 3.0 | 3.0 | 1970-01-01T00:00:00 | host2 |\ - \n| 3.0 | 3.5 | 1970-01-01T00:00:05 | host2 |\ + \n| 4.0 | 3.5 | 1970-01-01T00:00:05 | host2 |\ \n| 4.0 | 4.0 | 1970-01-01T00:00:10 | host2 |\ - \n| 4.0 | 4.5 | 1970-01-01T00:00:15 | host2 |\ + \n| 5.0 | 4.5 | 1970-01-01T00:00:15 | host2 |\ \n| 5.0 | 5.0 | 1970-01-01T00:00:20 | host2 |\ - \n| 5.0 | 5.5 | 1970-01-01T00:00:25 | host2 |\ \n+------------+------------+---------------------+-------+", ); do_range_select_test(10_000, 5_000, 5_000, Fill::Linear, true, expected).await; } - #[tokio::test] - async fn range_fill_integer_null() { - let expected = String::from( - "+------------+------------+---------------------+-------+\ - \n| MIN(value) | MAX(value) | timestamp | host |\ - \n+------------+------------+---------------------+-------+\ - \n| 0 | 0 | 1970-01-01T00:00:00 | host1 |\ - \n| 0 | | 1970-01-01T00:00:05 | host1 |\ - \n| 1 | 1 | 1970-01-01T00:00:10 | host1 |\ - \n| 1 | | 1970-01-01T00:00:15 | host1 |\ - \n| 2 | 2 | 1970-01-01T00:00:20 | host1 |\ - \n| 2 | | 1970-01-01T00:00:25 | host1 |\ - \n| 3 | 3 | 1970-01-01T00:00:00 | host2 |\ - \n| 3 | | 1970-01-01T00:00:05 | host2 |\ - \n| 4 | 4 | 1970-01-01T00:00:10 | host2 |\ - \n| 4 | | 1970-01-01T00:00:15 | host2 |\ - \n| 5 | 5 | 1970-01-01T00:00:20 | host2 |\ - \n| 5 | | 1970-01-01T00:00:25 | host2 |\ - \n+------------+------------+---------------------+-------+", - ); - do_range_select_test(10_000, 5_000, 5_000, Fill::Null, false, expected).await; - } - #[tokio::test] async fn range_fill_integer_linear() { let expected = String::from( "+------------+------------+---------------------+-------+\ \n| MIN(value) | MAX(value) | timestamp | host |\ \n+------------+------------+---------------------+-------+\ + \n| 0.0 | -0.5 | 1969-12-31T23:59:55 | host1 |\ \n| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |\ - \n| 0.0 | 0.5 | 1970-01-01T00:00:05 | host1 |\ + \n| 1.0 | 0.5 | 1970-01-01T00:00:05 | host1 |\ \n| 1.0 | 1.0 | 1970-01-01T00:00:10 | host1 |\ - \n| 1.0 | 1.5 | 1970-01-01T00:00:15 | host1 |\ + \n| 2.0 | 1.5 | 1970-01-01T00:00:15 | host1 |\ \n| 2.0 | 2.0 | 1970-01-01T00:00:20 | host1 |\ - \n| 2.0 | 2.5 | 1970-01-01T00:00:25 | host1 |\ + \n| 3.0 | 2.5 | 1969-12-31T23:59:55 | host2 |\ \n| 3.0 | 3.0 | 1970-01-01T00:00:00 | host2 |\ - \n| 3.0 | 3.5 | 1970-01-01T00:00:05 | host2 |\ + \n| 4.0 | 3.5 | 1970-01-01T00:00:05 | host2 |\ \n| 4.0 | 4.0 | 1970-01-01T00:00:10 | host2 |\ - \n| 4.0 | 4.5 | 1970-01-01T00:00:15 | host2 |\ + \n| 5.0 | 4.5 | 1970-01-01T00:00:15 | host2 |\ \n| 5.0 | 5.0 | 1970-01-01T00:00:20 | host2 |\ - \n| 5.0 | 5.5 | 1970-01-01T00:00:25 | host2 |\ \n+------------+------------+---------------------+-------+", ); do_range_select_test(10_000, 5_000, 5_000, Fill::Linear, false, expected).await; @@ -1347,18 +1324,18 @@ mod test { "+------------+------------+---------------------+-------+\ \n| MIN(value) | MAX(value) | timestamp | host |\ \n+------------+------------+---------------------+-------+\ + \n| 0.0 | 6.6 | 1969-12-31T23:59:55 | host1 |\ \n| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |\ - \n| 0.0 | 6.6 | 1970-01-01T00:00:05 | host1 |\ + \n| 1.0 | 6.6 | 1970-01-01T00:00:05 | host1 |\ \n| 1.0 | 1.0 | 1970-01-01T00:00:10 | host1 |\ - \n| 1.0 | 6.6 | 1970-01-01T00:00:15 | host1 |\ + \n| 2.0 | 6.6 | 1970-01-01T00:00:15 | host1 |\ \n| 2.0 | 2.0 | 1970-01-01T00:00:20 | host1 |\ - \n| 2.0 | 6.6 | 1970-01-01T00:00:25 | host1 |\ + \n| 3.0 | 6.6 | 1969-12-31T23:59:55 | host2 |\ \n| 3.0 | 3.0 | 1970-01-01T00:00:00 | host2 |\ - \n| 3.0 | 6.6 | 1970-01-01T00:00:05 | host2 |\ + \n| 4.0 | 6.6 | 1970-01-01T00:00:05 | host2 |\ \n| 4.0 | 4.0 | 1970-01-01T00:00:10 | host2 |\ - \n| 4.0 | 6.6 | 1970-01-01T00:00:15 | host2 |\ + \n| 5.0 | 6.6 | 1970-01-01T00:00:15 | host2 |\ \n| 5.0 | 5.0 | 1970-01-01T00:00:20 | host2 |\ - \n| 5.0 | 6.6 | 1970-01-01T00:00:25 | host2 |\ \n+------------+------------+---------------------+-------+", ); do_range_select_test( diff --git a/tests/cases/standalone/common/range/by.result b/tests/cases/standalone/common/range/by.result index 0da499a30fe4..250cc6dd167a 100644 --- a/tests/cases/standalone/common/range/by.result +++ b/tests/cases/standalone/common/range/by.result @@ -50,7 +50,7 @@ SELECT ts, max(val) RANGE '5s' FROM host ALIGN '20s' BY () ORDER BY ts; | 1970-01-01T00:00:20 | 5 | +---------------------+----------------------------------+ -SELECT ts, CAST(length(host) as INT64) + 2, max(val) RANGE '5s' FROM host ALIGN '20s' BY (CAST(length(host) as INT64) + 2) ORDER BY ts; +SELECT ts, length(host)::INT64 + 2, max(val) RANGE '5s' FROM host ALIGN '20s' BY (length(host)::INT64 + 2) ORDER BY ts; +---------------------+----------------------------------------+----------------------------------+ | ts | character_length(host.host) + Int64(2) | MAX(host.val) RANGE 5s FILL NULL | diff --git a/tests/cases/standalone/common/range/by.sql b/tests/cases/standalone/common/range/by.sql index b7aae24c97e9..fcf94c124b45 100644 --- a/tests/cases/standalone/common/range/by.sql +++ b/tests/cases/standalone/common/range/by.sql @@ -26,7 +26,7 @@ SELECT ts, max(val) RANGE '5s' FROM host ALIGN '20s' BY (2) ORDER BY ts; -- Implement by rewrite `BY()` to `BY(1)` automatically through sqlparser. They are semantically equivalent. SELECT ts, max(val) RANGE '5s' FROM host ALIGN '20s' BY () ORDER BY ts; -SELECT ts, CAST(length(host) as INT64) + 2, max(val) RANGE '5s' FROM host ALIGN '20s' BY (CAST(length(host) as INT64) + 2) ORDER BY ts; +SELECT ts, length(host)::INT64 + 2, max(val) RANGE '5s' FROM host ALIGN '20s' BY (length(host)::INT64 + 2) ORDER BY ts; -- Test error diff --git a/tests/cases/standalone/common/range/calculate.result b/tests/cases/standalone/common/range/calculate.result index a4c10994c0d8..e94a3228ba58 100644 --- a/tests/cases/standalone/common/range/calculate.result +++ b/tests/cases/standalone/common/range/calculate.result @@ -26,14 +26,14 @@ SELECT ts, host, covar(val::DOUBLE, val::DOUBLE) RANGE '20s' FROM host ALIGN '10 +---------------------+-------+---------------------------------------------------+ | ts | host | COVARIANCE(host.val,host.val) RANGE 20s FILL NULL | +---------------------+-------+---------------------------------------------------+ -| 1970-01-01T00:00:00 | host1 | | +| 1969-12-31T23:59:50 | host1 | | +| 1970-01-01T00:00:00 | host1 | 0.5 | | 1970-01-01T00:00:10 | host1 | 0.5 | -| 1970-01-01T00:00:20 | host1 | 0.5 | -| 1970-01-01T00:00:30 | host1 | | -| 1970-01-01T00:00:00 | host2 | | +| 1970-01-01T00:00:20 | host1 | | +| 1969-12-31T23:59:50 | host2 | | +| 1970-01-01T00:00:00 | host2 | 0.5 | | 1970-01-01T00:00:10 | host2 | 0.5 | -| 1970-01-01T00:00:20 | host2 | 0.5 | -| 1970-01-01T00:00:30 | host2 | | +| 1970-01-01T00:00:20 | host2 | | +---------------------+-------+---------------------------------------------------+ SELECT ts, host, 2 * min(val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; @@ -70,7 +70,7 @@ SELECT ts, host, min(val * 2) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; | 1970-01-01T00:00:20 | host2 | 10 | +---------------------+-------+---------------------------------------------+ -SELECT ts, host, min(CAST(val as Float64)) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; +SELECT ts, host, min(val::DOUBLE) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; +---------------------+-------+----------------------------------+ | ts | host | MIN(host.val) RANGE 5s FILL NULL | @@ -87,7 +87,7 @@ SELECT ts, host, min(CAST(val as Float64)) RANGE '5s' FROM host ALIGN '5s' ORDER | 1970-01-01T00:00:20 | host2 | 5.0 | +---------------------+-------+----------------------------------+ -SELECT ts, host, min(floor(CAST(val as Float64))) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; +SELECT ts, host, min(floor(val::DOUBLE)) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; +---------------------+-------+-----------------------------------------+ | ts | host | MIN(floor(host.val)) RANGE 5s FILL NULL | @@ -127,29 +127,29 @@ SELECT ts, host, (min(val) + max(val)) RANGE '20s' + 1.0 FROM host ALIGN '10s' O +---------------------+-------+------------------------------------------------------------------------------------+ | ts | host | MIN(host.val) RANGE 20s FILL NULL + MAX(host.val) RANGE 20s FILL NULL + Float64(1) | +---------------------+-------+------------------------------------------------------------------------------------+ -| 1970-01-01T00:00:00 | host1 | 1.0 | -| 1970-01-01T00:00:10 | host1 | 2.0 | -| 1970-01-01T00:00:20 | host1 | 4.0 | -| 1970-01-01T00:00:30 | host1 | 5.0 | -| 1970-01-01T00:00:00 | host2 | 7.0 | -| 1970-01-01T00:00:10 | host2 | 8.0 | -| 1970-01-01T00:00:20 | host2 | 10.0 | -| 1970-01-01T00:00:30 | host2 | 11.0 | +| 1969-12-31T23:59:50 | host1 | 1.0 | +| 1970-01-01T00:00:00 | host1 | 2.0 | +| 1970-01-01T00:00:10 | host1 | 4.0 | +| 1970-01-01T00:00:20 | host1 | 5.0 | +| 1969-12-31T23:59:50 | host2 | 7.0 | +| 1970-01-01T00:00:00 | host2 | 8.0 | +| 1970-01-01T00:00:10 | host2 | 10.0 | +| 1970-01-01T00:00:20 | host2 | 11.0 | +---------------------+-------+------------------------------------------------------------------------------------+ -SELECT ts, host, covar(ceil(CAST(val as Float64)), floor(CAST(val as Float64))) RANGE '20s' FROM host ALIGN '10s' ORDER BY host, ts; +SELECT ts, host, covar(ceil(val::DOUBLE), floor(val::DOUBLE)) RANGE '20s' FROM host ALIGN '10s' ORDER BY host, ts; +---------------------+-------+----------------------------------------------------------------+ | ts | host | COVARIANCE(ceil(host.val),floor(host.val)) RANGE 20s FILL NULL | +---------------------+-------+----------------------------------------------------------------+ -| 1970-01-01T00:00:00 | host1 | | +| 1969-12-31T23:59:50 | host1 | | +| 1970-01-01T00:00:00 | host1 | 0.5 | | 1970-01-01T00:00:10 | host1 | 0.5 | -| 1970-01-01T00:00:20 | host1 | 0.5 | -| 1970-01-01T00:00:30 | host1 | | -| 1970-01-01T00:00:00 | host2 | | +| 1970-01-01T00:00:20 | host1 | | +| 1969-12-31T23:59:50 | host2 | | +| 1970-01-01T00:00:00 | host2 | 0.5 | | 1970-01-01T00:00:10 | host2 | 0.5 | -| 1970-01-01T00:00:20 | host2 | 0.5 | -| 1970-01-01T00:00:30 | host2 | | +| 1970-01-01T00:00:20 | host2 | | +---------------------+-------+----------------------------------------------------------------+ SELECT ts, host, floor(cos(ceil(sin(min(val) RANGE '5s')))) FROM host ALIGN '5s' ORDER BY host, ts; @@ -169,23 +169,23 @@ SELECT ts, host, floor(cos(ceil(sin(min(val) RANGE '5s')))) FROM host ALIGN '5s' | 1970-01-01T00:00:20 | host2 | 1.0 | +---------------------+-------+---------------------------------------------------------+ -SELECT ts, host, gcd(CAST(max(floor(CAST(val as Float64))) RANGE '10s' FILL PREV as INT64) * 4, max(val * 4) RANGE '10s' FILL PREV) * length(host) + 1 FROM host ALIGN '5s' ORDER BY host, ts; +SELECT ts, host, gcd(CAST(max(floor(val::DOUBLE)) RANGE '10s' FILL PREV as INT64) * 4, max(val * 4) RANGE '10s' FILL PREV) * length(host) + 1 FROM host ALIGN '5s' ORDER BY host, ts; +---------------------+-------+------------------------------------------------------------------------------------------------------------------------------------------------+ | ts | host | gcd(MAX(floor(host.val)) RANGE 10s FILL PREV * Int64(4),MAX(host.val * Int64(4)) RANGE 10s FILL PREV) * character_length(host.host) + Int64(1) | +---------------------+-------+------------------------------------------------------------------------------------------------------------------------------------------------+ +| 1969-12-31T23:59:55 | host1 | 1 | | 1970-01-01T00:00:00 | host1 | 1 | -| 1970-01-01T00:00:05 | host1 | 1 | +| 1970-01-01T00:00:05 | host1 | 21 | | 1970-01-01T00:00:10 | host1 | 21 | -| 1970-01-01T00:00:15 | host1 | 21 | +| 1970-01-01T00:00:15 | host1 | 41 | | 1970-01-01T00:00:20 | host1 | 41 | -| 1970-01-01T00:00:25 | host1 | 41 | +| 1969-12-31T23:59:55 | host2 | 61 | | 1970-01-01T00:00:00 | host2 | 61 | -| 1970-01-01T00:00:05 | host2 | 61 | +| 1970-01-01T00:00:05 | host2 | 81 | | 1970-01-01T00:00:10 | host2 | 81 | -| 1970-01-01T00:00:15 | host2 | 81 | +| 1970-01-01T00:00:15 | host2 | 101 | | 1970-01-01T00:00:20 | host2 | 101 | -| 1970-01-01T00:00:25 | host2 | 101 | +---------------------+-------+------------------------------------------------------------------------------------------------------------------------------------------------+ DROP TABLE host; diff --git a/tests/cases/standalone/common/range/calculate.sql b/tests/cases/standalone/common/range/calculate.sql index 07d34173c4e6..6bbc7eb84eba 100644 --- a/tests/cases/standalone/common/range/calculate.sql +++ b/tests/cases/standalone/common/range/calculate.sql @@ -24,9 +24,9 @@ SELECT ts, host, 2 * min(val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; SELECT ts, host, min(val * 2) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; -SELECT ts, host, min(CAST(val as Float64)) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; +SELECT ts, host, min(val::DOUBLE) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; -SELECT ts, host, min(floor(CAST(val as Float64))) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; +SELECT ts, host, min(floor(val::DOUBLE)) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts; SELECT ts, host, floor(min(val) RANGE '5s') FROM host ALIGN '5s' ORDER BY host, ts; @@ -34,10 +34,10 @@ SELECT ts, host, floor(min(val) RANGE '5s') FROM host ALIGN '5s' ORDER BY host, SELECT ts, host, (min(val) + max(val)) RANGE '20s' + 1.0 FROM host ALIGN '10s' ORDER BY host, ts; -SELECT ts, host, covar(ceil(CAST(val as Float64)), floor(CAST(val as Float64))) RANGE '20s' FROM host ALIGN '10s' ORDER BY host, ts; +SELECT ts, host, covar(ceil(val::DOUBLE), floor(val::DOUBLE)) RANGE '20s' FROM host ALIGN '10s' ORDER BY host, ts; SELECT ts, host, floor(cos(ceil(sin(min(val) RANGE '5s')))) FROM host ALIGN '5s' ORDER BY host, ts; -SELECT ts, host, gcd(CAST(max(floor(CAST(val as Float64))) RANGE '10s' FILL PREV as INT64) * 4, max(val * 4) RANGE '10s' FILL PREV) * length(host) + 1 FROM host ALIGN '5s' ORDER BY host, ts; +SELECT ts, host, gcd(CAST(max(floor(val::DOUBLE)) RANGE '10s' FILL PREV as INT64) * 4, max(val * 4) RANGE '10s' FILL PREV) * length(host) + 1 FROM host ALIGN '5s' ORDER BY host, ts; DROP TABLE host; diff --git a/tests/cases/standalone/common/range/interval.result b/tests/cases/standalone/common/range/interval.result index bbc524555dce..99247049ad16 100644 --- a/tests/cases/standalone/common/range/interval.result +++ b/tests/cases/standalone/common/range/interval.result @@ -7,14 +7,14 @@ CREATE TABLE host ( Affected Rows: 0 INSERT INTO TABLE host VALUES - ("1970-01-01T01:00:00+08:00", 'host1', 0), - ("1970-01-01T02:00:00+08:00", 'host1', 1), - ("1971-01-02T03:00:00+08:00", 'host1', 2), - ("1971-01-02T04:00:00+08:00", 'host1', 3), - ("1970-01-01T01:00:00+08:00", 'host2', 4), - ("1970-01-01T02:00:00+08:00", 'host2', 5), - ("1971-01-02T03:00:00+08:00", 'host2', 6), - ("1971-01-02T04:00:00+08:00", 'host2', 7); + ("1970-01-01T01:00:00+00:00", 'host1', 0), + ("1970-01-01T02:00:00+00:00", 'host1', 1), + ("1971-01-02T03:00:00+00:00", 'host1', 2), + ("1971-01-02T04:00:00+00:00", 'host1', 3), + ("1970-01-01T01:00:00+00:00", 'host2', 4), + ("1970-01-01T02:00:00+00:00", 'host2', 5), + ("1971-01-02T03:00:00+00:00", 'host2', 6), + ("1971-01-02T04:00:00+00:00", 'host2', 7); Affected Rows: 8 @@ -24,9 +24,9 @@ SELECT ts, host, min(val) RANGE (INTERVAL '1 year') FROM host ALIGN (INTERVAL '1 | ts | host | MIN(host.val) RANGE IntervalMonthDayNano("950737950171172051122527404032") FILL NULL | +---------------------+-------+--------------------------------------------------------------------------------------+ | 1970-01-01T00:00:00 | host1 | 0 | -| 1971-12-22T00:00:00 | host1 | 2 | +| 1970-12-27T00:00:00 | host1 | 2 | | 1970-01-01T00:00:00 | host2 | 4 | -| 1971-12-22T00:00:00 | host2 | 6 | +| 1970-12-27T00:00:00 | host2 | 6 | +---------------------+-------+--------------------------------------------------------------------------------------+ SELECT ts, host, min(val) RANGE (INTERVAL '1' year) FROM host ALIGN (INTERVAL '1' year) ORDER BY host, ts; @@ -35,9 +35,9 @@ SELECT ts, host, min(val) RANGE (INTERVAL '1' year) FROM host ALIGN (INTERVAL '1 | ts | host | MIN(host.val) RANGE IntervalMonthDayNano("950737950171172051122527404032") FILL NULL | +---------------------+-------+--------------------------------------------------------------------------------------+ | 1970-01-01T00:00:00 | host1 | 0 | -| 1971-12-22T00:00:00 | host1 | 2 | +| 1970-12-27T00:00:00 | host1 | 2 | | 1970-01-01T00:00:00 | host2 | 4 | -| 1971-12-22T00:00:00 | host2 | 6 | +| 1970-12-27T00:00:00 | host2 | 6 | +---------------------+-------+--------------------------------------------------------------------------------------+ DROP TABLE host; diff --git a/tests/cases/standalone/common/range/interval.sql b/tests/cases/standalone/common/range/interval.sql index cae339a7a570..3e17ecae58cd 100644 --- a/tests/cases/standalone/common/range/interval.sql +++ b/tests/cases/standalone/common/range/interval.sql @@ -5,14 +5,14 @@ CREATE TABLE host ( ); INSERT INTO TABLE host VALUES - ("1970-01-01T01:00:00+08:00", 'host1', 0), - ("1970-01-01T02:00:00+08:00", 'host1', 1), - ("1971-01-02T03:00:00+08:00", 'host1', 2), - ("1971-01-02T04:00:00+08:00", 'host1', 3), - ("1970-01-01T01:00:00+08:00", 'host2', 4), - ("1970-01-01T02:00:00+08:00", 'host2', 5), - ("1971-01-02T03:00:00+08:00", 'host2', 6), - ("1971-01-02T04:00:00+08:00", 'host2', 7); + ("1970-01-01T01:00:00+00:00", 'host1', 0), + ("1970-01-01T02:00:00+00:00", 'host1', 1), + ("1971-01-02T03:00:00+00:00", 'host1', 2), + ("1971-01-02T04:00:00+00:00", 'host1', 3), + ("1970-01-01T01:00:00+00:00", 'host2', 4), + ("1970-01-01T02:00:00+00:00", 'host2', 5), + ("1971-01-02T03:00:00+00:00", 'host2', 6), + ("1971-01-02T04:00:00+00:00", 'host2', 7); SELECT ts, host, min(val) RANGE (INTERVAL '1 year') FROM host ALIGN (INTERVAL '1 year') ORDER BY host, ts; diff --git a/tests/cases/standalone/common/range/to.result b/tests/cases/standalone/common/range/to.result index 9568a23e7af7..2a066d7d202c 100644 --- a/tests/cases/standalone/common/range/to.result +++ b/tests/cases/standalone/common/range/to.result @@ -7,14 +7,14 @@ CREATE TABLE host ( Affected Rows: 0 INSERT INTO TABLE host VALUES - ("1970-01-01T23:30:00+00:00", 'host1', 0), - ("1970-01-01T22:30:00+00:00", 'host1', 1), - ("1970-01-02T23:30:00+00:00", 'host1', 2), - ("1970-01-02T22:30:00+00:00", 'host1', 3), - ("1970-01-01T23:30:00+00:00", 'host2', 4), - ("1970-01-01T22:30:00+00:00", 'host2', 5), - ("1970-01-02T23:30:00+00:00", 'host2', 6), - ("1970-01-02T22:30:00+00:00", 'host2', 7); + ("1970-01-01T22:30:00+00:00", 'host1', 0), + ("1970-01-01T23:30:00+00:00", 'host1', 1), + ("1970-01-02T22:30:00+00:00", 'host1', 2), + ("1970-01-02T23:30:00+00:00", 'host1', 3), + ("1970-01-01T22:30:00+00:00", 'host2', 4), + ("1970-01-01T23:30:00+00:00", 'host2', 5), + ("1970-01-02T22:30:00+00:00", 'host2', 6), + ("1970-01-02T23:30:00+00:00", 'host2', 7); Affected Rows: 8 @@ -23,10 +23,10 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts; +---------------------+-------+----------------------------------+ | ts | host | MIN(host.val) RANGE 1d FILL NULL | +---------------------+-------+----------------------------------+ -| 1970-01-02T00:00:00 | host1 | 0 | -| 1970-01-03T00:00:00 | host1 | 2 | -| 1970-01-02T00:00:00 | host2 | 4 | -| 1970-01-03T00:00:00 | host2 | 6 | +| 1970-01-01T00:00:00 | host1 | 0 | +| 1970-01-02T00:00:00 | host1 | 2 | +| 1970-01-01T00:00:00 | host2 | 4 | +| 1970-01-02T00:00:00 | host2 | 6 | +---------------------+-------+----------------------------------+ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO UNKNOWN ORDER BY host, ts; @@ -38,12 +38,12 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1900-01-01T00:00:0 +---------------------+-------+----------------------------------+ | ts | host | MIN(host.val) RANGE 1d FILL NULL | +---------------------+-------+----------------------------------+ +| 1969-12-31T23:00:00 | host1 | 0 | | 1970-01-01T23:00:00 | host1 | 1 | -| 1970-01-02T23:00:00 | host1 | 0 | -| 1970-01-03T23:00:00 | host1 | 2 | +| 1970-01-02T23:00:00 | host1 | 3 | +| 1969-12-31T23:00:00 | host2 | 4 | | 1970-01-01T23:00:00 | host2 | 5 | -| 1970-01-02T23:00:00 | host2 | 4 | -| 1970-01-03T23:00:00 | host2 | 6 | +| 1970-01-02T23:00:00 | host2 | 7 | +---------------------+-------+----------------------------------+ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1970-01-01T00:00:00+01:00' ORDER BY host, ts; @@ -51,12 +51,12 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1970-01-01T00:00:0 +---------------------+-------+----------------------------------+ | ts | host | MIN(host.val) RANGE 1d FILL NULL | +---------------------+-------+----------------------------------+ +| 1969-12-31T23:00:00 | host1 | 0 | | 1970-01-01T23:00:00 | host1 | 1 | -| 1970-01-02T23:00:00 | host1 | 0 | -| 1970-01-03T23:00:00 | host1 | 2 | +| 1970-01-02T23:00:00 | host1 | 3 | +| 1969-12-31T23:00:00 | host2 | 4 | | 1970-01-01T23:00:00 | host2 | 5 | -| 1970-01-02T23:00:00 | host2 | 4 | -| 1970-01-03T23:00:00 | host2 | 6 | +| 1970-01-02T23:00:00 | host2 | 7 | +---------------------+-------+----------------------------------+ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '2023-01-01T00:00:00+01:00' ORDER BY host, ts; @@ -64,12 +64,12 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '2023-01-01T00:00:0 +---------------------+-------+----------------------------------+ | ts | host | MIN(host.val) RANGE 1d FILL NULL | +---------------------+-------+----------------------------------+ +| 1969-12-31T23:00:00 | host1 | 0 | | 1970-01-01T23:00:00 | host1 | 1 | -| 1970-01-02T23:00:00 | host1 | 0 | -| 1970-01-03T23:00:00 | host1 | 2 | +| 1970-01-02T23:00:00 | host1 | 3 | +| 1969-12-31T23:00:00 | host2 | 4 | | 1970-01-01T23:00:00 | host2 | 5 | -| 1970-01-02T23:00:00 | host2 | 4 | -| 1970-01-03T23:00:00 | host2 | 6 | +| 1970-01-02T23:00:00 | host2 | 7 | +---------------------+-------+----------------------------------+ SELECT ts, min(val) RANGE (INTERVAL '1' day) FROM host ALIGN (INTERVAL '1' day) TO '1900-01-01T00:00:00+01:00' by (1) ORDER BY ts; @@ -77,9 +77,9 @@ SELECT ts, min(val) RANGE (INTERVAL '1' day) FROM host ALIGN (INTERVAL '1' day) +---------------------+----------------------------------------------------------------------------+ | ts | MIN(host.val) RANGE IntervalMonthDayNano("18446744073709551616") FILL NULL | +---------------------+----------------------------------------------------------------------------+ +| 1969-12-31T23:00:00 | 0 | | 1970-01-01T23:00:00 | 1 | -| 1970-01-02T23:00:00 | 0 | -| 1970-01-03T23:00:00 | 2 | +| 1970-01-02T23:00:00 | 3 | +---------------------+----------------------------------------------------------------------------+ DROP TABLE host; diff --git a/tests/cases/standalone/common/range/to.sql b/tests/cases/standalone/common/range/to.sql index ba4a001a48ca..19b2ec19a2b5 100644 --- a/tests/cases/standalone/common/range/to.sql +++ b/tests/cases/standalone/common/range/to.sql @@ -5,14 +5,14 @@ CREATE TABLE host ( ); INSERT INTO TABLE host VALUES - ("1970-01-01T23:30:00+00:00", 'host1', 0), - ("1970-01-01T22:30:00+00:00", 'host1', 1), - ("1970-01-02T23:30:00+00:00", 'host1', 2), - ("1970-01-02T22:30:00+00:00", 'host1', 3), - ("1970-01-01T23:30:00+00:00", 'host2', 4), - ("1970-01-01T22:30:00+00:00", 'host2', 5), - ("1970-01-02T23:30:00+00:00", 'host2', 6), - ("1970-01-02T22:30:00+00:00", 'host2', 7); + ("1970-01-01T22:30:00+00:00", 'host1', 0), + ("1970-01-01T23:30:00+00:00", 'host1', 1), + ("1970-01-02T22:30:00+00:00", 'host1', 2), + ("1970-01-02T23:30:00+00:00", 'host1', 3), + ("1970-01-01T22:30:00+00:00", 'host2', 4), + ("1970-01-01T23:30:00+00:00", 'host2', 5), + ("1970-01-02T22:30:00+00:00", 'host2', 6), + ("1970-01-02T23:30:00+00:00", 'host2', 7); SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts;