1.1 - 8.10 - nPath Patterns - Teradata Vantage

Teradata Vantage™ - Machine Learning Engine Analytic Function Reference

Product
Teradata Vantage
Release Number
1.1
8.10
Release Date
October 2019
Content Type
Programming Reference
Publication ID
B700-4003-079K
Language
English (United States)

The value of the Pattern syntax element specifies the sequence of rows for which the function searches. You compose the pattern definition, pattern, with symbols (which you define in the Symbols syntax element), operators, and parentheses. In the pattern definition, symbols represent rows. You can combine symbols with pattern operators to define simple or complex patterns of rows for which to search.

Basic Pattern Operators

The following table lists and describes the basic pattern operators, in decreasing order of precedence. In the table, A and B are symbols that have been defined in the Symbols syntax element.

Operator Description Precedence
A Matches one row that meets the definition of A. 1 (highest)
A. Matches one row that meets the definition of A. 1
A? Matches 0 or 1 rows that satisfy the definition of A. 1
A* Matches 0 or more rows that satisfy the definition of A (greedy operator). 1
A+ Matches 1 of more rows that satisfy the definition of A (greedy operator). 1
A.B Matches two rows, where the first row meets the definition of A and the second row meets the definition of B. 2
A|B Matches one row that meets the definition of either A or B. 3

The nPath function uses greedy pattern matching. That is, it finds the longest available match when matching patterns specified by nongreedy operators. For more information, see nPath Greedy Pattern Matching.

Pattern Operator Precedence

Example Equivalent
A.B+ A.(B+)
A|B* A|(B*)
A.B|C (A.B)|C

Example:

A.(B|C)+.D?.X*.A

The preceding pattern definition matches any set of rows whose first row meets the definition of symbol A, followed by a non-empty sequence of rows, each of which meets the definition of either symbol B or C, optionally followed by one row that meets the definition of symbol D, followed by any number of rows that meet the definition of symbol X, and ending with a row that meets the definition of symbol A.

You can use parentheses to define precedence rules. Parentheses are recommended for clarity, even where not strictly required.

Start Anchor and End Anchor Pattern Operators

To indicate that a sequence of rows must start or end with a row that matches a certain symbol, use the start anchor (^) or end anchor ($) operator.

Operator Description
^A Appears only at beginning of pattern. Indicates that set of rows must start with row that meets definition of A.
A$ Appears only at end of pattern. Indicates that set of rows must end with row that meets definition of A.

Subpattern Operators

Subpattern operators let you specify how often a subpattern must appear in a match. You can specify a minimum number, exact number, or range. In the following table, X represents any pattern definition composed of symbols and any of the previously described pattern operators.

Operator Description
(X){a} Matches exactly a occurrences of pattern X.
(X){a,} Matches at least a occurrences of pattern X.
(X){a,b} Matches at least a and no more than b occurrences of pattern X.