Web API: Expression/query: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
'''Expression | The '''Expression query''' runs a query written using the expression language in the server and returns the query results. | ||
HTTP request header '''Authorization''' with value '''Bearer <access token>''' needs to be in place to identify the session. | |||
<pre> | |||
Url: POST /api/expression/query | |||
Content-Type: application/json;charset=UTF-8 | |||
Body: | |||
{ | |||
ModelId: "123", | |||
Filter: "{"Items":[{\"Type\":\"IncludeCases\",\"Items\":[{\"Type\":\"CaseAttributeValue\",\"Attribute\":\"Account Manager\",\"Values\":[\"Patricia White\",\"Rober Miller\"]}]}]}", | |||
Configuration: "{\"Root\":\"Cases\","Dimensions\":[{\"name\":\"Case Duration\",\"expression\":\"Duration.ToInteger(TotalDays)\"}],\"Values\":[{\"name\":\"Case count\",\"expression\":\"Count(_)\"}]}", | |||
QueryIdentifier: "myQuery1", | |||
CancelEarlierQueriesWithIdentifier: "true" | |||
} | |||
</pre> | |||
== Request Format == | |||
Request body is a JSON object supporting the following properties: | |||
Expression Analysis query allows the following parameters: | Expression Analysis query allows the following parameters: | ||
* '''AnalysisType''': Analysis type is '''33''' for the Expression Analysis. | * '''AnalysisType''': Analysis type is '''33''' for the Expression Analysis. | ||
Line 67: | Line 77: | ||
</pre> | </pre> | ||
== Expression | == Response Format == | ||
Expression | The response can be an array (default) or object, determined by the '''ResponseType''' parameter. | ||
Parameter '''StringifyValues''' (boolean) (default false) determines that the cell values are stringified. When no stringification is used, values use normal JSON formatting for strings, numbers, booleans and nulls. Dates use format yyyy-MM-ddTHH:mm:ss.fff. Other data types use default stringification. | |||
In the cell values, the first character is the data type and rest of the characters are the value which interpretation depends on the data type as follows: | |||
* 0: string | |||
* 1: float number. May contain a decimal point (.) | |||
* 2: date in the form yyyy-MM-ddTHH:mm:ss.fff | |||
* 3: null value. There is no value part. | |||
* 4: small integer (32 bit) | |||
* 5: large integer (64 bit) | |||
* 6: boolean. Value is either ''True'' or ''False'' | |||
Example response: | |||
<pre> | |||
</pre> | |||
== Expression Query == | |||
Expression allows configurable objects, such as cases, events, event types or flows, to be divided into configurable dimensions and calculable values (KPIs). In a basic form, the result of this analysis is a table with the following columns: (1) One column for each specified dimension, and (2) at least one column for each specified value. The result of this analysis is a table with one row for each unique dimension value combination. | |||
When building expresssion analysis, it's essential to note in which contexts the individual expressions are run: | |||
* ''Root expression'' is run either in the [[QPR_ProcessAnalyzer_Objects_in_Expression_Language#EventLog|EventLog]] or [[Generic_Objects_in_Expression_Language#Generic_Context|generic]] context, depending on the ''ContextType'' setting. | |||
* ''Dimension expressions'' are run in the context of the individual object returned by the root expression. | |||
* ''Value (measure) expressions'' is run in the context of the array of items that are part of the dimensioned slice. If dimensioning is disabled (i.e. dimensions parameter is null), the value expression is run in the context of the individual object returned by the root expression. | |||
* ''Row initialization expression'' is run in the same context as the measures. RowInitExpression is run before the measures, so variables initialized in the RowInitExpression are available in the measures. | |||
* ''Aggregation expression'' is run in the context of an array of the rest of the items, i.e. items to be aggregated as the last row. | |||
== Configuration Parameter == | |||
The '''Configuration''' parameter has following structure: | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 258: | Line 298: | ||
== [[QPR ProcessAnalyzer Expression Analysis Examples|QPR ProcessAnalyzer Expression Analysis examples]] == | == [[QPR ProcessAnalyzer Expression Analysis Examples|QPR ProcessAnalyzer Expression Analysis examples]] == | ||
[[Category: QPR ProcessAnalyzer]] | [[Category: QPR ProcessAnalyzer]] |
Revision as of 18:32, 25 January 2021
The Expression query runs a query written using the expression language in the server and returns the query results.
HTTP request header Authorization with value Bearer <access token> needs to be in place to identify the session.
Url: POST /api/expression/query Content-Type: application/json;charset=UTF-8 Body: { ModelId: "123", Filter: "{"Items":[{\"Type\":\"IncludeCases\",\"Items\":[{\"Type\":\"CaseAttributeValue\",\"Attribute\":\"Account Manager\",\"Values\":[\"Patricia White\",\"Rober Miller\"]}]}]}", Configuration: "{\"Root\":\"Cases\","Dimensions\":[{\"name\":\"Case Duration\",\"expression\":\"Duration.ToInteger(TotalDays)\"}],\"Values\":[{\"name\":\"Case count\",\"expression\":\"Count(_)\"}]}", QueryIdentifier: "myQuery1", CancelEarlierQueriesWithIdentifier: "true" }
Request Format
Request body is a JSON object supporting the following properties: Expression Analysis query allows the following parameters:
- AnalysisType: Analysis type is 33 for the Expression Analysis.
- Configuration: Expression analysis configuration defined using JSON. Note that it's not allowed to use linebreaks in the JSON, i.e. the JSON definition must be in one line.
- ModelId: Model for which the calculation is run. This parameter is mandatory, if the calculation is run in an eventlog context.
- Filter: Filter definition as JSON. If Filter is defined, please do not use the FilterId parameter.
- FilterId: Filter for which the calculation run. If FilterId is not specified, calculation is run from the entire model. If FilterId is defined, please do not use the Filter parameter.
- ContextType: When eventlog, the root expression is run in an EventLog context, i.e.g EventLog's functions and properties can be used. When generic, the root expression is run in the generic context. If not specified, eventlog is used if FilterId or ModelId parameter is specified.
- RuntimeComparison: When set to true, the expression analysis works in the comparison mode (i.e. root causes mode) and the ComparisonEventLog property is available in the expressions. You also need to pass the Comparison parameter which the comparison between case sets are based on. The default value is false.
- Comparison: Comparison definition as JSON.
- Variable_<name>: Parameters starting with Variable_ define variables that are available as variables in the KPI expressions with name <name>. For example, when adding Variable_Region=Dallas to the query, there is a variable Region containing value Dallas that can be used in the expressions.
- EnableResultCaching: When set to true, expression analysis results are cached both in the client and server side. When false, analysis results are not cached. When ContextType=generic, no caching is used regardless of this setting.
- QueryIdentifier: Identifier of the query. Can be used to refer to the query, when cancelling pending queries.
- CancelEarlierQueriesWithIdentifier: Boolean value defining whether possible previous query with the same QueryIdentifier is cancelled when a new query with the same identifier is received by the server.
Example query:
{ "AnalysisType": 33, "ModelId": 1234, "Filter": { "Items": [ { "Type": "IncludeCases", "Items": [ { "Type": "EventType", "Values": [ "Change Price" ] } ] } ] }, "Configuration": { "Root": "Cases", "Dimensions": [ { "Name": "Start Month", "Expression": "StartTime.Month" } ], "Values": [ { "Name": "Average Case Duration in Days", "Expression": "Average(_.Duration).TotalDays" } ], "Ordering": [ { "Name": "Start Month", "Direction": "Ascending" } ] } }
Response Format
The response can be an array (default) or object, determined by the ResponseType parameter.
Parameter StringifyValues (boolean) (default false) determines that the cell values are stringified. When no stringification is used, values use normal JSON formatting for strings, numbers, booleans and nulls. Dates use format yyyy-MM-ddTHH:mm:ss.fff. Other data types use default stringification.
In the cell values, the first character is the data type and rest of the characters are the value which interpretation depends on the data type as follows:
- 0: string
- 1: float number. May contain a decimal point (.)
- 2: date in the form yyyy-MM-ddTHH:mm:ss.fff
- 3: null value. There is no value part.
- 4: small integer (32 bit)
- 5: large integer (64 bit)
- 6: boolean. Value is either True or False
Example response:
Expression Query
Expression allows configurable objects, such as cases, events, event types or flows, to be divided into configurable dimensions and calculable values (KPIs). In a basic form, the result of this analysis is a table with the following columns: (1) One column for each specified dimension, and (2) at least one column for each specified value. The result of this analysis is a table with one row for each unique dimension value combination.
When building expresssion analysis, it's essential to note in which contexts the individual expressions are run:
- Root expression is run either in the EventLog or generic context, depending on the ContextType setting.
- Dimension expressions are run in the context of the individual object returned by the root expression.
- Value (measure) expressions is run in the context of the array of items that are part of the dimensioned slice. If dimensioning is disabled (i.e. dimensions parameter is null), the value expression is run in the context of the individual object returned by the root expression.
- Row initialization expression is run in the same context as the measures. RowInitExpression is run before the measures, so variables initialized in the RowInitExpression are available in the measures.
- Aggregation expression is run in the context of an array of the rest of the items, i.e. items to be aggregated as the last row.
Configuration Parameter
The Configuration parameter has following structure:
Property | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Root | Root expression returning objects that are used in the next calculation step, which is the dimensioning. The root expression is run either in the EventLog context or in the generic context, depending on the ContextType parameter. | ||||||||||||||||
Dimensions | Array of Dimension objects. The rows are sliced into different groups based on how many unique values the dimension expressions produce. There can be zero to many dimensions. The result data contains a column for each dimension.
If dimension array is empty (i.e. Dimensions: []), all root objects are aggregated into a single row. If dimensions array is not defined at all (i.e. Dimensions: null), each object in the root expression will be as a separate row in the result. Then context for the value expression is (instead of array of objects) a single object. Each dimension may have the following properties:
| ||||||||||||||||
Values | Array of Value objects, which are the actual calculated values (i.e. measures or KPI's). Value expressions are calculated for each sliced data group, i.e. for each unique dimension value. The context of the value expression is an array of objects.
Each value object may contain properties defined in the table below. | ||||||||||||||||
Ordering | Array of Ordering objects. Ordering defined how the result table is sorted.
| ||||||||||||||||
AggregateOthers |
When true, all rows that are left out due to the MaximumRowCount limit, are aggregated and shown as the last row. Expressions to calculate the aggregations, can be defined for each dimension and measure using the AggregationExpression property. When the AggregationExpression is not defined, the default aggregated value is null. When the AggregateOthers is used, the maximum number of rows is still the MaximumRowCount, so with the aggregation there is one data row less shown. Default for AggregateOthers is false. | ||||||||||||||||
MaximumRowCount |
Integer value defining a limit how many rows at maximum are returned by the analysis. The default value is null, which means that all the rows will be returned. If sorting is used, the analysis results are first sorted before the limit is applied. | ||||||||||||||||
FirstRow |
Integer value defining the starting row number from the analysis results to return. The default value is null, which means that the first row will be the first returned row. Row numbers start from 0. If sorting is used, the analysis results are first sorted before this setting is applied. | ||||||||||||||||
Criteria | Expression returning boolean value to filter the resulting dataset row-by-row after dimensions and values are calculated. The criteria expression is calculated for each row of the dataset, and those rows are removed where the criteria expression results a false value. The respective row in the dataset is as a context for the criteria expression, similar to the DataFrame's Where function. | ||||||||||||||||
RowInitExpression | Specifies an expression that is evaluated for every generated row before evaluating the value expressions. RowInitExpression is calculated after the dimension expressions have been calculated and dimensions generated. RowInitExpression can be used to make common calculations and define variables that are needed in several value expressions. | ||||||||||||||||
ColumnOrdering |
An array of column names that defines the order in which the columns are returned. If an array contains a name that does not exist in the results, its value will be returned as null values in the returned result. If an array does not contain a name that is in the original result, then that column will not be returned at all. If ColumnOrdering is not defined, all the result rows will be returned in the defined order so that all the dimensions are returned before the values. Example: "ColumnOrdering": ["Case Count", "Account Manager", "Average Duration"] |
Properties of the Value object:
Property | Description |
---|---|
Name | Name for the value. Used only when ValueType is Single. |
Expression | Behavior depends on the ValueType property:
|
AggregationExpression | Expression to calculate the aggregated value for the rest of the rows for this column when using the AggregateOthers setting. All the aggregated values are provided as the context (_) for the aggregation expression. If no aggregation expression is defined, null value is used. Example aggregation expressions:
Row count: "AggregationExpression": "Count(_)" Sum of values (for numerical columns): "AggregationExpression": "Sum(_)" Showing count, minimum and maximum values: "AggregationExpression": "\"(\" + Count(_) + \" others) \" + Min(_) + \" - \" + Max(_)" |
ValueType |
Type of the value, which is one of the following:
|
ValueDimensionExpression
(ValueType: Dynamic, Pivot) |
Expression used to generate columns in Dynamic and Pivot value types. The expression should return an array where each item represents a column. This expression is executed once when calculating the Expression analysis. For Dynamic type value ValueDimensionExpression field is mandatory, and for Pivot type it's not mandatory.
The result of this expression will be given as the value of variable ValueDimension when evaluating the Expression. For Pivot type value, this can be used to override the default set of columns created automatically based on the actual cell evaluation results. An array of all the actual dimension values created by the actual cell evaluation result is given as context object for the evaluation. |
NameExpression
(ValueType: Dynamic, Pivot) |
Expression used to generate column names in Dynamic and Pivot value types. This expression is run once for each column, and the expression has as a context the column generated in the ValueDimensionExpression, and as a result the expression should give the column name. |
DimensionOrderExpression
(ValueType: Pivot) |
Expression used to order the dimensions when pivot value type value is used. If not defined, the following default expression will be used: OrderByValue(_). |
PivotAggregationExpression
(ValueType: Pivot) |
Expression used to aggregate all the values within one cell of pivot type values. If the expression returns an array of arrays, the first item in the inner array is used as the ValueDimension and the second item is used as the root object when evaluating PivotAggregationExpression. By default, if expression returns only an array of atomic objects, the root object of the evaluation of PivotAggregationExpression is the value of the current ValueDimension. |
DefaultValueExpression
(ValueType: Pivot) |
Expression whose result is used to fill the "gaps" of the matrix created when pivot value type is used. |
JSON structure example:
{ "Root": "Root expression", "Dimensions": [ { "Name": "Dimension 1 name", "Expression": "Dimension 1 expression" }, { "Name": "Dimension 2 name", "Expression": "Dimension 2 expression" }, ... ], "Values": [ { "Name": "KPI 1 name", "Expression": "KPI 1 expression" }, { "Name": "KPI 2 name", "Expression": "KPI 2 expression" }, ... ], "Ordering": [ { "Name": "Ordered column 1 name", "Direction": "Ascending/Descending" }, { "Name": "Ordered column 2 name", "Direction": "Ascending/Descending" }, ... ] }