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 |
Represents the size of the sliding time window for statistics, in units oftimestampColumn (for example,timestampColumn asDATEWhen the unit is days, the value range is from 1 to 365. When the unit is months, the value range is from 1 to 12.DATETIME, in seconds).
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/DATETIME/TIMESTAMP/BIGINT/INT |
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 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'), -- Outside the 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'), -- duplicate step1 (3, '2026-01-01 11:03:00', 'step3');Group by
col1. The value ofcol1can be1or2. Calculate the funnel stage progress for users (identified bycol2) who complete the 'step1' → 'step2' → 'step3' process within 600 seconds in each group.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: Describes the differences between the
defaultmode and thestrict_deduplicationmode.default: Group bycol1and count the progress of users (col2) who completed the funnel stage of the 'step1' → 'step2' → 'step3' process within 1,800 seconds wherecol1 = 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 (stop upon duplicate events): Group bycol1and count the progress of users (col2) who completed the funnel stage of the 'step1' → 'step2' → 'step3' process within 1800 seconds for whomcol1 = 3.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
