diff --git a/be/src/exprs/aggregate_functions.cpp b/be/src/exprs/aggregate_functions.cpp index dbd1b1c818..590e07838a 100644 --- a/be/src/exprs/aggregate_functions.cpp +++ b/be/src/exprs/aggregate_functions.cpp @@ -2500,9 +2500,10 @@ void AggregateFunctions::window_funnel_init(FunctionContext* ctx, StringVal* dst WindowFunnelState* state = new WindowFunnelState(); dst->ptr = (uint8_t*)state; // constant args at index 0 and 1 - DCHECK(ctx->is_arg_constant(0)); - BigIntVal* window = reinterpret_cast(ctx->get_constant_arg(0)); - state->window = window->val; + if (ctx->is_arg_constant(0)) { + BigIntVal* window = reinterpret_cast(ctx->get_constant_arg(0)); + state->window = window->val; + } // TODO handle mode in the future } diff --git a/regression-test/data/query/aggregate/window_funnel.out b/regression-test/data/query/aggregate/window_funnel.out new file mode 100644 index 0000000000..d830ba5591 --- /dev/null +++ b/regression-test/data/query/aggregate/window_funnel.out @@ -0,0 +1,7 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !window_funnel -- +1 + +-- !window_funnel -- +2 + diff --git a/regression-test/suites/query/aggregate/window_funnel.groovy b/regression-test/suites/query/aggregate/window_funnel.groovy new file mode 100644 index 0000000000..279b433b53 --- /dev/null +++ b/regression-test/suites/query/aggregate/window_funnel.groovy @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// The cases is copied from https://github.com/trinodb/trino/tree/master +// /testing/trino-product-tests/src/main/resources/sql-tests/testcases/aggregate +// and modified by Doris. + +suite("window_funnel") { + def tableName = "windowfunnel_test" + + sql """ DROP TABLE IF EXISTS ${tableName} """ + sql """ + CREATE TABLE IF NOT EXISTS ${tableName} ( + xwho varchar(50) NULL COMMENT 'xwho', + xwhen datetime COMMENT 'xwhen', + xwhat int NULL COMMENT 'xwhat' + ) + DUPLICATE KEY(xwho) + DISTRIBUTED BY HASH(xwho) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1" + ); + """ + sql "INSERT into ${tableName} (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 10:41:00', 1)" + sql "INSERT INTO ${tableName} (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 13:28:02', 2)" + sql "INSERT INTO ${tableName} (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 16:15:01', 3)" + sql "INSERT INTO ${tableName} (xwho, xwhen, xwhat) VALUES('1', '2022-03-12 19:05:04', 4)" + + qt_window_funnel """ select + window_funnel( + 1, + 'default', + t.xwhen, + t.xwhat = 1, + t.xwhat = 2 + ) AS level + from ${tableName} t; + """ + qt_window_funnel """ select + window_funnel( + 20000, + 'default', + t.xwhen, + t.xwhat = 1, + t.xwhat = 2 + ) AS level + from ${tableName} t; + """ +}