UC12 - Filter Data Dynamically with an Expression Variable

In data query operators, you can filter values dynamically using an expression. The goal is to retrieve an expression with arguments from an index unit and store it in an Expression variable. Then you can inject this expression in a data query operator using an input parameter, and filter the values shown in your Data Perspective dynamically.

This feature is similar to the initialization of filters when you start a Data Perspective.

See Also
FILTER
Defining a Variable for Data Perspective Access
Creating Input Parameters
RESULT SET
  1. In Data Perspective Studio, create a parameter to inject expressions into your data query.
    1. From the top bar, click $ Input parameters.
    2. In the Parameters panel, click to add a Parameter.
    3. Give a name to the parameter. For example, myparameter.
    4. For Return type, select the return type of the input parameter.

      The return type is the type that comes out of the expression. If the expression takes a string and an integer as input, and processes data to calculate another integer, then the return type must be Integer. If the expression calculates a string, the return type must be String.

    5. For Default value, define the same type as the Return type.
    6. Select DataQuery parameter, to make the input parameter available in data queries.

    There is a correlation between the input parameters arguments and the expression arguments. For example, if you create an arg1 argument, of type String, you can use it in your expression by entering arg1 directly. It also works the other way round. If you define an expression using a variable part (for example, "a+b"), you can create the corresponding arguments in the input parameter (for example, arguments "a" and "b").

  2. Add an operator to the data query. For example, add a FILTER operator.    
    1. Select an Index unit.
    2. In Variable, select an index unit class, and specify the name of the variable that you will use in the Expression field.
  3. In the operator, configure an Expression calling the input parameter.
    1. In Expression, click .
    2. In the Expression Editor, enter an expression. For example, you can enter an expression so that input.age must be higher than the result of your expression.

  4. Add a RESULT SET operator at the end of the data query and test your configuration.
    1. Click Run.
    2. In the Params field, you can see the input parameter.
    3. Enter an expression and verify its result in the right panel.
  5. In Data Factory Studio, create a field of type Text in your Semantic Graph Index to contain the expression.

    You might need to "escape" the expression. For example, enter the following string in your index unit: a===\"Paris\" to run an expression like a==="Paris" in Data Perspective Studio.

  6. In Data Perspective Studio, create an Expression variable.
    1. From the navigation menu, select Resources > Variables.
    2. Click Add variable.
    3. In Name, enter the variable name. For example, myvar.
    4. In Type, select Expression and whether it must be mono-valued or multivalued.

      Important: The return type must be the same as the input parameter bound to the variable.

    5. Enter either an Initial value if your variable has a single value, or several Initial values if your variable has multiple values.
  7. Add a Set variable effect.
    1. From the navigation menu, select Settings > Actions.
    2. Under On Perspective access, click to add a new effect.
    3. Select the Set variable effect.
    4. From Information source, select a data query and a result set. Then select the field from which the Data Perspective will retrieve the first value.
    5. From Target studio variable, select the Expression variable defined in the previous step.