This is an automated email from the ASF dual-hosted git repository.
morrysnow 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 c53b6a9532 [fix](Nereids) fix nullable() of lead/lag (#17014)
c53b6a9532 is described below
commit c53b6a9532d6af36f983f03b55d6a80067708a2a
Author: YangShaw <[email protected]>
AuthorDate: Fri Feb 24 21:27:44 2023 +0800
[fix](Nereids) fix nullable() of lead/lag (#17014)
fix bug when we use NULL as default value for window function lead() and
lag()
---
.../trees/expressions/functions/window/Lag.java | 14 ++++++++--
.../trees/expressions/functions/window/Lead.java | 14 ++++++++--
.../data/nereids_syntax_p0/window_function.out | 32 ++++++++++++++++++++++
.../nereids_syntax_p0/window_function.groovy | 2 ++
4 files changed, 56 insertions(+), 6 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 9acb49a7fe..1a5fc2debe 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,8 +21,8 @@ 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.functions.PropagateNullable;
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;
@@ -35,8 +35,8 @@ import com.google.common.collect.Lists;
import java.util.List;
/** Window function: lag */
-public class Lag extends WindowFunction implements TernaryExpression,
PropagateNullable,
- ExplicitlyCastableSignature, RequireTrivialTypes {
+public class Lag extends WindowFunction implements TernaryExpression,
ExplicitlyCastableSignature,
+ RequireTrivialTypes {
static {
List<FunctionSignature> signatures = Lists.newArrayList();
@@ -78,6 +78,14 @@ public class Lag extends WindowFunction implements
TernaryExpression, PropagateN
return child(2);
}
+ @Override
+ public boolean nullable() {
+ if (children.size() == 3 && child(2) instanceof NullLiteral) {
+ return true;
+ }
+ return child(0).nullable();
+ }
+
@Override
public Lag withChildren(List<Expression> children) {
Preconditions.checkArgument(children.size() >= 1 && children.size() <=
3);
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 9770a65fc0..9baf523ff0 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,8 +21,8 @@ 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.functions.PropagateNullable;
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;
@@ -37,8 +37,8 @@ import java.util.List;
/**
* Window function: Lead()
*/
-public class Lead extends WindowFunction implements TernaryExpression,
PropagateNullable,
- ExplicitlyCastableSignature, RequireTrivialTypes {
+public class Lead extends WindowFunction implements TernaryExpression,
ExplicitlyCastableSignature,
+ RequireTrivialTypes {
static {
List<FunctionSignature> signatures = Lists.newArrayList();
@@ -80,6 +80,14 @@ public class Lead extends WindowFunction implements
TernaryExpression, Propagate
return child(2);
}
+ @Override
+ public boolean nullable() {
+ if (children.size() == 3 && child(2) instanceof NullLiteral) {
+ return true;
+ }
+ return child(0).nullable();
+ }
+
@Override
public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
return visitor.visitLead(this, context);
diff --git a/regression-test/data/nereids_syntax_p0/window_function.out
b/regression-test/data/nereids_syntax_p0/window_function.out
index 70d9973a60..921703d421 100644
--- a/regression-test/data/nereids_syntax_p0/window_function.out
+++ b/regression-test/data/nereids_syntax_p0/window_function.out
@@ -239,6 +239,38 @@
222
222
+-- !lead --
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+1
+2
+2
+2
+
+-- !lag --
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+1
+1
+1
+2
+2
+2
+
-- !max --
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 33bef9260b..76318169b1 100644
--- a/regression-test/suites/nereids_syntax_p0/window_function.groovy
+++ b/regression-test/suites/nereids_syntax_p0/window_function.groovy
@@ -67,6 +67,8 @@ suite("test_window_function") {
order_qt_last_value "SELECT last_value(c1) over(partition by c3 order by
c2) FROM window_test"
order_qt_lead "SELECT lead(c1, 1, 111) over(partition by c3 order by c2)
FROM window_test"
order_qt_lag "SELECT lag(c1, 1, 222) over(partition by c3 order by c2)
FROM window_test"
+ order_qt_lead "SELECT lead(c1, 3, null) over(partition by c3 order by c2)
FROM window_test"
+ order_qt_lag "SELECT lag(c1, 2, null) over(partition by c3 order by c2)
FROM window_test"
order_qt_max "SELECT max(c1) over(partition by c3 order by c2) FROM
window_test"
order_qt_min "SELECT min(c1) over(partition by c3 order by c2) FROM
window_test"
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]