Show TOC

Background documentationRedwood Expression Language Locate this document in the navigation structure

 

Redwood Expression Language (or REL) is a simple expression language that supports basic arithmetic and comparison operators, and some predefined functions. Different scripting contexts have different predefined functions, the functions on this page are available in all contexts.

The REL can be used to specify:

  • Job definition parameter default values

  • Job definition return code mappings

  • Job chain step preconditions

  • Job chain job preconditions

  • Job chain job parameter mappings

  • Job chain job scheduling parameters

Expressions in REL are designed to be very similar to expressions in RedwoodScript, and the predefined functions are the same.

Operators

Redwood Expression Language provides support for the basic arithmetic operators:

  • + - addition and string concatenation

  • - - subtraction

  • * - multiplication

  • / - division

  • % - integer modulus

It also supports comparison:

  • === - equal to

  • !== - not equal to

  •      - greater than

  •   →=   - greater than or equal

  • < - less than

  • <= - less than or equal

Predefined functions

A number of predefined functions are available, these are grouped into functional areas.

Math
  • Math.abs(x) - take the absolute value of a number. For positive numbers, this is the number, for negative numbers this is the opposite of the number. For example: Math.abs(1) = 1, Math.abs(-10) = 10.

  • Math.floor(x) - take the floor of a number, this is the largest integer less than or equal to x. For example: floor(2.9) = 2, floor(-2) = -2 and floor(-2.3) = -3

  • Math.ceil(x) - take the ceiling of a number, this is the smallest integer not less than x. For example: ceiling(2.3) = 3, ceiling(2) = 2 and ceiling(-2.3) = -2.

  • Math.round(x) - round x to the nearest integer. This uses the 'bankers rounding' algorithm to round numbers .5 exactly, such numbers are rounded to the nearest even number. For example: Math.round(2.2) = 2, Math.round(2.4) = 2, Math.round(3.5) = 4.

Range
  • Range.inRange(candidate, range) - is candidate in the range specified by range''. For example: Range.inRange(2, '1-3') = true, Range.inRange(4, '2-3,6-') is false.

  • Range.inSet(candidate, set) - is candidate in the range specified by set''. For example: Range.inSet(1, ' X X X X ') = true, Range.inSet(6, '_1_3_5_7') = false.

Ranges are made up of components, separated by commas. Each range component can be:

  • x - the number x

  • -x - all numbers from zero to x (including x).

  • x-y - all numbers from x to y (including both x and y)

  • y- - all numbers from y to the maximum value for an integer.

Example ranges:

  • 1-5,7-9

  • -5, 8-

  • 1,2,4,8,16

Sets are made up of elements, starting at zero. If the element at position x is ' ' (space) or '_' (underscore) then that element is NOT in the set. Otherwise that element is in the set.

Example sets:

  • 0 2 4 6 - contains 0, 2, 4, 6

  • X X X X - contains 0, 2, 4, 6

  • _X_X_X_ - contains 1, 3, 5

Example expression:

  • =Range.inRange(1, '0-5') is true

  • =Range.inSet(2, '01_345') is false

Time

Function

Arguments

Description

Time.now()

timeZoneId

The time in the specified time zone; for example (2009/08/23 09:39:33,324 GMT)

Time.now()

The time in the specified time zone; for example (2009/08/23 09:39:33,324 GMT)

Time.isTimeWindowOpen()

dateTimeZone, timeWindowName

Is the specified time window open at the specified time.

Time.isTimeWindowOpenNow()

timeWindowName

Is the specified time window open at the current system time.

Time.expression()

dateTimeZone, expression

Apply expression to dateTimeZone

Time.expressionNow()

expression

Apply expression to Time.now()

Time expressions are a sequence of one or more operations, applied in order to a time (generally now, but may be a specified date).

The following time expressions are available:

  • set <specifier> <value> - set <specifier> to <value>

  • add <value> <specifier> - add <value> to <specifier> (This may propagate)

  • subtract <value> <specifier> - subtract <value> from <specifier> (This may propagate)

  • truncate <specifier> - truncate at <specifier> (This will zero <specifier> and everything below it).

