Expression Language

Contents

Overview

The Data Pipeline Expression Language (DPEL) is similar to that found in the Java language. It contains a few additions that make it easier to read for developers and non-developers alike.

The DPEL engine is used by several endpoints to parse and evaluate expressions at runtime. This allows expressions to be treated as configuration instead of being baked into the application. DPEL expressions can be used to set calculated fields, filter records, and generate XML (XmlElement's when(), element(), and attribute() methods all accept dynamic expressions).

The DPEL engine can also be used apart from Data Pipeline as long as you don't mind working with internal classes that may change in the future (see com.northconcepts.datapipeline.internal.parser.Parser.parseExpression(String)).

 

Literals

Type Description Example
String Single or double quoted Java String "abcd"
'abcd'
Integer Java long 123
Decimal Java double 123.0
Date / Time date 'yyyy-MM-dd'
time 'HH:mm'
timestamp 'yyyy-MM-dd HH:mm'
date '2010-04-22'
time '01:54'
timestamp '2010-04-22 01:54'
Interval

A measure of time.


<integer> millisecond(s) | second(s) | minute(s) | hour(s) | day(s) | week(s) | month(s) | year(s)

1 millisecond
2 milliseconds
base + 2 weeks
date '2010-04-22' + 5 days
date '2010-04-22' - start > 2 months
Boolean Java boolean: true, false, yes, or no completed == false
started == yes
Null Java null null

Variables

Type Description Example
Simple Case-sensitive identifier, beginning with a letter or underscore followed by zero or more letters, numbers, underscores, and periods. invoiceDate
invoice_date
Explicit A simple variable or variable containing spaces surrounded by ${ and }. ${invoiceDate}
${Invoice Date}
Positional A variable defined by position or context. Currently unused. ?

Arithmetic Operators

Type Description Example
Unary Plus   +a
Unary Minus   -a
-(a + b)
Exponent base ** exponent a ** b
2 ** 4
Multiplication   33 * 2
Divide   100 / 5
Remainder   78 % 5
78 mod 5
Addition Numeric addition or string concatenation 4 + 3
"abc" + 'def'
Subtraction   25.7 - 95.42

Relational Operators

Type Description Example
Equals = or == 1 = 1
1 == 1
true == yes
Not Equals != or <> a != b
a <> b
Greater > a > b
Greater or Equal >= a >= b
Less < a < b
Less or Equal <= a <= b

Logical Operators

Type Description Example
And and or && a && b
a and b
Or or or || a || b
a or b
Xor xor or ^ a ^ b
a xor b
Not not or ! !(a > 7)
not (a > 7)

Method Calls

The expression language supports calls to user-defined, static Java methods. Methods can be called either using their fully-qualified Java name or by an alias. See the add my own function example for a demo that registers and calls a function alias.




Examples

The following examples all use the built-in expression language.




Built-in Functions

arrayToString(Object[] array, String separator)
Convert an array of Objects to a String separated by the separator.
Parameters:
array - Object array
separator - the separator for the Objects
Returns:
java.lang.String
arrayToString(int[] array, String separator)
Convert an int array to a String separated by the separator.
Parameters:
array - int array
separator - the separator for the ints
Returns:
java.lang.String
arrayToString(long[] array, String separator)
Convert a long array to a String separated by the separator.
Parameters:
array - long array
separator - the separator for the longs
Returns:
java.lang.String
arrayToString(double[] array, String separator)
Convert a double array to a String separated by the separator.
Parameters:
array - double array
separator - the separator for the doubles
Returns:
java.lang.String
arrayToString(List array, String separator)
Convert a List<?> to a String separated by the separator.
Parameters:
array - a List<?>
separator - the separator for the List<?>
Returns:
java.lang.String
bytesToHex(byte[] bytes)
Converts an array of bytes to a hexadecimal string.
Parameters:
bytes - the array of bytes to convert
Returns:
java.lang.String
coalesce(Object ... expression)
Returns the first non-null expression or null if all expressions are null.
Parameters:
expression - an array of Objects
Returns:
java.lang.Object
columnNameToInt(String columnName)
Converts a string column name to an int. (e.g., column A = 0, column CW = 100, column AB = 27)
Parameters:
columnName - the string to convert
Returns:
int
compare(Object o1, Object o2)
Compares two Objects. Returns 0 if both objects are equal, -1 if the first object is null, 1 if the second object in null.
Parameters:
o1 - the first Object
o2 - the second Object
Returns:
int
compare(String s1, String s2, boolean caseSensitive)
Compares two string if they are equal. If caseSensitive is true, it matches the exact case. A value of 0 is returned if the strings are equal, -1 if the first string is null, 1 if the second string is null.
Parameters:
s1 - the first string to compare to
s2 - the second string to compare to
caseSensitive - set to false to ignore case
Returns:
int
contains(String string, String substring)
Returns true if the string contains the substring. It will match the exact case.
Parameters:
string - the string to be searched
substring - the string to search for
Returns:
boolean
contains(String string, String substring, boolean caseSensitive)
Returns true if the string contains the substring. If caseSensitive is true, it will match the exact case.
Parameters:
string - the string to be searched
substring - the string to search for
caseSensitive - set to true to match exact case
Returns:
boolean
contains(String[] elements, String element, boolean caseSensitive)
Returns true if the string element is contained in the array of string elements. If caseSensitive is true, it will match the exact case.
Parameters:
elements - array of strings to be searched
element - the string to search for
caseSensitive - set to true to match exact case
Returns:
boolean
decode(Object expression, Object search1, Object result1, Object ... searchResultDefault)
Returns result1 if expression equals search1. Otherwise expression is matched against searchResultDefault and the result is the next Object in the array (i.e., the array are search pairs of search and result objects).
Parameters:
expression - the Object to search for
search1 - the first Object to be matched with expression
result1 - returned when expression equals search1
searchResultDefault - an array of search pairs (search and result)
Returns:
java.lang.Object
emptyToNull(String s)
Returns null if the string is empty. Otherwise, the same string is returned.
Parameters:
s - a string
Returns:
java.lang.String
endsWith(String string, String substring, boolean caseSensitive)
Returns true if the string ends with the substring. If caseSensitive is true, it will match the exact case.
Parameters:
string - the string to be searched
substring - the string to search for
caseSensitive - set to true to match exact case
Returns:
boolean
endsWith(CharSequence string, CharSequence substring)
Returns true if the string ends with the substring.
Parameters:
string - the CharSequence to be searched
substring - the CharSequence to search for
Returns:
boolean
equals(Object expression1, Object expression2)
Returns true if both Objects are equal.
Parameters:
expression1 - the first Object to compare
expression2 - the second Object to compare
Returns:
boolean
formatDate(Date date, String pattern)
Converts a java.util.Date to a string using the specified format pattern.
Parameters:
date - the date to be formatted as a string.
pattern - the pattern describing the date and time format.
Returns:
java.lang.String
formatDouble(Double number, String pattern)
Converts a Double to a string using the specified format pattern.
Parameters:
number - the value to format
pattern - the pattern describing the number format.
Returns:
java.lang.String
formatLong(Long number, String pattern)
Converts a Long to a string using the specified format pattern.
Parameters:
number - the value to format
pattern - the pattern describing the number format.
Returns:
java.lang.String
getCharacterCount(String string, char searchChar)
Returns the number of searchChars contained in string or zero (0).
Parameters:
string - the string to be searched
searchChar - the character to search for
Returns:
int
getRandomString(int length)
Returns a random string with the specified length.
Parameters:
length - the resulting length of the string
Returns:
java.lang.String
iif(boolean booleanExpression, Object trueResult, Object falseResult)
Returns trueResult if booleanExpression is true, otherwise returns falseResult.
Parameters:
booleanExpression - the boolean expression
trueResult - the Object to return if the boolean expression is true
falseResult - the Object to return if the boolean expression is false
Returns:
java.lang.Object
intToColumnName(int column)
Converts an int to a string column name. Similar to spreadsheet column names. (e.g., column 27 = AB, column 100 = CW, column 0 = A)
Parameters:
column - the number to convert
Returns:
java.lang.String
isEmpty(String s)
Return true if the string is empty, null or all whitespaces.
Parameters:
s - the string to be processed
Returns:
boolean
isNotEmpty(String s)
Return true if the string is not empty or is not null.
Parameters:
s - the string to be processed
Returns:
boolean
isOneOf(int actual, int ... expected)
Returns true if actual equals one of the integers in expected.
Parameters:
actual - the int to compare
expected - the array of int to be compared with
Returns:
boolean
isOneOf(Object actual, Object ... expected)
Returns true if actual equals one of the objects in expected.
Parameters:
actual - the Object to compare
expected - the array of Objects to be compared with
Returns:
java.lang.Object
left(String string, int length)
Returns the substring of string starting from the left until the specified length.
Parameters:
string - the string to be parsed
length - the number of characters to return
Returns:
java.lang.String
length(Object value)
Returns the length of value.
Parameters:
value - the Object to be processed
Returns:
int
matches(String s1, String s2, boolean caseSensitive, boolean allowEmpty)
Returns true if both strings match. If caseSensitive is true, it will match the exact case. If allowEmpty is true, it will allow matching with an empty string.
Parameters:
s1 - the first string to match
s2 - the second string to match
caseSensitive - set to true to match exact case
allowEmpty - set to true to allow empty string matching
Returns:
boolean
matches(String s1, String s2, boolean caseSensitive)
Returns true if both strings match. If caseSensitive is true, it will match the exact case.
Parameters:
s1 - the first string to match
s2 - the second string to match
caseSensitive - set to true to match exact case
Returns:
boolean
matches(String s1, String s2)
Returns true if both strings match.
Parameters:
s1 - the first string to match
s2 - the second string to match
Returns:
boolean
now()
Returns the current date-time.
Returns:
java.util.Date
nullif(Object expression1, Object expression2)
Returns null if the two expressions are equal, otherwise returns expression1.
Parameters:
expression1 - the first Object to compare
expression2 - the second Object to compare
Returns:
java.lang.Object
padLeft(String string, int length, char padChar)
Pads the number of characters specified on the left of the string, length is the resulting size of the string with padding.
Parameters:
string - the string to be padded
length - the resulting size of the string with padding
padChar - the character to add/pad
Returns:
java.lang.String
padRight(String string, int length, char padChar)
Pads the number of characters specified on the right of the string, length is the resulting size of the string with padding.
Parameters:
string - the string to be padded
length - the resulting size of the string with padding
padChar - the character to add/pad
Returns:
java.lang.String
parseBoolean(String s)
Returns a boolean initialized to the value of the specified string.
Parameters:
s - the string to be parsed
Returns:
boolean
parseDate(String value, String pattern)
Converts a string to a java.util.Date using the specified pattern.
Parameters:
value - the string to parse.
pattern - the pattern describing the date and time format.
Returns:
java.util.Date
parseDouble(String s)
Returns a double initialized to the value of the specified string.
Parameters:
s - the string to be parsed
Returns:
double
parseDouble(String number, String pattern)
Converts a string to a double using the specified format pattern.
Parameters:
number - the value to parse.
pattern - the pattern describing the number format.
Returns:
double
parseInt(String s)
Returns an int initialized to the value of the specified string.
Parameters:
s - the string to be parsed
Returns:
int
parseLong(String s)
Returns a long initialized to the value of the specified string.
Parameters:
s - the string to be parsed
Returns:
long
parseLong(String number, String pattern)
Converts a string to a long using the specified format pattern.
Parameters:
number - the value to parse.
pattern - the pattern describing the number format.
Returns:
long
repeat(String string, int count)
Creates a new string out of the string provided, appended count times.
Parameters:
string - the string to append
count - the number of times to append the string
Returns:
java.lang.String
right(String string, int length)
Returns the substring of string starting from the right until the specified length.
Parameters:
string - the string to be parsed
length - the number of characters to return
Returns:
java.lang.String
sha2(Object ... values)
Applies the SHA-2 message digest algorithm to values and returns it as a string.
Parameters:
values - the Object array to be hashed
Returns:
java.lang.String
sha256(Object ... values)
Applies the SHA-256 message digest algorithm to values and returns it as a string.
Parameters:
values - the Object array to be hashed
Returns:
java.lang.String
sha512(Object ... values)
Applies the SHA-512 message digest algorithm to values and returns it as a string.
Parameters:
values - the Object array to be hashed
Returns:
java.lang.String
startsWith(String string, String substring, boolean caseSensitive)
Returns true if the string starts with substring. If caseSensitive is true, it will match the exact case.
Parameters:
string - the string to be searched
substring - the substring to search for
caseSensitive - set to true to match exact case
Returns:
boolean
startsWith(CharSequence string, CharSequence substring)
Returns true if the string starts with substring.
Parameters:
string - the CharSequence to be searched
substring - the CharSequence to search for
Returns:
boolean
startsWith(CharSequence string, CharSequence substring, int offset)
Returns true if the string starts with substring. If offset is set, it will start matching the substring at that point in the string.
Parameters:
string - the CharSequence to be searched
substring - the CharSequence to search for
offset - the starting point of the search
Returns:
boolean
substring(String string, int beginIndex, int endIndex)
Returns the substring of string starting from the beginIndex until one before the endIndex. An empty is returned if either index is greater than the length of the string.
Parameters:
string - the string to be parsed
beginIndex - the starting index
endIndex - one after the ending index
Returns:
java.lang.String
toBigDecimal(Object value)
Converts value to a BigDecimal.
Parameters:
value - the Object to convert
Returns:
java.math.BigDecimal
toBigInteger(Object value)
Converts value to a BigInteger.
Parameters:
value - the Object to convert
Returns:
java.math.BigInteger
toDate(Date value)
Converts value to a java.sql.Date.
Parameters:
value - the Object to convert
Returns:
java.sql.Date
toDatetime(Date value)
Converts value to a java.util.Date.
Parameters:
value - the Object to convert
Returns:
java.util.Date
toDouble(Object value)
Converts value to a Double.
Parameters:
value - the Object to convert
Returns:
java.lang.Double
toInt(Object value)
Converts value to an Integer.
Parameters:
value - the Object to convert
Returns:
java.lang.Integer
toLong(Object value)
Converts value to a Long.
Parameters:
value - the Object to convert
Returns:
java.lang.Long
toLowerCase(Object value)
Converts all the characters in value to lowercase.
Parameters:
value - the Object to be processed
Returns:
java.lang.String
toTime(Date value)
Converts value to a java.sql.Time.
Parameters:
value - the Object to convert
Returns:
java.sql.Time
toUpperCase(Object value)
Converts all the characters in value to uppercase.
Parameters:
value - the Object to be processed
Returns:
java.lang.String
trimLeft(String string)
Removes all leading whitespace.
Parameters:
string - the string to be trimmed
Returns:
java.lang.String
trimLeft(String string, char padChar)
Removes all leading characters specified. If padChar is not specified, whitespace is removed.
Parameters:
string - the string to be trimmed
padChar - the character to trim
Returns:
java.lang.String
trimRight(String string)
Removes all trailing whitespace.
Parameters:
string - the string to be trimmed
Returns:
java.lang.String
trimRight(String string, char padChar)
Removes all trailing characters specified. If padChar is not specified, whitespace is removed.
Parameters:
string - the string to be trimmed
padChar - the character to trim
Returns:
java.lang.String

examples

Mobile Analytics