Skip to content
DonMartin76 edited this page Jul 14, 2015 · 3 revisions

Expression Types

For an "Expression" in NFT, there exist the following types of expression (and sub-expression) types:

Any expression has (a) a list of input parameter types, and (b) a return type. The supported data types are currently only the following:

  • Strings: string
  • Integer values: int
  • Boolean values: bool

Some operators support an arbitrary input type, which in code is denominated as an any type. These are usually the operators which operate on string parameters. The types int and bool are automatically converted to their string representations in case passed into such an operator.

Data Type checking

The expression parser and evaluator will perform a simple type check on input parameters. Depending on the use of the expression, it will also be checked if the return type of the expression matches its use in the configuration file. Examples:

  • For a field definition, the return type can be of any type, but will be converted to string before passing to the writer instance
  • For a source filter definition, the return type of the top expression must be a bool.

Expression Language

The NFT expression language is, except for the string literals and the integer literals a prefix language, which means that operators on parameters are always noted in front of a parameter list.

The only exceptions for this are the following two:

  • The + infix operator is shorthand for the Concat operator (see Concat Operator)
  • The = infix operator is shorthand the the Equals operator (see Equals Operator)

The number of parameters of an operator is (currently) a fixed number which is documented in the Operator Documentation. There are no operators which have a variable number of parameters.

Examples:

Use Case Expression
Concatenating first and last name with a blank in the middle Concat(Concat($FirstName, " "), "$LastName)
Alternatively: $FirstName + " " + $LastName
Create an email address, if both first name and last name are present If(And(Not(IsEmpty($FirstName))), Not(IsEmpty($LastName)))), $FirstName + "." + $LastName + "@mydomain.com", "")
Lookup a key in a lookup table, if present If(HasKey("MyLookup", $Key), MyLookup($Key, $Value), "<undefined>")
## The Field operator `$`

The field operator $ refers to a field in the source data. After the $ sign, the field name has to be passed.

The evaluator will retrieve the value of this source data field and pass it on.

If a source transformation is being used in the transformation configuration, the evaluator will first look into the fields generated by the transformation, and after that (if not found) resort to consulting the source data fields.

For more information on transformations, see Config File Documentation and SAP Transformer (which is an implementation of a Transformer).

Examples:

Use Case Expression
Retrieve the content of the street field from the data source $Street
Upper case the last name UpperCase($LastName)

If the field operator cannot find the source field, it will throw an error and the processing will be cancelled.

The return type of the Field operator is always string. If you need this to be interpreted as an integer, use the Int Operator.

## Using String literals

Any string contained within double quotes "" will be treated as a string literal. A string literal is encapsulated in the evaluator as an operator without parameters which returns a string type with the value passed within the double quotes.

Examples:

<Field name="bogus">"This is a fixed string"</Field>
<Field name="something">"Return status: " + $status</Field>

As in the example, string literals can be used anywhere a string type is needed, be it as parameter values or return values for strings. In the first example, the field bogus is simply mapped to the static string This is a fixed string.

## Using Integer literals

Integer literals can be written intuitively into an expression, wherever an int type is needed. Normal use cases for this include specific parameter values for string manipulation operators such as the Substring or PadLeft Operator.

On most cases where a string expression return type is needed, an expression rendering an int type can be used. The integer is in that case converted to a string, using no kind of formatting whatsoever.

Example: PadLeft($invoiceCode, 10, "0") pads the field $invoiceCode with zeros to the left until the output has 10 (or more) characters. Here, 10 is the integer literal.

An integer literal is encapsulated in the evaluator as an operator without operators which returns an int type with the value passed on.

## Using operators

An operator has input parameters and a return type.

An extensive documentation on the available operators can be found under Operator Documentation.

## Using custom operators

Custom operators are treated in exactly the same way as normal operators are. For an extensive documentation of custom operators, see Using Custom Operators.

## Parameters

For the sake of completeness, the parameter operator % is mentioned on this page. The parameter operator can only be used within custom operators for reference to the input parameter of a custom operator.

See Using Custom Operators for more information.

Example:

<CustomOperator name="MakeEMail" paramCount="3" returnType="string"/>
  <Parameters>
    <Parameter name="firstName" type="string" />
    <Parameter name="lastName" type="string" />
    <Parameter name="domain" type="string" />
  </Parameters>
  <Switch>
    <!-- Sanity check of input parameters -->
    <Case condition="IsEmpty(%firstName)">""</Case>
    <Case condition="IsEmpty(%lastName)">""</Case>
    <Case condition="IsEmpty(%domain)">""</Case>
    <!-- Now string together the EMail address -->
    <Otherwise>Concat(Concat(Concat(Concat(%firstName, "."), %lastName), "@"), %domain)</Otherwise>
  </Switch>
</CustomOperator>

This function may then be called in a field definition, for example as follows:

<Field name="email">MakeEMail($FirstName, $LastName, "mydomain.com")</Field>
Clone this wiki locally