The <value> is always a number:

  • The days of the week start at 1 for Sunday.

  • The days of the year start at 1 for 1 January.

The <specifier> is one of:

  • add/subtract: second, minute, hour, day, week, month, year

  • truncate: second, minute, hour, day, week, month

  • set: second, minute, hour, day, dow, day_of_year, week, week_of_month, month

The day is always the day of the month, and dow is the day of the week.

Example time expressions:

  • add 1 minute

  • add 3 seconds

  • set hour 1

  • truncate day

  • subtract 2 days

Example using the Time functions

In these examples, the current time is 2009/08/23 10:50:44,910 GMT according to output of the =Time.now('GMT') function.

Example 1

=Time.isTimeWindowOpen(Time.now('GMT'), 'System_Week_WorkDays')

This expression returns true if at evaluation-time it is a workday in the GMT timezone. An expression like this might be used as a job chain step (or job) precondition to prevent certain steps from running on weekends.

Example 2

=Time.expression(Time.now('Europe/Paris'), 'add 2 hours add 1 minute add 1 second subtract 2 days')

This expression added 2 hours, 1 minute a second and subtracted 2 days from the current time in the Europe/Paris timezone and returned 2009/08/21 13:51:45,910 Europe/Paris

Example 3

=Time.expression(Time.now('GMT'), 'truncate minute')

This expression returned: 2009/08/23 10:50:00,000 GMT

Example 4

=Time.expression(Time.now('GMT'), 'set minute 13')

This expression returned: 2009/08/23 10:13:44,910 GMT

Example 4

=Time.expression(Time.now('GMT'), 'subtract 1 month')

This expression returned: 2009/07/23 10:13:44,910 GMT

Example using the Time functions as a precondition:

=Time.isTimeWindowOpen(Time.now('GMT'), 'System_Week_WorkDays')

The function returned false, so the job is skipped

Strings

String functions are all applied to a string instance. Strings are treated as arrays of characters, with the first index at 0 and the final index at length-1.

  • aString.concat(s1, [s2[, ...]]) - concatenate s1, s2, ... to aString. This function takes one or more arguments. For example: 'a'.concat('b') = 'ab', 'a'.concat('b', 'c', 'd') = 'abcd'

  • aString.charAt(pos) - return the character at pos in aString. The index pos is zero based. For example: '012345'.charAt(2) = '2'.

  • aString.indexOf(candidate[, startIndex]) - return the first index of candidate in aString. If startIndex is not specified, the search starts at 0, otherwise it starts at startIndex. For example: '012345345'.indexOf('3') = 3

  • aString.lastIndexOf(candidate[, startIndex]) - return the last index of candidate in aString. If startIndex is not specified, the search starts at 0, otherwise it starts at startIndex. '012345345'.lastIndexOf('3') = 6

  • aString.split(separator, limit) - slice aString using separator, returning at most limit entries. For example: '1,2,3,456,7'.split(',', 4) = ['1', '2', '3', '456,7']

  • aString.substring(start[, end]) - return a substring of aString starting at start. If end is not specified the remainder of the string is returned, otherwise it is the last index to return. '01234'.substring(2,4) = '234'

  • aString.toLowerCase() - convert the string to lower case. For example: 'AbC'.toLowerCase() = 'abc'

  • aString.toUpperCase() - convert the string to upper case. For example: 'aBc'.toUpperCase() = 'ABC'

Note Note

Like in Java, the + (plus) character can be used for concatenation of strings. For example 'Hello '+'Universe!'

End of the note.
Casts

Change a data type to another.

  • ToBoolean(x) - convert x to a boolean.

  • ToNumber(x) - convert x to a number.

  • ToInteger(x) - convert x to an integer.

  • ToString(x) - convert x to a string.

Note Note

Expressions always start with an equals sign (=).

