Note
For V4.4.2, this function is available starting with V4.4.2 BP1.
For V4.6.x, this function is available starting with V4.6.1.
Declaration
WINDOW_FUNNEL(window, mode, timestamp, cond1, cond2, ..., condN)
Description
WINDOW_FUNNEL is a funnel analysis aggregate function that calculates the maximum number of steps that meet the condition in sequence within a specified time window.
This function is compatible with Hologres/ClickHouse syntax.
Parameters
Parameters |
Type |
Description |
|---|---|---|
| window | BIGINT |
Indicates the size of the sliding time window for statistics. The unit depends ontimestampcolumns.
NoticeThis parameter must be a constant expression. If no data meets the first condition, the function returns 0. |
| mode | VARCHAR |
Represents the matching pattern. Valid values:
|
| timestamp | DATE/INT/NUMBER |
A column that represents a timestamp. |
| cond1, cond2, ..., condN | BOOLEAN |
Represents a conditional event chain, which is a Boolean expression that supports up to 256 events. |
Response parameters
- Returns a
UINT32value in the range [0, N], where N is the number of conditional events. - Indicates the maximum number of steps matched in sequence from the first condition within the specified time window.
Examples
Create the table
test_tbl1.obclient> CREATE TABLE test_tbl1 (col1 INT, col2 DATE, col3 VARCHAR2(50));Insert test data into the
test_tbl1table.obclient> INSERT INTO test_tbl1 VALUES (1, TO_DATE('2026-01-01 10:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'step1'), (1, TO_DATE('2026-01-01 10:05:00', 'YYYY-MM-DD HH24:MI:SS'), 'step2'), (1, TO_DATE('2026-01-01 10:09:00', 'YYYY-MM-DD HH24:MI:SS'), 'step3'), -- Within a 10-minute window (2, TO_DATE('2026-01-01 11:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'step1'), (2, TO_DATE('2026-01-01 11:05:00', 'YYYY-MM-DD HH24:MI:SS'), 'step2'), (2, TO_DATE('2026-01-01 11:15:00', 'YYYY-MM-DD HH24:MI:SS'), 'step3'), -- Outside the 10-minute window (3, TO_DATE('2026-01-01 11:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'step1'), (3, TO_DATE('2026-01-01 11:01:00', 'YYYY-MM-DD HH24:MI:SS'), 'step2'), (3, TO_DATE('2026-01-01 11:02:00', 'YYYY-MM-DD HH24:MI:SS'), 'step1'), -- duplicate step1 (3, TO_DATE('2026-01-01 11:03:00', 'YYYY-MM-DD HH24:MI:SS'), 'step3');Group by
col1. The value ofcol1is either1or2. Calculate the funnel stage progress for each group, where users (identified bycol2) complete the 'step1' → 'step2' → 'step3' process within 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;The return result is as follows:
+------+--------------+ | COL1 | FUNNEL_STAGE | +------+--------------+ | 1 | 3 | | 2 | 2 | +------+--------------+ 2 rows in setComparison of different modes: Displays the differences between the
defaultmode and thestrict_deduplicationmode.defaultmode: Group bycol1and count the progress of users (col2) who completed the funnel stage of the 'step1' → 'step2' → 'step3' process within 1,800 seconds whencol1 = 3.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 return result is as follows:
+------+--------------+ | COL1 | FUNNEL_STAGE | +------+--------------+ | 3 | 3 | +------+--------------+ 1 row in setstrict_deduplicationmode (stops upon encountering duplicate events): Group bycol1and count the progress of users withcol1 = 3(identified bycol2) completing the funnel stage of the 'step1' → 'step2' → 'step3' process 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
