Skip to content

Commit

Permalink
[fix](Nereids) make the type of the first parameter in window_funnel …
Browse files Browse the repository at this point in the history
…is intergerLike (apache#15810)
  • Loading branch information
keanji-x authored Jan 12, 2023
1 parent b86e781 commit 39697bb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public WindowFunnel(boolean distinct, Expression arg0, Expression arg1, Expressi
@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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;

Expand Down Expand Up @@ -433,6 +434,10 @@ public boolean isBooleanType() {
return this instanceof BooleanType;
}

public boolean isIntegerLikeType() {
return this instanceof IntegralType;
}

public boolean isTinyIntType() {
return this instanceof TinyIntType;
}
Expand Down
7 changes: 7 additions & 0 deletions regression-test/data/nereids_syntax_p0/function.out
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@

-- !ceil --
3

-- !window_funnel --
1

-- !window_funnel --
2

43 changes: 43 additions & 0 deletions regression-test/suites/nereids_syntax_p0/function.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
}

0 comments on commit 39697bb

Please sign in to comment.