From 01af7ae3da4b7c784380d1db6c840da5a62508b9 Mon Sep 17 00:00:00 2001 From: zhangstar333 Date: Fri, 6 Dec 2024 11:21:24 +0800 Subject: [PATCH] update case --- .../test_first_value_window.out | 20 +++++ .../test_first_value_window.groovy | 80 +++++++++---------- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/regression-test/data/correctness_p0/test_first_value_window.out b/regression-test/data/correctness_p0/test_first_value_window.out index 9281fc6e7c1f6d..22bf1aa51f48e8 100644 --- a/regression-test/data/correctness_p0/test_first_value_window.out +++ b/regression-test/data/correctness_p0/test_first_value_window.out @@ -101,3 +101,23 @@ b 3 2 3 5 b \N 2 3 6 b 2 2 2 7 +-- !select_default_last_rewrite_first2 -- +a 1 1 0 +a \N 1 1 +a \N 1 2 +a 2 2 3 +b \N \N 4 +b 3 3 5 +b \N 3 6 +b 2 2 7 + +-- !select_default7 -- +a 1 1 1 1 1 0 +a \N 1 1 1 1 1 +a \N 1 1 1 1 2 +a 2 2 2 2 1 3 +b \N \N \N \N \N 4 +b 3 3 3 3 3 5 +b \N 3 3 3 3 6 +b 2 2 2 2 3 7 + diff --git a/regression-test/suites/correctness_p0/test_first_value_window.groovy b/regression-test/suites/correctness_p0/test_first_value_window.groovy index 0149f1f1c2fb56..b3030c4c44c83e 100644 --- a/regression-test/suites/correctness_p0/test_first_value_window.groovy +++ b/regression-test/suites/correctness_p0/test_first_value_window.groovy @@ -237,7 +237,7 @@ suite("test_first_value_window") { qt_select_default_last_rewrite_first """ SELECT uid ,amt - ,(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt3 + ,(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt3 ,time_s FROM ( SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL @@ -272,44 +272,44 @@ suite("test_first_value_window") { ; """ - // the rewrite maybe error, need fix? - // qt_select_default_last_rewrite_first """ - // SELECT uid - // ,amt - // ,(FIRST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt3 - // ,time_s - // FROM ( - // SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL - // SELECT 'a' AS uid, null AS amt, 1 AS time_s UNION ALL - // SELECT 'a' AS uid, null AS amt, 2 AS time_s UNION ALL - // SELECT 'a' AS uid, 2 AS amt, 3 AS time_s UNION ALL - // SELECT 'b' AS uid, null AS amt, 4 AS time_s UNION ALL - // SELECT 'b' AS uid, 3 AS amt, 5 AS time_s UNION ALL - // SELECT 'b' AS uid, null AS amt, 6 AS time_s UNION ALL - // SELECT 'b' AS uid, 2 AS amt, 7 AS time_s - // ) t - // ORDER BY uid, time_s DESC; - // """ + //last value: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW + qt_select_default_last_rewrite_first2 """ + SELECT uid + ,amt + ,(FIRST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt3 + ,time_s + FROM ( + SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 1 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 2 AS time_s UNION ALL + SELECT 'a' AS uid, 2 AS amt, 3 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 4 AS time_s UNION ALL + SELECT 'b' AS uid, 3 AS amt, 5 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 6 AS time_s UNION ALL + SELECT 'b' AS uid, 2 AS amt, 7 AS time_s + ) t + ORDER BY uid, time_s; + """ - // qt_select_default7 """ - // SELECT uid - // ,amt - // ,COALESCE(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) amt1 - // ,COALESCE(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ASC ROWS BETWEEN 100 PRECEDING AND CURRENT ROW)) amt_not - // ,COALESCE(FIRST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt2 - // ,COALESCE(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt3 - // ,time_s - // FROM ( - // SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL - // SELECT 'a' AS uid, null AS amt, 1 AS time_s UNION ALL - // SELECT 'a' AS uid, null AS amt, 2 AS time_s UNION ALL - // SELECT 'a' AS uid, 2 AS amt, 3 AS time_s UNION ALL - // SELECT 'b' AS uid, null AS amt, 4 AS time_s UNION ALL - // SELECT 'b' AS uid, 3 AS amt, 5 AS time_s UNION ALL - // SELECT 'b' AS uid, null AS amt, 6 AS time_s UNION ALL - // SELECT 'b' AS uid, 2 AS amt, 7 AS time_s - // ) t - // ORDER BY uid, time_s - // ; - // """ + qt_select_default7 """ + SELECT uid + ,amt + ,COALESCE(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) amt1 + ,COALESCE(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ASC ROWS BETWEEN 100 PRECEDING AND CURRENT ROW)) amt_not + ,COALESCE(FIRST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt2 + ,COALESCE(LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s DESC ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)) amt3 + ,time_s + FROM ( + SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 1 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 2 AS time_s UNION ALL + SELECT 'a' AS uid, 2 AS amt, 3 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 4 AS time_s UNION ALL + SELECT 'b' AS uid, 3 AS amt, 5 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 6 AS time_s UNION ALL + SELECT 'b' AS uid, 2 AS amt, 7 AS time_s + ) t + ORDER BY uid, time_s + ; + """ }