Skip to content

Commit

Permalink
[improve](function) the offset params in lead/lag function could use 0 (
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangstar333 committed Apr 10, 2024
1 parent b7ebbd8 commit 73f3e4f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void checkLegalityBeforeTypeCoercion() {
if (children().size() >= 2) {
checkValidParams(getOffset(), true);
if (getOffset() instanceof Literal) {
if (((Literal) getOffset()).getDouble() <= 0) {
if (((Literal) getOffset()).getDouble() < 0) {
throw new AnalysisException(
"The offset parameter of LAG must be a constant positive integer: " + this.toSql());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void checkLegalityBeforeTypeCoercion() {
if (children().size() >= 2) {
checkValidParams(getOffset(), true);
if (getOffset() instanceof Literal) {
if (((Literal) getOffset()).getDouble() <= 0) {
if (((Literal) getOffset()).getDouble() < 0) {
throw new AnalysisException(
"The offset parameter of LEAD must be a constant positive integer: " + this.toSql());
}
Expand Down
32 changes: 32 additions & 0 deletions regression-test/data/nereids_syntax_p0/window_function.out
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,35 @@
1.0
1.5

-- !select_lead --
1
2
1
2
1
2
1
2
1
2
2
1
1
1

-- !select_lag --
1
2
1
2
1
2
1
2
1
2
2
1
1
1

Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,7 @@ suite("window_function") {
left join adj_nullable_2 on c1 = c4
where c6 is not null;
"""

qt_select_lead "SELECT lead(c1, 0, 111) over(partition by c3 order by c2) FROM window_test"
qt_select_lag "SELECT lag(c1, 0, 222) over(partition by c3 order by c2) FROM window_test"
}

0 comments on commit 73f3e4f

Please sign in to comment.