End of the note.
Constraints

The following functions are available for validating parameter values.

Constraint.listConstraint(titles, list, bool)

Constraint.pairListConstraint(titles, list, bool)

  • titles is a comma separated list of titles.

  • list is either a normal list or a pair list

  • bool is a boolean expression involving the parameter value

=Constraint.listConstraint('Country', 'de,nl,gt', \

Table.getColumnString('Countries', value, 'Key') !== '')

=Constraint.pairlistConstraint('Country', 'de=49,nl=31,gt=502',\

Table.getColumnString('Countries', value, 'Key') !== '')

Note Note

Both expressions are on one line, please remove the backslash (\) and end of line combinations.

End of the note.
Tables

The following functions are declared within the Table object and allow you to interact with tables, such as the System_Variables table.

  • getColumnString(table, key, column)

  • getRow(table, key)

  • getColumnNumber(table, key, column)

  • formatRow(table, key, rowStart, columnFormat, columnSeparator, rowEnd)

    • columnFormat - accepts strings as well as the following substitution parameters to specify the position of the elements:

      • {0} - column header

      • {1} - value

      • {2} - columnSeparator (should always be the first)

The following examples use the Countries table

Countries Table:

Key

Name

Abbreviation

Translation

Conversion_Rate

31

The Netherlands

NL

Nederland

1.0

33

France

Fr

France

1.0

49

Germany

De

Deutschland

1.0

502

Guatemala

Gt

Guatemala

11.6

Note Note

The Key column is a special built-in column; it is used by the table functions, for example, to look up data in the table and does not need to be specified in the table definition.

End of the note.

getColumnString

=Table.getColumnString('Countries', '31', 'Translation')

Returns:

Nederland

getColumnNumber

=Table.getColumnNumber('Countries', '502', 'Conversion_Rate')

Returns:

11.6

getRow

=Table.getRow('Countries', '33')

Returns:

FrFranceFrance

formatRow

=Table.formatRow('Countries', '49', '#', '{2}{0}={1}', '|', '#')

Returns:

#Abbreviation=De|Conversion_Rate=1.0|Name=Germany|Translation=Deutschland#

=Table.formatRow('Countries', '49', '||', '{2}{1}', '#', '||')

Returns:

||De#1.0#Germany#Deutschland||

=Table.formatRow('Countries', '49', '', '{2}{1}', '\n', '')

Returns:

De

1.0

Germany

Deutschland

The following RedwoodExpressionLanguage function allows you to retrieve values out of the built-in System_Variables table:

  • Variable.getString(key)

It is a shorthand for Table.getColumnString('System_Variables', key, 'SystemValue')

JobChainParameters
  • chainParameters.<paramaeter_name>

  • chainOutParameters.<paramaeter_name>

  • chainJobId

  • JobChainParameters.getOutValueNumber(String jobName, String parameterName)

  • JobChainParameters.getOutValueString(String jobName, String parameterName)

  • JobChainParameters.getOutValueDate(String jobName, String parameterName)

JobChainParameters.getOutValueString("backup, Job 1", "connectString")

Job chain job names take the form Step name, job job number. For example: "Step 2, job 3" or "Data load, job 1".

Get the value of the Date output parameter bckDate of the job named Backup, Job 1 in the current job chain, which is, by default, the first job of the step named Backup.

Availability: Requires 'Module.Scripting' key.

JobChainParameters.getOutValueDate("Backup, Job 1", "bckDate")

Get the value of the Number output parameter BckSize of the job named Backup, Job 1 in the current job chain, which is the first job of the step called Backup.

Availability: Requires 'Module.Scripting' key.

JobChainParameters.getOutValueNumber("Backup, Job 1", "bckSize")

Get the value of the String output parameter connectString of the job named Backup, Job 1 in the current job chain, which is the first job of the step called Backup.

Availability: Requires 'Module.Scripting' key.

JobChainParameters.getOutValueString("backup, Job 1", "connectString")