Skip to content

Commit

Permalink
update case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Dec 6, 2024
1 parent a9b8510 commit 9ccde36
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 40 deletions.
20 changes: 20 additions & 0 deletions regression-test/data/correctness_p0/test_first_value_window.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
;
"""
}

0 comments on commit 9ccde36

Please sign in to comment.