This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e2d9014920 [improve](function) the offset params in lead/lag function 
could use 0 (#33174)
3e2d9014920 is described below

commit 3e2d9014920db4a99e5d909e2865ac31790b36e1
Author: zhangstar333 <87313068+zhangstar...@users.noreply.github.com>
AuthorDate: Fri Apr 5 07:56:43 2024 +0800

    [improve](function) the offset params in lead/lag function could use 0 
(#33174)
---
 .../nereids/trees/expressions/functions/window/Lag.java      |  2 +-
 .../nereids/trees/expressions/functions/window/Lead.java     |  2 +-
 .../correctness_p0/test_always_nullable_window_function.out  | 12 ++++++++++++
 .../test_always_nullable_window_function.groovy              |  8 +++++++-
 4 files changed, 21 insertions(+), 3 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/correctness_p0/test_always_nullable_window_function.out 
b/regression-test/data/correctness_p0/test_always_nullable_window_function.out
index 93605da2661..f38c4e9c9f7 100644
--- 
a/regression-test/data/correctness_p0/test_always_nullable_window_function.out
+++ 
b/regression-test/data/correctness_p0/test_always_nullable_window_function.out
@@ -95,3 +95,15 @@
 24     02-24-10-21     1       \N      \N      \N      \N      \N      \N      
\N      \N
 24     02-24-10-21     1       1       1       1       1.0     1       1       
\N      \N
 
+-- !select_lead_lag --
+1      1       1       04-21-11        21
+1      1       1       04-21-11        21
+0      0       0       04-22-10-21     22
+0      0       0       04-22-10-21     22
+1      1       1       04-22-10-21     22
+1      1       1       04-22-10-21     22
+1      1       1       04-23-10        23
+1      1       1       04-23-10        23
+1      1       1       02-24-10-21     24
+1      1       1       02-24-10-21     24
+
diff --git 
a/regression-test/suites/correctness_p0/test_always_nullable_window_function.groovy
 
b/regression-test/suites/correctness_p0/test_always_nullable_window_function.groovy
index 3ac6f17d8cd..a0774114176 100644
--- 
a/regression-test/suites/correctness_p0/test_always_nullable_window_function.groovy
+++ 
b/regression-test/suites/correctness_p0/test_always_nullable_window_function.groovy
@@ -172,5 +172,11 @@ suite("test_always_nullable_window_function") {
             lead(state, 2, null) over (partition by myday order by time_col) 
lead_value
         from ${nullableTableName} order by myday, time_col, state;
     """
-
+    sql "set enable_nereids_planner = true"
+    qt_select_lead_lag """
+        select lag(state, 0, 22) over (partition by myday order by time_col) 
lag_value,
+               lead(state, 0, 33) over (partition by myday order by time_col) 
lead_value,
+               state,time_col,myday
+               from ${nullableTableName} order by myday, time_col, state;
+    """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to