Sessions UDF — UDF Signature and Output Format
This UDF takes a collection of rows, each containing several columns, as input.
It first groups the rows based on shared values in specified columns, as defined by the groupSessionPattern.
Rows with matching values in the designated columns are placed in the same group.
Within each group, the function identifies sessions, where each session consists of a sequence of consecutive rows.
Rows are classified as session starters, session enders, or session members based on their match with startSessionPattern and endSessionPattern, provided by the user.
Thus, groups help organize and segment the input rows into cohesive sessions, each representing a collection of related events with boundaries set by user-defined criteria.
In instances where a single row satisfies both the startSessionPattern and endSessionPattern, that row is recognized as the beginning of a new session while simultaneously concluding the previous session.
Consequently, this new session is retained regardless of the value of isIgnoreIfNoEnd.
Additional options allow you to specify whether the generated session ID should be hashed and whether to exclude sessions lacking rows that match the start or end criteria. This provides flexibility in handling incomplete sessions and customizing session identifiers.
The function signature is as follows:
def igrafxSessions(
inputLines: util.List[String],
ignorePattern: String,
groupSessionPattern: String,
startSessionPattern: String,
endSessionPattern: String,
sessionIdPattern: String,
isSessionIdHash: Boolean,
isIgnoreIfNoStart: Boolean,
isIgnoreIfNoEnd: Boolean
): util.List[Struct]
The output format is structured as:
STRUCT<SESSION_ID VARCHAR(STRING), LINE VARCHAR(STRING)>
- SESSION_ID: The unique ID for each session.
- LINE: A line from the initial input collection that belongs to the session.