Expression Notes
Values
All expressions will use values of some kind. These values may be added and used as part of the expression, or may be read from the attribute or attributes that are input to the Expression processor.
Values in expressions may be Strings, Numbers or Arrays of Strings or Numbers. Numbers are stored in IEEE double precision format, with a maximum value of around 1.8 x 10308. Where date values are used in an expression, these values are represented by the equivalent Java timestamp (the number of milliseconds since 00:00 on January 1, 1970).
Expressions
Expressions are made up of Items combined by Operators. The supported Items are as follows:
-
Numbers: Numbers may be represented as simple integers, or more complex numbers may be written using the floating point system, with an optional exponent.
Examples:
1000 2.1212 0.1 1.2321e-20 1e10
-
Null: The special name
null
represents an undefined value. -
String Constants: String constants are enclosed in ' or " quotes. Java style back slash (\) escapes may be used within a string for special characters, as follows:
-
\n
or\nn
or\nnn
: Character with octal code N -
\n
: Line feed (code 10) -
\r
: Carriage return (code 13) -
\a
: Bell character (code 7) -
\t
: Tab (code 9) -
\b
: Backspace (code 8) -
\f
: Formfeed (code 12) -
\v
: Vertical tab (code 11)
Examples:
"the cat slept on the mat" "this is a line feed: \n" 'this is also a string'
-
-
Attribute Names: A name used in an expression must contain letters, digits, $, _ or . and must not start with a digit. If it is necessary to use a name which contains other characters, it may be entered in an expression using the special syntax
@'name
'
or@"name"
. For example if the name contains spaces, it must be entered as:@"a name with spaces"
-
Array Values: An array value may be entered as a list of values enclosed in curly brackets:
{ }
.Examples:
{1, 2, 3} {a+2, b-5}
-
Array Selections: An array element may be selected using an index expression in square brackets:
[ ]
. The first element is index 1. A subarray may be selected using an array slice, where a slice is indicated by a colon:[lwb:upb]
.Examples:
arr[1] arr[x+1] z[2:3+m] {1,2,3}[2]
The following Operators are available, in descending order of priority:
Operator | Priority | Meaning |
---|---|---|
^ |
8 |
Power of (for example, ^ 0.5 evaluates a square root) |
* |
7 |
Multiply |
/ |
7 |
Divide |
% |
7 |
Modulus |
+ |
6 |
Add |
- |
6 |
Subtract |
|| |
6 |
String concatenation |
> |
5 |
Greater than |
< |
5 |
Less than |
>= |
5 |
Greater than or equal to |
<= |
5 |
Less than or equal to |
= or == |
4 |
Is equal to |
!= or <> |
4 |
Is not equal to |
& |
3 |
Logical AND |
| |
2 |
Logical OR |
! |
1 |
Monadic logical NOT |
Comparison operators evaluate to 1 if the comparison succeeds, and 0 if it does not.
Operators with higher priority bind more 'tightly' than operators with lower priority. For example:
a = b + c * d ^ e
is equivalent to:
a = (b + (c * (d ^ e)))
Functions
The following functions are supported in the expression language:
Function | Argument(s) | Result | Meaning |
---|---|---|---|
floor (x) |
Number |
Number |
Round down |
ceil (x) |
Number |
Number |
Round up |
round (x) |
Number |
Number |
Round to nearest |
abs (x) |
Number |
Number |
Absolute value |
length (x) |
String or Array |
Number |
Length of string (in characters) or array (in elements) |
isset (x) |
Any |
Number |
1 if arguments are equal, 0 if not equal. Nulls compare as equals. |
equals (a,b) |
Scalar |
Number |
1 if arguments are equal, 0 if not equal. Nulls compare as equals. |
substr (string, start) or substr (string, start, length) |
String, Number, Number |
String |
Substring - negative start value counts from end |
trimleft (string, start) or trimleft (string, start, length) |
String, Number, Number |
String |
Substring from left |
trimright (string, start) or trimright (string, start, length) |
String, Number, Number |
String |
Substring from right |
chartonumber (string) |
String |
Number |
Convert first character of string to its numeric code. Result is null if the string is empty. |
indexof (string, sub) or indexof (string, sub, start) |
String, Number, Number |
Number |
Find first index of substring in string, starting at start; result is 0 if not found |
upper (string) |
String |
String |
Upper case |
lower (string) |
String |
String |
Lower case |
stringify (x) |
String or Number |
String |
Convert number or string to string for storage |
digest (x) |
String or Number |
String |
Generate a 'digest' from the argument |
format (num) or formatdate (num, format) |
Number, String |
String |
Format a number using the default or supplied number format (see java.text.DecimalFormat) |
parsedate (string) or parsedate (string, format) |
String, String |
Number |
Parse a date using the default or supplier date format; result is null is parsing failed |
soundex (string) |
String |
String |
Soundex |
refinedsoundex (string) |
String |
String |
Refined soundex |
metaphone (string) |
String |
String |
Basic metaphone |
doublemetaphone (string) or doublemetaphone (string, length) |
String, Number |
String |
Metaphone with optional length (default 12) |
regexsplit (string, regex) or regexsplit (string, regex, limit) |
String, String, Number |
String Array |
Split into array by using regex - see java.lang.String.split. |
regexreplace (string, regex, replace) |
String, String, String |
String |
Replace all occurrences of a regex in a string with a replacement |
trim (string) |
String |
String |
Remove space characters from start and end of a string |
mult (number, number, ...) |
Numbers |
Number |
Product of all the arguments |
sum (number, number, ...) |
Numbers |
Number |
Sum of all the arguments - any nulls will make the result null |
zsum (number, number, ...) |
Numbers |
Number |
Sum of all the arguments, treating nulls as zero |
concat (string, string, ...) |
Strings |
String |
Concatenate all the arguments |
concat2 (delimiter, string, string, ...) |
Strings |
String |
Concatenate all the arguments, using the first as the delimiter |
concat3 (delimiter, noblanks, string, string, ...) |
String, Number, Strings |
Strings |
Concatenate all the arguments, using the first as the delimiter. If the second argument is non-zero, ignore blank strings. |
array (value, value, ...) |
Any |
Array |
Makes an array from the arguments |
trim2 (string, code) |
String, String |
String |
Trim spaces from left (code = 'l'), right (code = 'r'), both (code = 'b') or everywhere (code = 'a') |
nodatacheck (string) |
String |
String |
No data classification - returns '-' if string is populated, or no data code ('a' - 'f'), as follows: a = null b = empty string c = control characters d = single space e = multiple spaces f = other whitespace |
Expression Contexts
Expressions are used in a number of different contexts within EDQ. Each context has a different set of names available. A select few of the contexts are listed here.
-
The Expression and Expression Filter processors: Each name used in the expression must match an attribute selected as an input for the processor. Matching is case sensitive; if an attribute name includes a suffix (that is, part of the attribute name after a full stop), the suffix is ignored.
If an attribute name is not a valid expression name, for example because it contains spaces, it must be entered using the
@"name"
syntax. For example if the attribute is address line 1 (street), it must be entered as:@"address line 1 (street)"
-
Calculator Processors: A number of standard processors are implemented using the
com.datanomic.director.runtime.widgets.common.Calculator
class. This takes an expression from a processor parameter (from the XML) and evaluates it using the input attributes.An expression parameter must be defined for each of the outputs in the processor. The parameter name for the output with ID
N
isexpr.N
. If there is a single output only, the simpler nameexpr
may be used instead.Within an expression, an input attribute is referred to as
iN where N
is the input ID from the XML. If the input may be associated with multiple attributes then the name may be used in 'aggregating' contexts only.The outputs are evaluated in ID order and an earlier output may be referred to as
oN where N
is the output ID from the XML.In addition, 'working' expressions may be defined to store values which may be used in more than one place in the output expressions. These working expressions are evaluated before any of the output expressions. The parameter names for working expressions are
expr.t1
,expr.t2
, etc.Processor options may also be used in calculator expressions - just use the name of the option.
Examples:
-
The expression for the Upper Case processor is defined with:
<parameters> <parameter name="expr">upper(i1)</parameter> </parameters>
-
The expression for the Concatenate processor is defined with:
<parameters> <parameter name="expr">concat2(separator, i1)</parameter> </parameters>
Note the use of the
separator
property. -
The expression for the Trim Characters processor is defined with:
<parameters> <parameter name="expr.o1">side == 'l' ? trimleft(i1, start, length) : trimright(i1, start, length)</parameter> </parameters>
-
The expression for the Select Array Element processor is defined with:
<parameters> <parameter name="expr.t1">fromend ? (length(i1) - index) + 1 : index</parameter> <parameter name="expr.o1">i1[t1]</parameter> </parameters>
-
The expressions for the Regex Replace processor are defined with:
<parameters> <parameter name="expr.o1">regexreplace(i1, regex, replace)</parameter> <parameter name="expr.o2">o1 != i1 ? 'Y' : 'N'</parameter> </parameters>
In this case, the first expression does the replacement and the second computes the 'success' flag.
Advanced Features
-
Conditional Expressions: Conditional expressions may be specified using the following syntax:
a ? b : c
The result is 'b' if 'a' is true and 'c' otherwise.
-
Iterator Expressions: An iterator expression is a special feature for use in 'aggregating' functions like Sum or Concatenate. The syntax is as follows:
{a : expr}
Here
a
is an array or multi-attribute name (an input attribute which may have any number of actual attributes assigned to it), andexpr
is an expression which will containa
. The expression is evaluated with a replaced by each successive value in the name, and the results are fed to the aggregating function.The best way to illustrate this is with examples:
Example 1
sum({ a : a ^ 2 })
This sums the squares of all the elements in a.
Example 2
sum( { a : a < 0 ? 1 : 0 })
This counts all the elements of a which are negative.
Example 3
sum({ i1 : nodatacheck(i1) = '-'}) > 0 ? 'Y' : 'N'
Count the elements of i1 (input attribute 1) which are populated and evaluate to Y if any have data and N if all have 'No Data'.