From 39697bb83eb7b88b35752e97929da676c72b17bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E5=81=A5?= Date: Thu, 12 Jan 2023 11:53:28 +0800 Subject: [PATCH] [fix](Nereids) make the type of the first parameter in window_funnel is intergerLike (#15810) --- .../functions/agg/WindowFunnel.java | 2 +- .../apache/doris/nereids/types/DataType.java | 5 +++ .../data/nereids_syntax_p0/function.out | 7 +++ .../suites/nereids_syntax_p0/function.groovy | 43 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/WindowFunnel.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/WindowFunnel.java index c73a2149e1..c37d66471d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/WindowFunnel.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/WindowFunnel.java @@ -74,7 +74,7 @@ public class WindowFunnel extends AggregateFunction @Override public void checkLegalityBeforeTypeCoercion() { String functionName = getName(); - if (!getArgumentType(0).isIntegerType()) { + if (!getArgumentType(0).isIntegerLikeType()) { throw new AnalysisException("The window params of " + functionName + " function must be integer"); } if (!getArgumentType(1).isStringLikeType()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java index b76eb19745..89d2b11e92 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/DataType.java @@ -29,6 +29,7 @@ import org.apache.doris.nereids.trees.expressions.literal.Literal; import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral; import org.apache.doris.nereids.types.coercion.AbstractDataType; import org.apache.doris.nereids.types.coercion.CharacterType; +import org.apache.doris.nereids.types.coercion.IntegralType; import org.apache.doris.nereids.types.coercion.NumericType; import org.apache.doris.nereids.types.coercion.PrimitiveType; @@ -433,6 +434,10 @@ public abstract class DataType implements AbstractDataType { return this instanceof BooleanType; } + public boolean isIntegerLikeType() { + return this instanceof IntegralType; + } + public boolean isTinyIntType() { return this instanceof TinyIntType; } diff --git a/regression-test/data/nereids_syntax_p0/function.out b/regression-test/data/nereids_syntax_p0/function.out index f41cd574a8..3172837dc8 100644 --- a/regression-test/data/nereids_syntax_p0/function.out +++ b/regression-test/data/nereids_syntax_p0/function.out @@ -53,3 +53,10 @@ -- !ceil -- 3 + +-- !window_funnel -- +1 + +-- !window_funnel -- +2 + diff --git a/regression-test/suites/nereids_syntax_p0/function.groovy b/regression-test/suites/nereids_syntax_p0/function.groovy index efd1f1b698..a5398e200e 100644 --- a/regression-test/suites/nereids_syntax_p0/function.groovy +++ b/regression-test/suites/nereids_syntax_p0/function.groovy @@ -125,5 +125,48 @@ suite("nereids_function") { sql "select left('abcd', 3), right('abcd', 3)" result([['abc', 'bcd']]) } + + // test window_funnel function + sql """ DROP TABLE IF EXISTS window_funnel_test """ + sql """ + CREATE TABLE IF NOT EXISTS window_funnel_test ( + xwho varchar(50) NULL COMMENT 'xwho', + xwhen datetimev2(3) COMMENT 'xwhen', + xwhat int NULL COMMENT 'xwhat' + ) + DUPLICATE KEY(xwho) + DISTRIBUTED BY HASH(xwho) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1" + ); + """ + + sql "INSERT into window_funnel_test (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 10:41:00.111111', 1)" + sql "INSERT INTO window_funnel_test (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 13:28:02.111111', 2)" + sql "INSERT INTO window_funnel_test (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 16:15:01.111111', 3)" + sql "INSERT INTO window_funnel_test (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 19:05:04.111111', 4)" + + qt_window_funnel """ + select + window_funnel( + 1, + 'default', + t.xwhen, + t.xwhat = 1, + t.xwhat = 2 + ) AS level + from window_funnel_test t; + """ + qt_window_funnel """ + select + window_funnel( + 20000, + 'default', + t.xwhen, + t.xwhat = 1, + t.xwhat = 2 + ) AS level + from window_funnel_test t; + """ }