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

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


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new bb6641b63e0 [cherry-pick](branch-21) add more signatures for lag/lead 
fucntion (#47940) (#48076)
bb6641b63e0 is described below

commit bb6641b63e04b6ce7853c829541074ab3729c3d2
Author: zhangstar333 <[email protected]>
AuthorDate: Wed Feb 19 20:41:40 2025 +0800

    [cherry-pick](branch-21) add more signatures for lag/lead fucntion (#47940) 
(#48076)
---
 .../trees/expressions/functions/window/Lag.java    |  34 +++++++++++++--------
 .../trees/expressions/functions/window/Lead.java   |  34 +++++++++++++--------
 .../data/correctness_p0/test_lag_lead_window.out   | Bin 844 -> 1402 bytes
 .../window_functions/test_window_function.out      | Bin 10367 -> 11741 bytes
 .../window_functions/test_window_function.out      | Bin 10367 -> 11741 bytes
 .../correctness_p0/test_lag_lead_window.groovy     |   9 ++++++
 .../window_functions/test_window_function.groovy   |  33 ++++++++------------
 .../window_functions/test_window_function.groovy   |  34 +++++++++------------
 8 files changed, 80 insertions(+), 64 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 7f7c9511e81..fc74cadebfc 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
@@ -21,7 +21,9 @@ import org.apache.doris.catalog.FunctionSignature;
 import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
 import org.apache.doris.nereids.trees.expressions.shape.TernaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.BigIntType;
@@ -39,9 +41,11 @@ public class Lag extends WindowFunction implements 
TernaryExpression, Explicitly
 
     static {
         List<FunctionSignature> signatures = Lists.newArrayList();
-        trivialTypes.forEach(t ->
-                signatures.add(FunctionSignature.ret(t).args(t, 
BigIntType.INSTANCE, t))
-        );
+        trivialTypes.forEach(t -> {
+            signatures.add(FunctionSignature.ret(t).args(t, 
BigIntType.INSTANCE, t));
+            signatures.add(FunctionSignature.ret(t).args(t, 
BigIntType.INSTANCE));
+            signatures.add(FunctionSignature.ret(t).args(t));
+        });
         SIGNATURES = ImmutableList.copyOf(signatures);
     }
 
@@ -51,21 +55,21 @@ public class Lag extends WindowFunction implements 
TernaryExpression, Explicitly
         super("lag", child, offset, defaultValue);
     }
 
-    private Lag(List<Expression> children) {
-        super("lag", children);
+    public Lag(Expression child, Expression offset) {
+        this(child, offset, new NullLiteral(child.getDataType()));
+    }
+
+    public Lag(Expression child) {
+        this(child, new BigIntLiteral(1L), new 
NullLiteral(child.getDataType()));
     }
 
     public Expression getOffset() {
-        if (children().size() <= 1) {
-            throw new AnalysisException("Not set offset of Lead(): " + 
this.toSql());
-        }
+        Preconditions.checkArgument(children.size() == 3);
         return child(1);
     }
 
     public Expression getDefaultValue() {
-        if (children.size() <= 2) {
-            throw new AnalysisException("Not set default value of Lead(): " + 
this.toSql());
-        }
+        Preconditions.checkArgument(children.size() == 3);
         return child(2);
     }
 
@@ -80,7 +84,13 @@ public class Lag extends WindowFunction implements 
TernaryExpression, Explicitly
     @Override
     public Lag withChildren(List<Expression> children) {
         Preconditions.checkArgument(children.size() >= 1 && children.size() <= 
3);
-        return new Lag(children);
+        if (children.size() == 1) {
+            return new Lag(children.get(0));
+        } else if (children.size() == 2) {
+            return new Lag(children.get(0), children.get(1));
+        } else {
+            return new Lag(children.get(0), children.get(1), children.get(2));
+        }
     }
 
     @Override
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 ec6a4b7b85c..251141a68cb 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
@@ -21,7 +21,9 @@ import org.apache.doris.catalog.FunctionSignature;
 import org.apache.doris.nereids.exceptions.AnalysisException;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import 
org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
 import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
 import org.apache.doris.nereids.trees.expressions.shape.TernaryExpression;
 import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.BigIntType;
@@ -41,9 +43,11 @@ public class Lead extends WindowFunction implements 
TernaryExpression, Explicitl
 
     static {
         List<FunctionSignature> signatures = Lists.newArrayList();
-        trivialTypes.forEach(t ->
-                signatures.add(FunctionSignature.ret(t).args(t, 
BigIntType.INSTANCE, t))
-        );
+        trivialTypes.forEach(t -> {
+            signatures.add(FunctionSignature.ret(t).args(t, 
BigIntType.INSTANCE, t));
+            signatures.add(FunctionSignature.ret(t).args(t, 
BigIntType.INSTANCE));
+            signatures.add(FunctionSignature.ret(t).args(t));
+        });
         SIGNATURES = ImmutableList.copyOf(signatures);
     }
 
@@ -53,21 +57,21 @@ public class Lead extends WindowFunction implements 
TernaryExpression, Explicitl
         super("lead", child, offset, defaultValue);
     }
 
-    private Lead(List<Expression> children) {
-        super("lead", children);
+    public Lead(Expression child, Expression offset) {
+        this(child, offset, new NullLiteral(child.getDataType()));
+    }
+
+    public Lead(Expression child) {
+        this(child, new BigIntLiteral(1L), new 
NullLiteral(child.getDataType()));
     }
 
     public Expression getOffset() {
-        if (children().size() <= 1) {
-            throw new AnalysisException("Not set offset of Lead(): " + 
this.toSql());
-        }
+        Preconditions.checkArgument(children.size() == 3);
         return child(1);
     }
 
     public Expression getDefaultValue() {
-        if (children.size() <= 2) {
-            throw new AnalysisException("Not set default value of Lead(): " + 
this.toSql());
-        }
+        Preconditions.checkArgument(children.size() == 3);
         return child(2);
     }
 
@@ -114,7 +118,13 @@ public class Lead extends WindowFunction implements 
TernaryExpression, Explicitl
     @Override
     public Lead withChildren(List<Expression> children) {
         Preconditions.checkArgument(children.size() >= 1 && children.size() <= 
3);
-        return new Lead(children);
+        if (children.size() == 1) {
+            return new Lead(children.get(0));
+        } else if (children.size() == 2) {
+            return new Lead(children.get(0), children.get(1));
+        } else {
+            return new Lead(children.get(0), children.get(1), children.get(2));
+        }
     }
 
     @Override
diff --git a/regression-test/data/correctness_p0/test_lag_lead_window.out 
b/regression-test/data/correctness_p0/test_lag_lead_window.out
index 0f1a9112dd7..041314a1c65 100644
Binary files a/regression-test/data/correctness_p0/test_lag_lead_window.out and 
b/regression-test/data/correctness_p0/test_lag_lead_window.out differ
diff --git 
a/regression-test/data/nereids_p0/sql_functions/window_functions/test_window_function.out
 
b/regression-test/data/nereids_p0/sql_functions/window_functions/test_window_function.out
index 5cfe5a4280b..c68c93691d3 100644
Binary files 
a/regression-test/data/nereids_p0/sql_functions/window_functions/test_window_function.out
 and 
b/regression-test/data/nereids_p0/sql_functions/window_functions/test_window_function.out
 differ
diff --git 
a/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
 
b/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
index 5cfe5a4280b..c68c93691d3 100644
Binary files 
a/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
 and 
b/regression-test/data/query_p0/sql_functions/window_functions/test_window_function.out
 differ
diff --git a/regression-test/suites/correctness_p0/test_lag_lead_window.groovy 
b/regression-test/suites/correctness_p0/test_lag_lead_window.groovy
index cf76d541e6e..1dfccca58ee 100644
--- a/regression-test/suites/correctness_p0/test_lag_lead_window.groovy
+++ b/regression-test/suites/correctness_p0/test_lag_lead_window.groovy
@@ -51,5 +51,14 @@ suite("test_lag_lead_window") {
     qt_select_default """ select id, create_time, lead(create_time, 1, 
'2022-09-06 00:00:00') over
                           (order by create_time desc) as "prev_time" from 
test1; """
     qt_select_default """ select id, create_time, lead(create_time, 1, 
date_sub('2022-09-06 00:00:00', interval 7 day)) over (order by create_time 
desc) as "prev_time" from test1; """
+
+    qt_select_lag_1 """ select id, create_time, lag(create_time) 
over(partition by id) as "prev_time" from test1 order by 1 ,2 ; """
+    qt_select_lag_2 """ select id, create_time, lag(create_time,1) 
over(partition by id) as "prev_time" from test1 order by 1 ,2 ; """
+    qt_select_lag_3 """ select id, create_time, lag(create_time,1,NULL) 
over(partition by id) as "prev_time" from test1 order by 1 ,2 ; """
+    qt_select_lag_4 """ select id, create_time, lead(create_time) 
over(partition by id) as "prev_time" from test1 order by 1 ,2 ; """
+    qt_select_lag_5 """ select id, create_time, lead(create_time,1) 
over(partition by id) as "prev_time" from test1 order by 1 ,2 ; """
+    qt_select_lag_6 """ select id, create_time, lead(create_time,1,NULL) 
over(partition by id) as "prev_time" from test1 order by 1 ,2 ; """
+
     sql """ DROP TABLE IF EXISTS test1 """
+
 }
diff --git 
a/regression-test/suites/nereids_p0/sql_functions/window_functions/test_window_function.groovy
 
b/regression-test/suites/nereids_p0/sql_functions/window_functions/test_window_function.groovy
index 3b038340c7f..946f671bb06 100644
--- 
a/regression-test/suites/nereids_p0/sql_functions/window_functions/test_window_function.groovy
+++ 
b/regression-test/suites/nereids_p0/sql_functions/window_functions/test_window_function.groovy
@@ -366,34 +366,27 @@ suite("test_window_function") {
                     rows between unbounded preceding and current row)
                     as wj from baseall order by ${k1}, wj"""
 
-    // test error
-    test {
-        sql("select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ 
${k1}, lag(${k2}) over (partition by ${k1} order by ${k3}) from baseall")
-        exception ""
-    }
+    qt_lag_1 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1},${k2}, 
lag(${k2}) over (partition by ${k1} order by ${k3},${k2}) from baseall order by 
1,2;"
+    
     test {
         sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lag(${k2}, -1, 1) over (partition by ${k1} order by ${k3}) from baseall"
         exception ""
     }
-    test {
-        sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lag(${k2}, 1) over (partition by ${k1} order by ${k3}) from baseall"
-        exception ""
-    }
-    test {
-        sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lead(${k2}) over (partition by ${k1} order by ${k3}) from baseall"
-        exception ""
-    }
+    
+    qt_lag_2 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, ${k2}, 
lag(${k2}, 1) over (partition by ${k1} order by ${k3},${k2}) from baseall order 
by 1,2;"
+    
+    qt_lead_1 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, 
${k2}, lead(${k2}) over (partition by ${k1} order by ${k3},${k2}) from baseall 
order by 1,2;"
+    
     test {
         sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lead(${k2}, -1, 1) over (partition by ${k1} order by ${k3}) from baseall"
         exception ""
     }
-    test {
-        sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lead(${k2}, 1) over (partition by ${k1} order by ${k3}) from baseall"
-        exception ""
-    }
-    qt_window_error1"""select 
/*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, first_value(${k2}) 
over (partition by ${k1}) from baseall order by ${k1}"""
-    qt_window_error2"""select 
/*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, first_value(${k2}) 
over (order by ${k3}) from baseall"""
-    qt_window_error3"""select 
/*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, max(${k2}) over 
(order by ${k3}) from baseall"""
+    
+    qt_lead_2 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, 
${k2}, lead(${k2}, 1) over (partition by ${k1} order by ${k3},${k2}) from 
baseall order by 1,2;"
+    
+    qt_window_error1"""select /*+SET_VAR(parallel_pipeline_task_num=1) */ 
${k1}, first_value(${k2}) over (partition by ${k1}) from baseall order by 
${k1}"""
+    qt_window_error2"""select /*+SET_VAR(parallel_pipeline_task_num=1) */ 
${k1}, first_value(${k2}) over (order by ${k3}) from baseall"""
+    qt_window_error3"""select /*+SET_VAR(parallel_pipeline_task_num=1) */ 
${k1}, max(${k2}) over (order by ${k3}) from baseall"""
     test {
         sql"""select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ 
${k1}, sum(${k2}) over (partition by ${k1} order by ${k3} rows
             between current row and unbounded preceding) as wj
diff --git 
a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
index 7354625c1cd..b20776ad6c5 100644
--- 
a/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/window_functions/test_window_function.groovy
@@ -364,34 +364,28 @@ suite("test_window_function") {
                     rows between unbounded preceding and current row)
                     as wj from baseall order by ${k1}, wj"""
 
-    // test error
-    test {
-        sql("select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ 
${k1}, lag(${k2}) over (partition by ${k1} order by ${k3}) from baseall")
-        exception ""
-    }
+    qt_lag_1 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, ${k2}, 
lag(${k2}) over (partition by ${k1} order by ${k3},${k2}) from baseall order by 
1,2;"
+
     test {
         sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lag(${k2}, -1, 1) over (partition by ${k1} order by ${k3}) from baseall"
         exception ""
     }
-    test {
-        sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lag(${k2}, 1) over (partition by ${k1} order by ${k3}) from baseall"
-        exception ""
-    }
-    test {
-        sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lead(${k2}) over (partition by ${k1} order by ${k3}) from baseall"
-        exception ""
-    }
+
+    qt_lag_2 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, 
${k2},lag(${k2}, 1) over (partition by ${k1} order by ${k3}, ${k2}) from 
baseall order by 1,2;"
+
+
+    qt_lead_1 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, 
${k2}, lead(${k2}) over (partition by ${k1} order by ${k3}, ${k2}) from baseall 
order by 1,2;"
+
     test {
         sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lead(${k2}, -1, 1) over (partition by ${k1} order by ${k3}) from baseall"
         exception ""
     }
-    test {
-        sql"select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, 
lead(${k2}, 1) over (partition by ${k1} order by ${k3}) from baseall"
-        exception ""
-    }
-    qt_window_error1"""select 
/*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, first_value(${k2}) 
over (partition by ${k1}) from baseall order by ${k1}"""
-    qt_window_error2"""select 
/*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, first_value(${k2}) 
over (order by ${k3}) from baseall"""
-    qt_window_error3"""select 
/*+SET_VAR(parallel_fragment_exec_instance_num=1) */ ${k1}, max(${k2}) over 
(order by ${k3}) from baseall"""
+    
+    qt_lead_2 "select /*+SET_VAR(parallel_pipeline_task_num=1) */ ${k1}, 
${k2}, lead(${k2}, 1) over (partition by ${k1} order by ${k3},${k2}) from 
baseall order by 1,2;"
+    
+    qt_window_error1"""select /*+SET_VAR(parallel_pipeline_task_num=1) */ 
${k1}, first_value(${k2}) over (partition by ${k1}) from baseall order by 
${k1}"""
+    qt_window_error2"""select /*+SET_VAR(parallel_pipeline_task_num=1) */ 
${k1}, first_value(${k2}) over (order by ${k3}) from baseall"""
+    qt_window_error3"""select /*+SET_VAR(parallel_pipeline_task_num=1) */ 
${k1}, max(${k2}) over (order by ${k3}) from baseall"""
     test {
         sql"""select /*+SET_VAR(parallel_fragment_exec_instance_num=1) */ 
${k1}, sum(${k2}) over (partition by ${k1} order by ${k3} rows
             between current row and unbounded preceding) as wj


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to