CONDITIONAL_TRUE_EVENT
functionsupportedCore SQL functionsReturns a window event number for each row within a window partition based on the result of the boolean argument expr1. The number starts from 0 and is incremented by 1 for each row on which the expr1 evaluates to true. One use of this function is to sessionize window partitions. For example, in click stream data, it can be used to determine whether a user has started a new session by checking whether the last event was longer ago than a threshold.
Syntax
supportedpartialnot supportednot scored
CONDITIONAL_TRUE_EVENT( <expr1> ) OVER ( [ PARTITION BY <expr2> ] ORDER BY <expr3> [ { ASC | DESC } ] [ NULLS { FIRST | LAST } ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | This is a boolean expression that changes the window event number value when it evaluates true. |
expr2 | required | This is the optional expression to partition by. |
expr3 | required | This is the expression to order by within each partition. |
Usage notes
- The conditional expression expr1 can contain the rank-related functions LAG and LEAD, which allow us to build more expressive windows. If used, these functions have to use the same OVER specification as the CONDITIONAL_TRUE_EVENT.