Updated on 2024-09-02 GMT+08:00

Funnel and Retention Functions

Funnel and retention functions are supported only in cluster 8.3.0 and later versions.

windowfunnel

The windowfunnel function is used to search for the event list in the sliding time window and calculate the maximum length of the event list that matches the condition events. Given a list of user-defined events, GaussDB(DWS) finds the longest sequential match starting from the first event and returns the length of the match. Once the matching fails, the entire matching ends. Example:

Assume that the window is large enough:

  • The condition events are c1, c2, and c3, but the user data is c1, c2, c3, and c4. So, c1, c2, and c3 are matched, and the return value of the function is 3.
  • The condition events are c1, c2, and c3, but the user data is c4, c3, c2, and c1. So, c1 is matched, and the return value of the function is 1.
  • The condition events are c1, c2, and c3, but the user data is c4 and c3. So, no event is matched, and the return value of the function is 0.

Syntax

1
windowFunnel(window, mode, timestamp, cond1, cond2, ..., condN)

Input parameters

  • window: bigint type. It indicates the size of the sliding time window. The unit is second.
  • mode: text type. Currently, only the Default mode is supported. For other modes, an error is reported. In the Default mode, it matches as many events as possible, starting from the first event in the window.
  • timestamp: time range when an event occurs. The timestamp without time zone, timestamp with time zone, date, int and bigint types are supported.
  • cond: variable-length Boolean array. It indicates the condition. GaussDB(DWS) supports only 1 to 32 conditions. If the number of conditions is not within the range, an error is reported.

Return values

level: int type. It indicates the maximum length of the event list that matches the condition.

retention

The retention function can use a group of conditions as parameters to analyze whether an event meets the conditions.

Syntax

1
retention(cond1, cond2, ..., cond32);

Input parameters

cond: variable-length Boolean array with a maximum length of 32 characters, indicating whether an event meets specific conditions. GaussDB(DWS) supports only 1 to 32 conditions. If the number of conditions is not within the range, an error is reported.

Return values

retention condition: tinyint array type. It indicates the expression of the returned result, which is the same as the length of the input parameter cond. If the cond1 and condi conditions are met, the ith value of the returned result is 1. Otherwise, the ith value is 0.

range_retention_count

Description: Records the retention of each user. This function returns an array, which can be used as the input parameter of the range_retention_sum function.

Syntax

1
range_retention_count(is_first, is_active, dt, retention_interval, retention_granularity, output_format)

Input parameters

  • is_first: indicates whether it is an initial behavior. The value is of the Boolean type. The value true indicates that it is an initial behavior, and the value false indicates that it is not an initial behavior.
  • is_active: indicates whether it is a retention behavior. The value is of the Boolean type. The value true indicates that it is a retention behavior, and the value false indicates that it is not a retention behavior.
  • dt: indicates the date when the behavior happens. The value is of the date type.
  • retention_interval: indicates the storage interval. The value is of the array type. A maximum of 15 storage intervals are supported. For example, ARRAY[1,3,5,7,15,30].
  • retention_granularity: indicates the retention granularity, which can be day, week, or month. The value is of the text type.
  • output_format: indicates the output format. The value is of the text type and can be normal (default) or expand (daily retention details can be obtained).

Return value: BIGINT array of user retention information.

range_retention_sum

Description: Summarizes and calculates the daily (weekly/monthly) retention rate of all users.

Syntax

1
range_retention_sum(range_retention_count_result)

Input parameter: return value of the range_retention_count function.

Return value: text array of user retention statistics.