diff --git a/dbms/src/AggregateFunctions/AggregateFunctionWindowFunnel.h b/dbms/src/AggregateFunctions/AggregateFunctionWindowFunnel.h index e19751d8daa..3a1d2adee4a 100644 --- a/dbms/src/AggregateFunctions/AggregateFunctionWindowFunnel.h +++ b/dbms/src/AggregateFunctions/AggregateFunctionWindowFunnel.h @@ -186,6 +186,14 @@ private: { return event_idx + 1; } + else if (strict_order && first_event && events_timestamp[event_idx - 1] == -1) + { + for (size_t event = 0; event < events_timestamp.size(); ++event) + { + if (events_timestamp[event] == -1) + return event; + } + } else if (events_timestamp[event_idx - 1] >= 0 && timestamp <= events_timestamp[event_idx - 1] + window) { events_timestamp[event_idx] = events_timestamp[event_idx - 1]; diff --git a/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.reference b/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.reference index 04851cc0e83..492135567ea 100644 --- a/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.reference +++ b/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.reference @@ -36,6 +36,7 @@ [4, 2] [5, 2] [6, 1] +[7, 1] [1, 2] [2, 2] [3, 0] diff --git a/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.sql b/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.sql index 43ae0197782..5a1610256ac 100644 --- a/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.sql +++ b/dbms/tests/queries/0_stateless/00632_aggregation_window_funnel.sql @@ -63,6 +63,8 @@ insert into funnel_test_strict_order values (1, 6, 'c') (2, 6, 'c') (3, 6, 'b') select user, windowFunnel(86400)(dt, event='a', event='b', event='c') as s from funnel_test_strict_order group by user order by user format JSONCompactEachRow; select user, windowFunnel(86400, 'strict_order')(dt, event='a', event='b', event='c') as s from funnel_test_strict_order group by user order by user format JSONCompactEachRow; select user, windowFunnel(86400, 'strict', 'strict_order')(dt, event='a', event='b', event='c') as s from funnel_test_strict_order group by user order by user format JSONCompactEachRow; +insert into funnel_test_strict_order values (1, 7, 'a') (2, 7, 'c') (3, 7, 'b'); +select user, windowFunnel(10, 'strict_order')(dt, event = 'a', event = 'b', event = 'c') as s from funnel_test_strict_order where user = 7 group by user format JSONCompactEachRow; drop table funnel_test_strict_order; drop table if exists funnel_test_non_null;