Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Dec 5, 2024
1 parent 2249738 commit a9b8510
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ struct CopiedValue : public Value<ColVecType, arg_is_nullable> {
}
}

size_t offset_pos() { return 0; }
size_t offset_pos() {
DCHECK(false) << " should call this in CopiedValue";
return 0;
}

private:
Field _copied_value;
Expand Down
40 changes: 40 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 @@ -61,3 +61,43 @@ b 3 3 \N 5
b \N 3 \N 6
b 2 3 \N 7

-- !select_default_desc --
a 2 3
a \N 2
a \N 1
a 1 0
b 2 7
b \N 6
b 3 5
b \N 4

-- !select_default_asc --
a 1 0
a \N 1
a \N 2
a 2 3
b \N 4
b 3 5
b \N 6
b 2 7

-- !select_default_last_rewrite_first --
a 1 1 0
a \N 1 1
a \N 1 2
a 2 1 3
b \N \N 4
b 3 3 5
b \N 3 6
b 2 3 7

-- !select_default6 --
a \N 2 \N 0
a 1 2 1 1
a 2 2 2 2
a \N 2 2 3
b \N 2 \N 4
b 3 2 3 5
b \N 2 3 6
b 2 2 2 7

113 changes: 113 additions & 0 deletions regression-test/suites/correctness_p0/test_first_value_window.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,117 @@ suite("test_first_value_window") {
ORDER BY uid, time_s
;
"""
qt_select_default_desc """
SELECT uid
,amt
,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;
"""

qt_select_default_asc """
SELECT uid
,amt
,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 ASC;
"""

// FIRST_VALUE: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
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
,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_default6 """
SELECT uid
,amt
,LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED following) amt1
,LAST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) amt2
,time_s
FROM (
SELECT 'a' AS uid, null AS amt, 0 AS time_s UNION ALL
SELECT 'a' AS uid, 1 AS amt, 1 AS time_s UNION ALL
SELECT 'a' AS uid, 2 AS amt, 2 AS time_s UNION ALL
SELECT 'a' AS uid, null 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
;
"""

// 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;
// """

// 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 a9b8510

Please sign in to comment.