The following table shows a list of all the DQL operators.
| Operator | Description |
|---|---|
| Addition |
| Subtraction or arithmetic negation |
| Multiplication |
| Division |
| Modulo |
| Less than |
| Less than or equal to |
| Greater than |
| Greater than or equal to |
| Equals |
| Does not equal |
| Logical NOT (negation) |
| Logical AND |
| Logical OR |
| Logical XOR (exclusive or) |
| Subquery comparison |
| Time alignment |
| Search |
The precedence for the operators is as follows (from strongest to weakest):
- (arithmetic negation)*, /, %@+, - (subtraction)~==, !=, >, >=, <, <=innotandxororYou can use arithmetic operators with numbers, represented by both the types long or double. In addition, some operators support the types timestamp, timeframe, duration or ip.
| Operator | Description | Example |
|---|---|---|
| Addition |
|
| Subtraction |
|
| Multiplication |
|
| Division |
|
| Modulo |
|
| Arithmetic negation |
|
| ADDITION | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long |
|
|
| |||||||||
Double |
|
|
| |||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp |
| |||||||||||
Duration |
|
|
| |||||||||
Timeframe |
| |||||||||||
Binary | ||||||||||||
IP |
|
|
| |||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
| SUBTRACTION | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long |
|
| ||||||||||
Double |
|
| ||||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp |
|
| ||||||||||
Duration |
| |||||||||||
Timeframe |
| |||||||||||
Binary | ||||||||||||
IP |
|
|
| |||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
| MULTIPLICATION | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long |
|
|
| |||||||||
Double |
|
|
| |||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp | ||||||||||||
Duration |
|
| ||||||||||
Timeframe | ||||||||||||
Binary | ||||||||||||
IP | ||||||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
When you divide a long value by another long value using the / operator, the result is also a long value, and any fractional part is discarded. To get a result with the fractional part (a double value), you need to convert or cast at least one of the operands to double (e.g., by using the toDouble function).
| DIVISION | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long |
|
| ||||||||||
Double |
|
| ||||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp | ||||||||||||
Duration |
|
|
| |||||||||
Timeframe | ||||||||||||
Binary | ||||||||||||
IP | ||||||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
The data type resulting from the operation is indicated in parentheses in the table above.
| MODULO | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long |
|
| ||||||||||
Double |
|
| ||||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp | ||||||||||||
Duration |
| |||||||||||
Timeframe | ||||||||||||
Binary | ||||||||||||
IP | ||||||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
| NEGATION | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
SELF |
|
|
|
| Operator | Description | Example |
|---|---|---|
| Less than |
|
| Less than or equal to |
|
| Greater than |
|
| Greater than or equal to |
|
true or false based on the result of the operatornull| <, <=, >, >= | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long | ||||||||||||
Double | ||||||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp | ||||||||||||
Duration | ||||||||||||
Timeframe | ||||||||||||
Binary | ||||||||||||
IP | ||||||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
| Operator | Description | Example |
|---|---|---|
| Equals |
|
| Does not equal |
|
Equality comparisons (==, !=) use a tri-state boolean algebra (true, false, null). This means that if any side of the equality comparison is null, the overall result of the comparison is null.
There are four DQL functions that cover scenarios where missing or null records need to be retrieved:
For example, the below query that uses basic filtering does not provide records with null or missing values:
fetch logs| filter log.source != "logsourcename" // does not provide the records where `log.source` is null or missing
However, using the isTrueOrNull function includes those records with null and missing values:
fetch logs| filter isTrueOrNull(log.source != "logsourcename") // also provides the records where `log.source` is null or missing
false for non-comparable types in case of == operator, true for non-compatible types in case of != operatortrue or false based on the result of the operatornull - if one of the operands is nullnull == null - null| ==, != | Long | Double | String | Boolean | Timestamp | Duration | Timeframe | Binary | IP | UID | Array | Record |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Long | ||||||||||||
Double | ||||||||||||
String | ||||||||||||
Boolean | ||||||||||||
Timestamp | ||||||||||||
Duration | ||||||||||||
Timeframe | ||||||||||||
Binary | ||||||||||||
IP | ||||||||||||
UID | ||||||||||||
Array | ||||||||||||
Record |
| Operator | Description | Example (yields true) |
|---|---|---|
| Logical NOT (negation) - Negates a logical state |
|
| Logical AND (multiplication) - Yields |
|
| Logical OR (addition) - Yields |
|
| Logical XOR (exclusive OR) - Yields |
|
The behavior of logical operators follows the tri-state boolean logic.
AND
true AND null = nullnull AND true = nullfalse AND null = falsenull AND false = falsenull AND null = nullOR
true OR null = truenull OR true = truefalse OR null = nullnull OR false = nullnull OR null = nullXOR
true XOR null = nullnull XOR true = nullfalse XOR null = nullnull XOR false = nullnull XOR null = nullNOT
null = nullIterative expressions allow you to perform element-wise operations on arrays without expanding them into separate records.
The core mechanism behind iterative expressions is the [] operator appended to an array, which can be referenced by a field name or any array expression in general. Writing myArray[] tells DQL to iterate over each element of myArray. You can also access nested fields within arrays of records using the syntax myArray[][fieldName], which iterates over each record in the array and extracts the specified field. Similarly, you can also use nested arrays and iterate along one dimension such as with myArray[][0].
DQL provides iterative functions such as iAny() and iCollectArray(), that consume the per-element results. iIndex() is a companion function available in any iterative expression that returns the 0-based integer index of the current element.
When DQL encounters an iterative expression, it follows these steps:
[] references to determine which arrays drive the iteration.[]. If multiple arrays are referenced, they must all have the same length, otherwise the result is null.i-th element of each [] referenced array.iCollectArray() if no iterative function is present.When an iterative expression appears outside of an explicit iterative function, such as iAny() or iCollectArray(), DQL implicitly wraps it in iCollectArray(). This means the per-element results are automatically collected into a new array.
In other words, these two statements are equivalent:
| fieldsAdd a[] * b[]
| fieldsAdd iCollectArray(a[] * b[])
Both evaluate a[i] * b[i] for each index i and collect the results into an array. This implicit wrapping allows you to write concise element-wise expressions directly in DQL without always spelling out iCollectArray(...).
When arrays are referenced with [], DQL performs element-wise operations. The implicit iCollectArray() wrapping applies in the following example as well:
data record(a = array(1, 2, 3), b = array(10, 20, 30)),record(a = array(1, 2, 3), b = array(10, 20)),record(a = array(1, 2, 3), b = null)| fieldsAdd a[] * b[]
Query result:
| a | b | a[] * b[] |
|---|---|---|
|
|
|
|
|
|
|
|
|
The iterative expression evaluates to null for records where a and b are not both arrays of equal size.
Checks an iterative boolean expression. Returns true if the expression evaluated to true for at least one element, false if it was never true (non-boolean values are treated as false), or null if all elements are null.
data record(a = array(1, 2, 3)),record(a = array(4, 5, 6))| fieldsAdd iAny(a[] >= 4)
Query result:
| a | iAny(a[] >= 4) |
|---|---|
|
|
|
|
data record(a = array(record(b = 1), record(b = 2), record(b = 3))),record(a = array(record(b = 4), record(b = 5), record(b = 6)))| fieldsAdd iAny(a[][b] >= 4)
Query result:
| a | iAny(a[][b] >= 4) |
|---|---|
[b: |
|
[b: |
|
data record(technologies = array("Java", "Python")),record(technologies = array("Go", "Rust")),record(technologies = array(null, null))| fieldsAdd no_java = not iAny(technologies[] == "Java"),any_but_java = iAny(not technologies[] == "Java")
Query result:
| technologies | no_java | any_but_java |
|---|---|---|
|
|
|
|
|
|
|
|
|
When all array elements are null, both expressions return null. iAny cannot resolve to true or false without at least one definitive value. Consequently, records with fully null arrays will never pass a filter iAny(...) regardless of where not is placed.
This pattern uses double negation: not in(needle[], haystack) is true for each element of needle that is absent from haystack. iAny(...) returns true if at least one element is missing. Negating the whole result with not means the expression is true only when no element is missing — that is, all elements of needle are contained in haystack.
data record(needle = array(1, 2), haystack = array(1, 2, 3)),record(needle = array(3, 4), haystack = array(1, 2, 3))| fieldsAdd not iAny(not in(needle[], haystack))
Query result:
| needle | haystack | not iAny(not in(needle[], haystack)) |
|---|---|---|
|
|
|
|
|
|
Collects the results of an iterative expression into a new array. Returns null if the expression can't be evaluated (for example, when referenced arrays differ in length or any referenced array is null).
data record(a = array(1, 2, 3), b = array(10, 20, 30))| fieldsAdd iCollectArray(a[] + b[])
Query result:
| a | b | iCollectArray(a[] + b[]) |
|---|---|---|
|
|
|
data record(services = array(record(name = "auth", latency = 12),record(name = "gateway", latency = 8),record(name = "cache", latency = 5)))| fieldsAdd total_latency = arraySum(iCollectArray(services[][latency]))| fieldsAdd service_names = iCollectArray(services[][name])
Query result:
| services | total_latency | service_names |
|---|---|---|
[name: |
|
|
For total_latency it is important to place iCollectArray() inside arraySum(...). Otherwise iCollectArray() would be implicitly added enclosing arraySum(). For service_names, explicitly adding iCollectArray(...) is optional.
null fallbackdata record(a = array(1, 2, 3), b = array(10, 20, 30)),record(a = array(1, 2, 3), b = null)| fieldsAdd c = if(isNotNull(b), iCollectArray(a[] * b[]), else: a)
Query result:
| a | b | c |
|---|---|---|
|
|
|
|
|
|
It is important to add iCollectArray() explicitly within the if(...) function. Otherwise, the whole if() function gets evaluated repeatedly, and the iterative expression evaluates to null when a or b are not arrays or are not the same size.
Returns the 0-based integer index of the current element in the enclosing iterative expression. Use it to pair each array element with its position or to compute index-dependent transformations.
iIndex() only works in expressions where at least one iterative expression ([]) is present.
data record(a = array(2, 3, 7, 7, 1))| fieldsAdd a_indexed = record(value = a[], index = iIndex())
Query result:
| a | a_indexed |
|---|---|
| [index: |
data record(a = array(2, 3, 7, 7, 1))| fields a = record(value = a[], index = iIndex())| expand a| fields index = a[index], value = a[value]
Query result:
| index | value |
|---|---|
|
|
|
|
|
|
|
|
|
|
The in comparison operator evaluates the occurrence of a value returned by the left side's expression within a list of values returned by the right side's DQL subquery.
Syntax
expression in [execution block]
Usage and constraints
| Name | Type | Mandatory | Constraints | Description |
|---|---|---|---|---|
left side | expression | yes | Either a field identifier or an expression. | The element to be found in the list returned by the right side's subquery. |
right side | execution block | yes | It has to return a single field providing a list of values. | The DQL Subquery which returns the list of values to compare against. |
Example
This example shows how to use the in keyword for filtering a host metric for the host's attribute:
timeseries avg(dt.host.cpu.usage), filter:dt.entity.host in [fetch dt.entity.host| fieldsAdd tags| expand tags| filter tags == "ServiceNow" | fields id]
The @ operator aligns a timestamp to the provided time unit. It rounds down the timestamp to the beginning of the time unit.
[timestamp|duration|calendarDuration] @ unit
On the left side of the @ operator, you can use a timestamp expression, a duration expression, or a calendar duration.
If you use the @ operator without an expression on the left side, the operator will use the timestamp expression now() and will align the current time to the time unit. For example, @h is the beginning of the current hour, and equivalent to now()@h. Expressions of type duration and calendar durations are considered as an offset to now().
For example, -2M@... is equivalent to (now() - 2M)@....
The time unit can be any DQL supported duration unit including s (second), m (minute), h (hour), or a calendar duration unit like d (day), w (week), M (month), q (quarter), and y (year).
Duration units (h, m, s, ms, us, and ns) allow to add a factor, for example, @3h.
Leaving the factor out is equivalent to setting it to 1. Note the following constraints when adding such factor:
h supports all divisors of 24: 1h, 2h, 3h, 4h, 6h, 8h, 12h, 24h. @24h is similar to @1d but might differ in the case of daylight-saving times.m and s support all divisors of 60: 1m, 2m, 3m, 4m, 5m, 6m, 10m, 12m, 15m, 20m, 30m, 60m, and equivalently for s.ms, us, and ns support all divisors of 1000.By default, the week unit w uses the first day of the week as defined by your configured locale.
To explicitly specify the first day of the week, you can use the following time units:
w0 (Sunday)w1 (Monday)w2 (Tuesday)w3 (Wednesday)w4 (Thursday)w5 (Friday)w6 (Saturday)w7 (Sunday)For example, @w1 means midnight of Monday of the current week.
For the following examples, the current time is Wednesday, 04 September 2024, 14:47:05+0200.
| Time modifier | Description | Resulting time |
|---|---|---|
| 2 hours ago, aligned to the hour | Wednesday, 04 September 2024, 12:00:00+0200 |
| Yesterday, aligned to the day | Tuesday, 03 September 2024, 00:00:00+0200 |
| 7 days ago, aligned to the day | Wednesday, 28 August 2024, 00:00:00+0200 |
| Start of this week, from Sunday | Sunday, 01 September 2024, 00:00:00+0200 |
| Start of this week, from Monday | Monday, 02 September 2024, 00:00:00+0200 |
| Start of this month | Sunday, 01 September 2024, 00:00:00+0200 |
| Start of last month | Thursday, 01 August 2024, 00:00:00+0200 |
| Start of this quarter | Monday, 01 July 2024, 00:00:00+0200 |
| Start of this year | Monday, 01 January 2024, 00:00:00+0100 |
You can use the ~ operator in expressions to match the value of an expression against a given search string. The performed comparison is case-insensitive and supports pattern matching using wildcards. The ~ operator returns a boolean value: true in case of a match, and false otherwise.
expression ~ "string literal"
You can use any expression on the left side of the ~ operator. For details on how different data types work with this operator, see the Returns section.
The string literal to search for. It can be one of the following:
A search string without a wildcard (*). For example:
content ~ "error"
A search string with wildcard (*) characters. For example:
user ~ "*dynatrace.com"
A search string supports a maximum of 64 wildcard characters. Consecutive wildcards (for example, **) aren't supported.
The ~ operator searches the value as a string token inside a string. Its behavior depends on the data type of the expression on the left side:
If the expression is of type string, the operator searches the value as a token inside the string. It's case-insensitive. For example, "Hello World" matches ~"world", but "HelloWorld" doesn't.
If the expression is of type long, double, smartscape ID, IP address, or UID, the operator only matches if the string representation of its value is equal to the search string. For example, the IP address 192.0.0.1 matches ~"192.0.0.1", but not ~"192".
If the expression is of type array, each element is checked. The operator matches if at least one of the elements in the array does.
If the expression is of type record, the operator matches if any field name or value matches.
If the expression is of type boolean, timestamp, duration, or binary, the result is always false.
| Expression type | Expression value | Operation | Result | Note |
|---|---|---|---|---|
String |
|
|
| |
String |
|
|
|
|
String |
|
|
| As it’s a string, the field has four tokens. |
IP |
|
|
| Only strings are tokenized. |
IP |
|
|
| The value is auto-converted, so there's an exact match. |
Long |
|
|
| The value is auto-converted, so there's an exact match. |
UID |
|
|
| The value is not tokenized, but can be auto-converted. |
Smartscape ID |
|
|
| The value is auto-converted. |
Smartscape ID |
|
|
| For a Smartscape ID, the check is case-sensitive. |
Smartscape ID |
|
|
| The value isn't tokenized. |
Record |
|
|
| Search also works in nested fields. |
Record |
|
|
| Search also works in the names of nested fields. |
Record |
|
|
|
|
Record |
|
|
| Search also works in the names of nested fields. |
Array |
|
|
| One element of the array is 3, which can be auto-converted to match |
Boolean |
|
|
| Booleans aren't supported. |
Duration |
|
|
| Durations aren't supported. |
The ~ operator searches the pattern in the tokens of a string. Its behavior depends on the data type of the expression on the left side:
string, the result is true if at least one of the tokens matches the pattern.array, the result is true if one of the elements of the array matches the pattern.record, the result is true if the name or value of a nested field matches the pattern.long, double, smartscapeId, IP address, UID, boolean, timestamp, duration, or binary) patterns aren't supported and the result is always false.| Expression type | Expression value | Operation | Result | Note |
|---|---|---|---|---|
String |
|
|
| |
String |
|
|
| |
String |
|
|
| |
String |
|
|
| |
String |
|
|
| |
String |
|
|
| It matches as it's a string and not an IP address. |
Record |
|
|
| The string matches the name of the nested field in the record. |
Record |
|
|
| The string matches the record. |
Array |
|
|
| The string matches within the array. |
IP |
|
|
| Only strings allow patterns. |
Long |
|
|
| Only strings allow patterns. |
Smartscape ID |
|
|
| Only strings allow patterns. |
Boolean |
|
|
| Only strings allow patterns. |
Duration |
|
|
| Only strings allow patterns. |