Expression Query¶
Expression query is a method of performing data calculation and analysis by adding and combining multiple query statements. It allows the use of mathematical operators and functions in queries for more complex processing and transformation of data.
In the actual chart query application of Guance, you can directly use the identifiers (such as a, b) of all queries to quickly build expressions, for example: a/b*100.
Note
- Queries referenced by expression queries cannot be deleted.
- For historically created expressions containing subqueries (A/B/...), their original identifiers cannot be used in new expressions. It is recommended to update the chart and use new expressions. Old expressions can still be used normally but are no longer supported for new creations.
Concepts¶
| Term | Description |
|---|---|
| Expression | Consists of one or more query statements, combined and calculated using mathematical operators (such as +, -, *, /) and functions (such as SUM, AVG, MAX). |
| Grouping Label | Used to identify and distinguish different query statements in a group. In expression queries, the grouping labels of all query statements must be consistent to ensure calculation accuracy. |
| Unit Handling | If the query statement includes units (such as KB, MB, seconds, etc.), the calculation result will retain the same units. For example, if query a has a unit of KB, then a + 100 will also have a unit of KB. |
Query Examples¶
Example 1: Calculate the sum of two queries
Assume you have two query statements:
- Query a: Returns the sum of data
- Query b: Returns the average of data
You can use expression query to calculate their sum: a+b
Example 2: Unit conversion of query results
Assume query a returns data in KB, and you want to convert it to MB: a/1024
Example 3: Complex calculation using functions
Assume you need to calculate the difference between the maximum value of query a and the minimum value of query b: MAX(a)-MIN(b)
Note
- Grouping Label Consistency: In expression queries, the grouping labels of all query statements must be consistent; otherwise, calculation errors may occur.
- Unit Consistency: In expression calculations, if the query statements include units, the calculation result will retain the same units.
- Performance Optimization: Complex expression queries may affect query performance. Data preprocessing may be necessary when required.