diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lag.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lag.java index d18a30b77cb740..42b41a1355661a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lag.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lag.java @@ -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()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lead.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lead.java index 04b62d76865aa9..004b5195c0cdaa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lead.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/window/Lead.java @@ -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()); } diff --git a/regression-test/data/nereids_syntax_p0/window_function.out b/regression-test/data/nereids_syntax_p0/window_function.out index 5e91a4682d1bd1..856adad0ff0030 100644 --- a/regression-test/data/nereids_syntax_p0/window_function.out +++ b/regression-test/data/nereids_syntax_p0/window_function.out @@ -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 + diff --git a/regression-test/suites/nereids_syntax_p0/window_function.groovy b/regression-test/suites/nereids_syntax_p0/window_function.groovy index 538038c774488c..bdce97138b7130 100644 --- a/regression-test/suites/nereids_syntax_p0/window_function.groovy +++ b/regression-test/suites/nereids_syntax_p0/window_function.groovy @@ -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" }