Supporting expressions for collection variables

Input variables passed for expression evaluation can be repeating or non-repeating. For repeating variables, the expression is evaluated once for each instance of the variable. Expression results are returned as a collection. Input variables can repeat at different levels, for example one of the input variables can be a list of strings and another can be a list of list of strings. For handling the difference in collection hierarchy, expression manager flattens these collection variables into a two-dimensional array where each row represents input parameters required to evaluate the expression. Expression is evaluated on each row and result is organized according to the hierarchy of the input variables.

All the collection variables being used for expression evaluation are part of the single hierarchy. When examining a path from root element to the deepest collection variable, all collection variables falls on this path. For non-repeating variables, there is no such restriction. If any of the input variable instance is null, the result is set to null for this instance. Expression evaluation for other instances is done in a normally. At any given level and index, all variables contain same number of elements. If a variable does not contain elements at a certain level, that variable is not compared for that level.

Example

The following schema represents a customer and account:

bank 
    *customer 
        age 
        *account 
            baseInterestRate 
            actualInterestRate

In this example the bank, customer and account are composite elements. Customer and account are repeating elements. The age is of type int and baseInterestRate and actualInterestRate are of type float. The bank can have many customers and each customer can have multiple accounts. Each account has a base interest rate and actual interest rate. Actual interest rate is a computed element and depends on base interest rate and customer’s age. Assume expression for acualInterestRate is baseInterestRate + (age >= 60 ? 0.5:0.0). At runtime expression manager is provided following values for age and baseInterestRate:

age: [20, 61] 
baseInterestRate: [[7, 8][7.5, 8, 8.5]]

After flattening these variables, the following two-dimensional array is created:

20 7 
20 8 
61 7.5 
61 8 
61 8.5

Age elements are repeated multiple times according to number of elements in baseInterestRates. Expression is evaluated for each of these rows. After evaluating expressions, results are arranged in the same hierarchy as the input variable baseInterestRate. The variable with most number of repeating levels is considered because expression is always at the deepest level and does not use variables which are further down in hierarchy. API returns the result as [[7, 8][8, 8.5, 9]].

// Ethnio survey code removed