Arithmetic and logical binary operators in concatenation comparison
ObjectScript returns a value of TRUE if the first unique character in the left operand has a higher ASCII value than the corresponding character in the right operand that is, if the character in the left operand comes after the character in the right operand in ASCII collating sequence.
If the right operand is shorter than the left operand, but otherwise identical, ObjectScript also returns a value of TRUE.
The first unique character in the left operand has a lower ASCII value than the corresponding character in the right operand.
The left operand is identical to the right operand. The left operand is shorter than the right operand, but otherwise identical. The result is TRUE.
The following example tests whether the string in B follows the string in A. You can produce a Not Follows operation by using the Unary Not operator with Binary Follows in either of the following equivalent formats:. Binary Sorts after tests whether the left operand sorts after the right operand in numeric subscript collation sequence. In numeric collation sequence, the null string collates first, followed by canonical numbers in numeric order with negative numbers first, zero next, and positive numbers, followed lastly by nonnumeric values.
WRITE ]] 2. ObjectScript pattern matching, described here, a syntax that demarcates the beginning of a pattern string with a question mark? Regular Expressions , a pattern match syntax supported with variants by many software vendors. They are described in a separate chapter of this manual. These pattern match systems are wholly separate. Each pattern match system can only be used in its own context. It is, however, possible to combine pattern match tests from different pattern match systems using logical AND and OR syntax, as shown in the following example:.
The ObjectScript pattern tests that the string must contain two consecutive uppercase letters. The Regular Expression pattern tests that the string must contain between 3 and 7 characters. The ObjectScript pattern match operator tests whether the characters in its left operand are correctly specified by the pattern in its right operand.
It returns a boolean value. The pattern match operator produces a result of TRUE 1 when the pattern correctly specifies the pattern of characters in the left operand. It produces a result of FALSE 0 if the pattern does not correctly specify the pattern of characters in the left operand. For example, the following tests if the string ssn contains a valid U.
Social Security Number 3 digits, a hyphen, 2 digits, a hyphen, and 4 digits:. The left operand the test value and the right operand the pattern are distinguished by the leading? The two operands may be separated by one or more blank spaces, or not separated by blank spaces, as shown in the following equivalent program example:.
No white space is permitted following the? White space within the pattern must be within a quoted string and is interpreted as being part of the pattern. The general format for a pattern match operation is as follows:.
The pattern sequence can be one of the following: A pattern-element consists of one of the following:. The repeat-count can evaluate to an integer or to the period wildcard character. Use the period to specify any number of instances. If more than one code is specified, the pattern is satisfied by matching any one of the codes. This provides logical OR capability in pattern specifications.
Use a literal string enclosed in double quotes in a pattern if you want to match a specific character or characters. In other situations, use the special pattern codes provided by ObjectScript. Characters associated with a particular pattern code are to some extent locale-dependent. The following table shows the available pattern codes and their meanings:.
Code Meaning A Matches any uppercase or lowercase alphabetic character. The 8-bit character set for the locale defines what is an alphabetic character. For the English locale based on the Latin-1 character set , this includes the ASCII values 65 through 90 A through Z , 97 through a through z , , , , through , through , and through E Matches any character, including non-printing characters, whitespace characters, and control characters.
L Matches any lowercase alphabetic character. The 8-bit character set for the locale defines what is a lowercase character. For the English locale based on the Latin-1 character set this includes the ASCII values 97 through a through z , , , , through , and through P Matches any punctuation character.
The character set for the locale defines what is a punctuation character for an extended 8-bit ASCII character set. For the English locale based on the Latin-1 character set , this includes the ASCII values 32 through 47, 58 through 64, 91 through 96, through , through , through , , through , , , , and U Matches any uppercase alphabetic character. The 8-bit character set for the locale defines what is an uppercase character.
Pattern codes are not case-sensitive; you can specify them in either uppercase or lowercase. You can specify multiple pattern codes to match a specific character or string.
Directional double-quote characters curly quotes do not match as punctuation characters. The Pattern Match operator differs from the Binary Contains [ operator. The Binary Contains operator returns TRUE 1 even if only a substring of the left-hand operand matches the right-hand operand. Also, Binary Contains expressions do not provide the range of options available with the Pattern Match operator.
In Binary Contains expressions, you can use only a single string as the right-hand operand, without any special codes. Consider the following Pattern Match expression:. Here are some examples of basic pattern matching:. You can extend the scope of a pattern code by specifying:. How many times a pattern can occur. To define a range for the number of times that pattern can occur in the target operand, use the form:.
The first n defines the lower limit for the range of occurrences; the second n defines the upper limit. As another example, consider the following expression:.
This expression checks to see whether var4 contains from one to six alphabetic characters. A result of FALSE 0 is returned if var4 contains zero or more than six alphabetic characters, or contains a non-alphabetic character. If you omit either n , ObjectScript supplies a default.
The default for the first n is zero 0. The default for the second n is any number. Consider the following example:. To define multiple patterns, you can combine n and pattern in a sequence of any length.
To detect both one and two digit months, you could modify the expression as:. Now the first pattern match 1. It uses the optional period. To define a combination pattern, use the form:. With a combination pattern, the sequence consisting of pattern1 followed by pattern2 is checked against the target operand. For example, consider the following expression:.
This expression checks for a pattern in which three numeric digits are followed by zero to four lowercase alphabetic characters. The expression returns TRUE 1 only if the target operand contains exactly one occurrence of the combined pattern. To define an indefinite pattern, use the form:. With an indefinite pattern, the target operand is checked for an occurrence of pattern , but any number of occurrences is accepted including zero occurrences.
For example, consider the expression:. This expression returns TRUE 1 if the target operand contains zero, one, or more than one numeric character, and contains no characters of any other type. Alternation allows for testing if an operand matches one or more of a group of specified pattern sequences. It provides logical OR capability to pattern matching. An alternation has the following syntax:. You can have nested alternation patterns, as in the following pattern match expression:.
For example, you may want to validate a U. At a minimum, the phone number must be a 7-digit phone number with a hyphen - separating the third and fourth digits. The phone number can also include a three-digit area code that must either have surrounding parentheses or be separated from the rest of the number by a hyphen.
The following pattern match expressions describe three valid forms of a U. Without an alternation, the following compound Boolean expression would be required to validate any form of U. With an alternation, the following single pattern can validate any form of U. The alternation in this example allows the area code component of the phone number to be satisfied by either 1" "3N1" " or 3N1"-".
The alternation count range of 0 to 1 indicates that the operand phone can have 0 or 1 area code components. Alternations with a repeat count greater than one 1 can produce many combinations of acceptable patterns. The following alternation matches the string shown and matches 26 other three-character strings.
If a pattern match successfully describes only part of a string, then the pattern match returns a result of FALSE 0. That is, there cannot be any string left over when the pattern is exhausted. There can be more than one interpretation of a pattern as it is matched against an operand.
For example, the following expression can be interpreted in two ways:. Not Match reverses the truth value of the Pattern Match. The following example uses the Not Match operator:. A pattern match with multiple alternations and indefinite patterns, when applied to a long string, can recurse many levels into the system stack. In rare cases, this recursion can rise to several thousand levels, threatening stack overflow and a process crash.
In the unusual event that such an error occurs, it is recommended that you either simplify your pattern, or apply it to shorter subunits of the original string. The ObjectScript indirection operator allows you to assign values indirectly to variables. Indirection is a technique that provides dynamic runtime substitution of part or all of a command line, a command, or a command argument by the contents of a data field.
Although indirection can promote more economical and more generalized coding than would be otherwise available, it is never essential. You should use indirection only in those cases where it offers a clear advantage. Also, if you use complicated indirections, be sure to document your code clearly. Indirections can sometimes be difficult to decipher. Indirection is specified by the indirection operator and, except for subscript indirection, takes the form:. All variables referenced in the substitution value are public variables, even when used in a procedure.
The variable can be an array node. The following routine illustrates that indirection looks at the entire variable value to its right. Which type of indirection is performed depends on the context in which the variable occurs. Each type of indirection is described separately below. Indirection cannot be used with dot syntax. This is because dot syntax is parsed at compile time, not at runtime. In name indirection, the indirection evaluates to a variable name, a line label, or a routine name.
Name indirection can only access public variables. For further details, refer to the User-defined Code chapter of this manual. When you use indirection to reference a named variable, the value of the indirection must be a complete global or local variable name, including any necessary subscripts. If a call attempts to use indirection to get or set the value of object properties, it may result in an error.
When you use indirection to reference a line label, the value of the indirection must be a syntactically valid line label. The value of the line label FIG if the value of N is 1. The value of the line label GO if the value of N is 2. The value of STOP in all other cases. When you use indirection to reference a routine name, the value of the indirection must be a syntactically valid routine name. In the following example, name indirection is used on the DO command to supply the appropriate procedure name.
At execution time, the contents of variable loc are substituted for the expected name:. Name indirection can substitute only a name value. The second SET command in the following example returns an error message because of the context. You can recast the example to execute correctly as follows:.
Pattern indirection is a special form of indirection. The indirection operator replaces a pattern match. The value of the indirection must be a valid pattern. Pattern matching is described under "Pattern Matching". Pattern indirection is especially useful when you want to select several possible patterns and then use them as a single pattern. In the following example, indirection is used with pattern matching to check for a valid U. Such codes can take either a five-digit nnnnn or a nine-digit nnnnnnnnn form.
The equivalent 'between' keyword also defines a closed range. Half-open ranges that contain the low endpoint but not the high endpoint [low: Half-closed ranges that contain the high endpoint but not the low endpoint low: The following statement two statements are equivalent: Both statements select orders where the price is in the range of zero and endpoints inclusive:.
The next statement selects order events where the price is greater then and less-or-equal to The following statement selects an inverted range by selecting all order events where the price is less then zero or the price is greater or equal to In case the value of low endpoint is less then the value of high endpoint the in operator reverses the range.
The between keyword specifies a range to test. The not keyword specifies that the result of the predicate be negated. The result of a between expression is of type Boolean. The next example shows how the between keyword can be used to select events with a price between 55 and 60 endpoints inclusive. While the between keyword always includes the endpoints of the range, the in operator allows finer control of endpoint inclusion. The like keyword provides standard SQL pattern matching.
In Esper, SQL patterns are case-sensitive by default. The syntax of like is:. The result of a like expression is of type Boolean. The escape character can be defined as follows. The regexp keyword is a form of pattern matching based on regular expressions implemented through the Java java.
The syntax of regexp is:. The result of a regexp expression is of type Boolean. The rexexp function matches the entire region against the pattern via java. The any operator is true if the expression returns true for one or more of the values returned by a list of expressions including array, Collection and Map values. The left-hand expression is evaluated and compared to each expression result using the given operator, which must yield a Boolean result.
The result of any is "true" if any true result is obtained. The result is "false" if no true result is found including the special case where the expressions are collections that return no rows. The operator can be any of the following values: The some keyword is a synonym for any.
Thus event properties that are lists, sets or maps may provide values to compare against. All expressions must be of the same type or a compatible type.
The any keyword coerces number values to compatible types. If expression returns an array, the operation compares each element of the array. If expression returns a Collection , the operation determines if the collection contains the value returned by the left-hand expression, applying contains semantics. If expression returns a Map , the operation determines if the map contains the key value returned by the left-hand expression, applying containsKey semantics.
The above query selects ProductOrder event that have a category field and a category array, and returns only those events in which the category value is not in the array. The all operator is true if the expression returns true for all of the values returned by a list of expressions including array, Collection and Map values. The result of all is "true" if all rows yield true including the special case where the expressions are collections that returns no rows.
The result is "false" if any false result is found. The result is null if the comparison does not return false for any row, and it returns null for at least one row.
The not in construct is equivalent to! The all keyword coerces number values to compatible types. The above query selects ProductOrder event that have a category field and a category array, and returns only those events in which the category value matches all values in the array.
The new data structure operator populates a new data structure by evaluating column names and assignment expressions. This is useful when an expression should return multiple results, for performing a transformation or inside enumeration method lambda expressions.
If an assignment expression is provided for a column, the operator evaluates the expression and assigns the result to the column name. If no assignment expression is provided, the column name is assumed to be an event property name and the value is the event property value. The above query returns a single property priceInfo for each arriving ProductOrder event.
The property value is itself a map that contains two entries: For the key name category the value of the category property and for the key name price the value of the price property multiplied by two. The next EPL is an example of the new operator within an expression definition and a case -statement one EPL statement not multiple:.
The following example illustrates this. Because the compiler evaluates the operations for n1 from left to right, the evaluation is the same when that order is explicitly indicated for n2. Both n1 and n2 have a result of three. You can use parentheses to force some parts of an expression to be evaluated before others. This can override both the order of precedence and the left associativity. Visual Basic always performs operations that are enclosed in parentheses before those outside.
However, within parentheses, it maintains ordinary precedence and associativity, unless you use parentheses within the parentheses. The feedback system for this content will be changing soon.