Considerations
This function is introduced in V4.4.2 BP1 for V4.4.2.
Syntax
WINDOW_FUNNEL(window, mode, timestamp, cond1, cond2, ..., condN)
Purpose
WINDOW_FUNNEL is an aggregation funnel analysis function. It calculates the maximum number of steps that meet the conditions in order within the specified time window.
This function is compatible with Hologres/ClickHouse syntax.
Parameters
| Parameter | Type | Description |
|---|---|---|
| window | BIGINT |
Specifies the size of the time window over which statistics are calculated. The unit is determined by the TIMESTAMP column. For example, if the TIMESTAMP column is of type DATE, the unit is days; if it is of type DATETIME, the unit is seconds.
NoticeThis parameter must be a constant expression. If no data matches the first condition, the function returns 0. |
| mode | VARCHAR |
Specifies the match mode, which can be one of the following values:
|
| timestamp | DATE/DATETIME/TIMESTAMP/BIGINT/INT |
The column that stores the timestamp. |
| cond1, cond2, ..., condN | BOOLEAN |
A chain of conditional events, which is a Boolean expression that supports up to 256 events. |
Return description
- Returns a
UINT32type value in the range [0, N], where N is the number of conditional events. - The maximum number of steps matched from the first condition, in sequence, within the specified time window.
Examples
Create the
test_tbl1table.obclient> CREATE TABLE test_tbl1 (col1 INT, col2 DATETIME, col3 VARCHAR(50));Insert test data into the
test_tbl1table.obclient> INSERT INTO test_tbl1 VALUES (1, '2026-01-01 10:00:00', 'step1'), (1, '2026-01-01 10:05:00', 'step2'), (1, '2026-01-01 10:09:00', 'step3'), -- within a 10-minute window (2, '2026-01-01 11:00:00', 'step1'), (2, '2026-01-01 11:05:00', 'step2'), (2, '2026-01-01 11:15:00', 'step3'), -- exceeds 10-minute window (3, '2026-01-01 11:00:00', 'step1'), (3, '2026-01-01 11:01:00', 'step2'), (3, '2026-01-01 11:02:00', 'step1'), -- repeated step1 (3, '2026-01-01 11:03:00', 'step3');Group by
col1(which has values1or2), and count the number of users (identified bycol2) who complete the 'step1' → 'step2' → 'step3' process in 600 seconds.obclient> SELECT col1, WINDOW_FUNNEL( 600, 'default', col2, col3 = 'step1', col3 = 'step2', col3 = 'step3') AS funnel_stage FROM test_tbl1 WHERE col1 IN (1, 2) GROUP BY col1 ORDER BY col1;Here is the result:
+------+--------------+ | col1 | funnel_stage | +------+--------------+ | 1 | 3 | | 2 | 2 | +------+--------------+ 2 rows in setDifferent modes: highlights the differences between the
defaultandstrict_deduplicationmodes.defaultmode: Group data bycol1. Count the users whosecol1 = 3(identified bycol2) who complete the 'step1' → 'step2' → 'step3' funnel in 1800 seconds.obclient> SELECT col1, WINDOW_FUNNEL( 1800, 'default', col2, col3 = 'step1', col3 = 'step2', col3 = 'step3') AS funnel_stage FROM test_tbl1 WHERE col1 = 3 GROUP BY col1;The output is as follows:
+------+--------------+ | col1 | funnel_stage | +------+--------------+ | 3 | 3 | +------+--------------+ 1 row in setstrict_deduplicationmode (stops on duplicates): Group bycol1to track the progress of users withcol1 = 3(identified bycol2) through the funnel stages 'step1' → 'step2' → 'step3' within 1800 seconds.obclient> SELECT col1, WINDOW_FUNNEL( 1800, 'strict_deduplication', col2, col3 = 'step1', col3 = 'step2', col3 = 'step3') AS funnel_stage FROM test_tbl1 WHERE col1 = 3 GROUP BY col1;The return result is as follows:
+------+--------------+ | col1 | funnel_stage | +------+--------------+ | 3 | 2 | +------+--------------+ 1 row in set
