This is an automated email from the ASF dual-hosted git repository.
zhangstar333 pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 73f3e4f83a3 [improve](function) the offset params in lead/lag function
could use 0 (#33174) (#33301)
73f3e4f83a3 is described below
commit 73f3e4f83a33960051e49cbaac1d542c6c89e367
Author: zhangstar333 <[email protected]>
AuthorDate: Wed Apr 10 17:47:06 2024 +0800
[improve](function) the offset params in lead/lag function could use 0
(#33174) (#33301)
---
.../trees/expressions/functions/window/Lag.java | 2 +-
.../trees/expressions/functions/window/Lead.java | 2 +-
.../data/nereids_syntax_p0/window_function.out | 32 ++++++++++++++++++++++
.../nereids_syntax_p0/window_function.groovy | 3 ++
4 files changed, 37 insertions(+), 2 deletions(-)
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 d18a30b77cb..42b41a13556 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 class Lag extends WindowFunction implements
TernaryExpression, Explicitly
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 04b62d76865..004b5195c0c 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 class Lead extends WindowFunction implements
TernaryExpression, Explicitl
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 5e91a4682d1..856adad0ff0 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 538038c7744..bdce97138b7 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"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]