Expression Service Specification
Idea: An Expression is a logical formula to evaluate a value which can be one or many values. Expressions can be used as values in other expressions but always must terminate to a value. A source field can be assigned a value of an expression when defining a mapper for the integration. There are several expressions provided by the mapper tool:
- String Literal: A string literal is composed of one value. The object has the following structure:
value string
- function Evaluation: Returns the value (string)
- Number Literal: A number literal is composed of one value. The object has the following structure:
value number
- function Evaluation: Returns the value (number)
- Bool Literal: A bool literal is composed of one value. The object has the following structure:
value bool
- function Evaluation: Returns the value (bool)
- Variable: A variable expression is composed of a field value. The object has the following structure:
field string
- function Evaluation: Returns the value at the field (any)
- Static: A static expression is composed of a field value and a lookup map. The object has the following structure:
field string
lookupMap {} (dictionary/map)
- function Evaluation: Attempts to find the value which is indexed by the field value of the source object and returns that lookup value on a match. Otherwise, will return the value of the field itself (any)
- Conditional: A conditional expression is composed of a conditional symbol, left expression, and right expression. The object has the following structure:
conditional string
(<, >, ≤, ≥, =, <>)
leftExpr Expression
rightExpr Expression
- function Evaluation: First evaluates the leftExpr to get its value, then evaluates the rightExpr to get its value. If either the left or right expressions are null or the values are null, an error is returned. Otherwise, it applies the conditional for the two values and returns the result value (bool)
- String Conditional: A string conditional expression is composed of a string conditional symbol, left expression, and right expression. The object has the following structure:
stringConditional string
(contains, equals, begins with, ends with)
leftExpr Expression
rightExpr Expression
- function Evaluation: First evaluates the leftExpr to get its value, then evaluates the rightExpr to get its value. If either the left or right expressions are null or the values are null, an error is returned. Otherwise, it applies the string conditional for the two values and returns the result value (bool)
- Operator: A operator expression is composed of a character operator, left expression, right expression. The object has the following structure:
operator string
(+, -, /, *)
leftExpr Expression
rightExpr Expression
- function Evaluation: First evaluates the leftExpr to get its value, then evaluates the rightExpr to get its value. If either the left or right expressions are null or the values are either null or not number types, an error is returned. Otherwise, it proceeds to apply the operator on the two numbers and returns the result value (number)
- String Operator: A string operator expression is composed of a character operator, left expression, right expression. The object has the following structure:
operator string
(concat, replace with, to upper, to lower, trim space of, length of)
expr1 Expression
expr2 Expression
expr3 Expression
- function Evaluation: Evaluates the expr1 to get its value, then evaluates the expr2, and finally expr3. If either the expr1 or expr2 expressions are null or the values are either null or not string types, an error is returned. Otherwise, it proceeds to apply the operator on the two numbers and returns the result value (number)
- Logical: A logical expression is composed of a logical operator, left expression, right expression. The object has the following structure:
logical string
(AND, OR, NOT)
leftExpr Expression
rightExpr Expression
- function Evaluation: First evaluates the leftExpr to get its value, then evaluates the rightExpr to get its value. If the logical operator is AND, OR, it verifies both expression evaluated values exist. Otherwise returns an error. When the logical operator is NOT, the rightExpr must only be present. When the expressions required are present, the logical operator is applied to the value and returns the result (bool)
- Branch: A branch expression is composed of a condition expression, true expression, and false expression. The object has the following structure:
condition Expression
trueExpr Expression
falseExpr Expression
- function Evaluation: First evaluates the condition expression. If the condition does not exist, it will result in an error. Also, if the condition expression evaluated value is not a bool, an error is returned. Otherwise, it will proceed in evaluating the true and false expressions. If either of these are null, an error is returned. Otherwise, if the condition value is true, it will return the true expression evaluated value (any) and if the condition is false it will return the false expression evaluated value (any)