You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/10/18 13:38:22 UTC
[incubator-doris] branch master updated: [BUG] Ensure that the
correct lead/lag function is selected (#4732)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 34d5ab8 [BUG] Ensure that the correct lead/lag function is selected (#4732)
34d5ab8 is described below
commit 34d5ab8e073e4be0690ed5f508c5711d32365c4e
Author: HangyuanLiu <46...@qq.com>
AuthorDate: Sun Oct 18 21:38:10 2020 +0800
[BUG] Ensure that the correct lead/lag function is selected (#4732)
* fix
* fix
---
.../org/apache/doris/analysis/FunctionCallExpr.java | 9 ++++++---
.../org/apache/doris/planner/QueryPlanTest.java | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index 35873a2..d43178d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -334,10 +334,13 @@ public class FunctionCallExpr extends Expr {
throw new AnalysisException(fnName.getFunction() + " only used in analytic function");
} else {
if (children.size() > 2) {
- if (!getChild(2).isConstant()) {
+ if (!getChild(1).isConstant() || !getChild(2).isConstant()) {
throw new AnalysisException(
- "The default parameter (parameter 3) of LAG must be a constant: "
- + this.toSql());
+ "The default parameter (parameter 2 or parameter 3) of LEAD/LAG must be a constant: " + this.toSql());
+ }
+ uncheckedCastChild(Type.BIGINT, 1);
+ if (!getChild(2).type.matchesType(getChild(0).type) && !getChild(2).type.matchesType(Type.NULL)) {
+ uncheckedCastChild(getChild(0).type, 2);
}
}
return;
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
index f2b93fb..ba3e24c 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
@@ -1310,6 +1310,27 @@ public class QueryPlanTest {
System.out.println(explainString);
Assert.assertTrue(explainString.contains("AGGREGATE (update finalize)"));
}
+
+ @Test
+ public void testLeadAndLagFunction() throws Exception {
+ connectContext.setDatabase("default_cluster:test");
+
+ String queryStr = "explain select time, lead(query_time, 1, NULL) over () as time2 from test.test1";
+ String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
+ Assert.assertTrue(explainString.contains("lead(`query_time`, 1, NULL)"));
+
+ queryStr = "explain select time, lead(query_time, 1, 2) over () as time2 from test.test1";
+ explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
+ Assert.assertTrue(explainString.contains("lead(`query_time`, 1, 2)"));
+
+ queryStr = "explain select time, lead(time, 1, '2020-01-01 00:00:00') over () as time2 from test.test1";
+ explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
+ Assert.assertTrue(explainString.contains("lead(`time`, 1, '2020-01-01 00:00:00')"));
+
+ queryStr = "explain select time, lag(query_time, 1, 2) over () as time2 from test.test1";
+ explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, queryStr);
+ Assert.assertTrue(explainString.contains("lag(`query_time`, 1, 2)"));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org