QPR ProcessAnalyzer Expressions: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
QPR ProcessAnalyzer expression language is robust query engine all the QPR ProcessAnalyzer data and models. The expression language is able to do many kinds of calculataion operations, such as aggregation, dimensioning and following relations between objects.
=== Expression and Evaluation Context ===
=== Expression and Evaluation Context ===


An '''expression''' is a text to be evaluated that has a result. Result can be any of the supported object types or empty. An expression may consist of multiple expressions, called '''sub-expressions'''.
An '''expression''' is a text to be evaluated and it has a result. Result can be any of the supported object types or empty. An expression may consist of multiple expressions, called '''sub-expressions'''.


Expression evaluation is always performed within some '''context'''. This context and its type defines which kind of functionalities are available. '''Current context''' is '''implicitly''' accessible in all the expressions. Whenever a function or property is called, functions and properties accessible in the current context are searched first. If function or property is not found in the current context, then more generic context is tried. Error is returned only if the requested functionality is not available in the current context or a generic context. Current context can be accessed '''explicitly''' by using variable named '''_''' (underscore).
Expression evaluation is always performed within some '''context'''. This context and its type defines what functionalities are available. '''Current context''' is automatically accessible in all the expressions. Whenever a function or property is called, functions and properties accessible in the current context are searched first. If function or property is not found in the current context, then more generic context is tried. Error is returned if the requested functionality is not available in the current context or a generic context. Current context can be accessed explicitly by using variable named '''_''' (underscore).


=== Expression Chaining and Hierarchies using . and : ===
=== Expression Chaining and Hierarchies using . and : ===
Expressions can be chained together two ways:
Expressions can be chained together two ways:
* '''Contextless chaining''': When '''.''' character is used to chain expressions, the resulting objects will not have context information.
* '''Contextless chaining''': When '''.''' character is used to chain expressions, the resulting objects will not have context information.
* '''Hierarchical chaining''': When ''':''' character is used to chain expressions, only the result of the whole chained expression will consist of hierarchical arrays (#29290#) where all the values in the first expression (=context object) will be bound to the arrays those values generated. If the second expression does not return an array, the result will be changed to be an array.
* '''Hierarchical chaining''': When ''':''' character is used to chain expressions, only the result of the whole chained expression will consist of hierarchical arrays where all the values in the first expression (=context object) will be bound to the arrays those values generated. If the second expression does not return an array, the result will be changed to be an array.


The second expression chained to the first one will be evaluated using the following rules:
The second expression chained to the first one will be evaluated using the following rules:

Revision as of 09:35, 31 January 2018

QPR ProcessAnalyzer expression language is robust query engine all the QPR ProcessAnalyzer data and models. The expression language is able to do many kinds of calculataion operations, such as aggregation, dimensioning and following relations between objects.

Expression and Evaluation Context

An expression is a text to be evaluated and it has a result. Result can be any of the supported object types or empty. An expression may consist of multiple expressions, called sub-expressions.

Expression evaluation is always performed within some context. This context and its type defines what functionalities are available. Current context is automatically accessible in all the expressions. Whenever a function or property is called, functions and properties accessible in the current context are searched first. If function or property is not found in the current context, then more generic context is tried. Error is returned if the requested functionality is not available in the current context or a generic context. Current context can be accessed explicitly by using variable named _ (underscore).

Expression Chaining and Hierarchies using . and :

Expressions can be chained together two ways:

  • Contextless chaining: When . character is used to chain expressions, the resulting objects will not have context information.
  • Hierarchical chaining: When : character is used to chain expressions, only the result of the whole chained expression will consist of hierarchical arrays where all the values in the first expression (=context object) will be bound to the arrays those values generated. If the second expression does not return an array, the result will be changed to be an array.

The second expression chained to the first one will be evaluated using the following rules:

  • If the result of the first expression is not an array, the second expression will be evaluated with the result of the first expression as its context object.
  • If the result of the first expression is an array, for every element in the array, the second expression will be evaluated with the array item as its context object. The result of the evaluation will be an array of evaluation results (one for each element in the array).
  • If any of the second expression evaluations returns an array, the resulting object will be an array of arrays. If the first expression evaluation returns a typed array, the result will be hierarchic in a way that first level results are objects that contain the information about the actual object as well as the results generated by the second level expressions.

These rules apply also when chaining more than two expressions together. For example, it is possible to generate three level hierarchy with nodes of type: event log -> case -> event: EventLogById(1).Cases.Events or EventLogById(1):Cases:Events.

Examples:

Contextless chaining: First expression not an array, second expression not an array:
"1".("Number is " + _)
Returns:
"Number is 1"

Contextless chaining: First expression is an array, second expression not an array:
[1,2,3].("Number is " + _)
Returns:
["Number is 1", "Number is 2", "Number is 3"]

Contextless chaining: First expression is an array, second expression is an array:
[1,2,3].["Number is " + _, "" + _ + ". number"]
Returns:
[ ["Number is 1", "1. number"], ["Number is 2", "2. number"], ["Number is 3", "3. number"] ]

Hierarchical chaining: First expression is an array, second expression is an array:
[1,2,3]:["Number is " + _, "" + _ + ". number"]
Returns:
[ HierarchicalArray(1, ["Number is 1", "1. number"]), HierarchicalArray(2, ["Number is 2", "2. number"]), HierarchicalArray(3, ["Number is 3", "3. number"]) ]

  • Hierarchical arrays: Whenever traversing a relation in expression language using hierarchical chaining operator ':' for chaining expressions, a hierarchical array will be returned. It is an object which behaves just like a normal array except it stores also context/root/key/label object which usually represents the object from which the array originated from, for example the original case object when querying events of a case.
  • Hierarchical objects: Arrays where at least one object in the array is itself an array is considered to be a hierarchical object. Hierarchical arrays are treated in similar way as normal arrays in hierarchical objects.
  • Depth of a hierarchical object is the number of inner arrays that there are in the object, i.e. how deep is the hierarchy.
  • Level in hierarchical object consists of all the nodes that are at specific depth in object's array hierarchy. 0 is the level at the root of the object, consisting only of the object itself as single item. Levels increase when moving towards leaves.
  • Leaf level is a level that doesn't have any sub levels.

Basic arithmetic operations

  • Addition (+) can be performed on numeric types, strings (concatenate two strings) and TimeSpans (addition of two TimeSpans).
  • Subtraction (-) can be performed on numeric types, DateTimes (calculating TimeSpan between two DateTimes) and TimeSpans (difference between two TimeSpans).
  • Multiplication (*) can be performed on numeric types, and between a TimeSpan and a numeric type (multiplying TimeSpan by number which results in TimeSpan),
  • Division (/) can be performed on numeric types, between a TimeSpan and a numeric type (dividing a TimeSpan where TimeSpan must be the left hand side operand).

Lookup operator

Lookup operator is used to extract a subset of values from an array. The value returned by the expression inside brackets defines a single index or multiple indexes to extract from the array. This expression will be evaluated in the context of the array being indexed. If the expression inside brackets results in an integer value, the result of the whole expression will be the array item at the specified index. If the expression inside brackets results in an array of integers, the result of the whole expression will be an array consisting of the array items at indexes specified by the integers.

Examples:

[1, 2, 3, 4][1]
Returns: 2

[1, 2, 3, 4][Count(_) - 1]
Returns: 4

["a", "b", "c", "d"][[0, Count(_) - 1]]
Returns: ["a", "d"]

[[1, 2], 3, [4, [5, 6]]][2][1][0]
Returns: 5

See Also