Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks SQL
Databricks Runtime 19.0 and above
Important
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Azure Databricks previews.
Defines the boolean variables that the PATTERN and MEASURES clauses of MATCH_RECOGNIZE reference and test.
Syntax
DEFINE { rowPatternVar AS booleanExpr } [, ...]
Parameters
rowPatternVar
An identifier that is unique within the
DEFINEclause. If you reuse a name, Azure Databricks raises MATCH_RECOGNIZE_DUPLICATE_PATTERN_VARIABLE.booleanExpr
A boolean expression that does not contain a subquery, aggregate function, or window function, and does not reference a column or column alias other than those from the
table_referencethat precedes theMATCH_RECOGNIZEclause.Column references can use the following functions specific to the
DEFINEclause:A column reference can be qualified by a row pattern variable name (
rowPatternVar.colName). This selects values from rows mapped to that variable in the current match. For example,LAST(down.tstamp)is the timestamp of the last row classified asdown. Unqualified column references refer to the current row in the match without selecting a specific pattern variable.If a row pattern variable is not yet matched, the qualified column reference evaluates to
NULL.When
rowPatternVarnames the pattern variable currently being tested for the row,rowPatternVar.colNamerefers to that row's column value and is equivalent to an unqualifiedcolName. WhenrowPatternVarnames a different pattern variable,rowPatternVar.colNamereads values from rows already mapped to that variable.Nondeterministic functions such as
rand()anduuid()are not allowed inDEFINEpredicates because NFA simulation can evaluate predicates multiple times per row. If you use one, Azure Databricks raises MATCH_RECOGNIZE_NONDETERMINISTIC_DEFINE.General aggregate functions other than
FIRST()andLAST()are not supported inDEFINE. If you use one, Azure Databricks raises MATCH_RECOGNIZE_DEFINE_UNSUPPORTED_AGGREGATE.
Common error conditions
- MATCH_RECOGNIZE_DEFINE_UNSUPPORTED_AGGREGATE
- MATCH_RECOGNIZE_DUPLICATE_PATTERN_VARIABLE
- MATCH_RECOGNIZE_NONDETERMINISTIC_DEFINE