Conversion functions convert the expression or value from one data type to another type.
Functions prefixed with as(Type)
ensure that a value is of a target type. If the data type is incompatible, they return null
. These functions are applicable after parsing.
...| parse content, "LD'DQL 'KVP{LD:key'='(LONG:valueLong| BOOLEAN:valueBoolean| [!;]*:valueStr)';'?}:q"| fields timestamp, asLong(q[workTime])
The as*T
will try to cast the input to T
but won't perform any conversions, it will cause an exception for strongly typed fields (marked as ) and null for incompatible data types (empty cell).
asT(arg) => if(typeOf(arg) == ’T’, arg)
Integer
Integer
Long
Long
Double
Double
String
Boolean
Timestamp
Duration
Timeframe
Geopoint
IpAddress
Binary
Array
Record
V<Integer>
V<Integer>
V<Long>
V<Long>
V<Double>
V<Double>
V<String>
V<Boolean>
V<Timestamp>
V<Duration>
V<Timeframe>
V<Geopoint>
V<IpAddress>
V<SummaryStats>
V<Binary>
V<Array>
V<Record>
V<Record>
Returns array value if the value is array
, otherwise, returns null
.
asArray(value)
Parameter
Type
Description
Required
value
array
required
The data type of the returned value is array
.
data record(a = array(2, 3, 7, 7, 1)),record(a = "DQL is awesome!"),record(a = 3.14)| fieldsAdd type(a), asArray(a)
Query result:
[2, 3, 7, 7, 1]
array
[2, 3, 7, 7, 1]
DQL is awesome!
string
3.14
double
Returns binary value (byte array) if the value is binary
, otherwise, returns null
.
asBinary(value)
Parameter
Type
Description
Required
value
binary
required
The data type of the returned value is binary
.
data record(a = 3.14),record(a = "dynatrace"),record(a = true),record(a = decodeBase64ToBinary("ZHluYXRyYWNl"))| fieldsAdd type(a), asBinary(a)
Query result:
3.14
double
dynatrace
string
true
boolean
ZHluYXRyYWNl
binary
ZHluYXRyYWNl
Returns boolean value if the value is boolean
, otherwise, returns null
.
asBoolean(value)
Parameter
Type
Description
Required
value
boolean
required
The data type of the returned value is boolean
.
data record(a = true),record(a = "true"),record(a = 1)| fieldsAdd type(a), asBoolean(a)
Query result:
a
type(a)
asBoolean(a)
true
boolean
true
true
string
null
1
long
null
Returns double
value if the value is double
, otherwise, returns null
.
asDouble(value)
Parameter
Type
Description
Required
value
double
required
The data type of the returned value is double
.
data record(a = 3),record(a = 3.14),record(a = "3.14")| fieldsAdd type(a), asDouble(a)
Query result:
a
type(a)
asDouble(a)
3
long
null
3.14
double
3.14
3.14
string
null
Returns duration value if the value is duration
, otherwise, returns null
.
asDuration(value)
Parameter
Type
Description
Required
value
duration
required
The data type of the returned value is duration
.
data record(a = 15s),record(a = 3.14),record(a = timeframe(from: "2019-08-01T09:30:00.000-0400", to: "2019-08-01T16:00:00.000-0400")),record(a = "42"),record(a = "42s")| fieldsAdd type(a), asDuration(a)
Query result:
15 s
duration
15 s
3.14
double
2019-08-01T13:30:00.000Z
2019-08-01T20:00:00.000Z
timeframe
42
string
42s
string
You can use this function to cast to an IP address.
asIp(expression)
Parameter
Type
Description
Required
expression
string expression, ip address
The expression to cast an expression to an IP address.
required
The data type of the returned value is ip
.
data record(a = ip("127.0.0.1")),record(a = "10.0.0.1")| fieldsAdd type(a), asIp(a)
Query result:
a
type(a)
asIp(a)
127.0.0.1
ip
127.0.0.1
10.0.0.1
string
null
Returns long
value if the value is long
, otherwise null
.
asLong(value)
Parameter
Type
Description
Required
value
long
required
The data type of the returned value is long
.
data record(a = 3),record(a = 3.14),record(a = "3")| fieldsAdd type(a), asLong(a)
Query result:
a
type(a)
asLong(a)
3
long
3
3.14
double
null
3
string
null
Returns the same value if the value is integer
, long
, double
, otherwise, returns null
.
asNumber(value)
Parameter
Type
Description
Required
value
double, long
required
The data type of the returned value is double
or long
.
data record(a = 3),record(a = 3.14),record(a = "3.14")| fieldsAdd type(a), asNumber(a)
Query result:
a
type(a)
asNumber(a)
3
long
3
3.14
double
3.14
3.14
string
null
Returns record value if the value is record
, otherwise, returns null
.
asRecord(value)
Parameter
Type
Description
Required
value
record
required
The data type of the returned value is record
.
data record(a = record(b = 3)),record(a = 3.14),record(a = "3"),record(a = array(2, 3, 7, 7, 1))| fieldsAdd type(a), asRecord(a)
Query result:
3
record
3
3.14
double
3
string
[2, 3, 7, 7, 1]
array
Returns string value if the value is string
, otherwise, returns null
.
asString(value)
Parameter
Type
Description
Required
value
string
required
The data type of the returned value is string
.
data record(a = array(1, 2, 3)),record(a = 3.14),record(a = "DQL is awesome!"),record(a = record(content = "A nested record"))| fieldsAdd type(a), asString(a)
Query result:
[1, 2, 3]
array
3.14
double
DQL is awesome!
string
DQL is awesome!
A nested record
record
Returns timeframe
value if the value is timeframe
, otherwise returns null
.
asTimeframe(value)
Parameter
Type
Description
Required
value
timeframe
required
The data type of the returned value is timeframe
.
data record(timeframe = timeframe(from: "2019-08-01T09:30:00.000-0400", to: "2019-08-01T16:00:00.000-0400")),record(timeframe = timeframe(from: - 24h, to: - 2h)),record(timeframe = "2019-08-01T15:30:00.000-0400/2019-08-01T22:00:00.000-0400")| fieldsAdd type(timeframe), asTimeframe(timeframe)
Query result:
timeframe
type(timeframe)
asTimeframe(timeframe)
start: 2019-08-01T13:30:00.000Z
end: 2019-08-01T20:00:00.000Z
timeframe
start: 2019-08-01T13:30:00.000Z
end: 2019-08-01T20:00:00.000Z
start: 2023-11-16T10:05:42.927Z
end: 2023-11-17T08:05:42.927Z
timeframe
start: 2023-11-16T10:05:42.927Z
end: 2023-11-17T08:05:42.927Z
2019-08-01T15:30:00.000-0400/2019-08-01T22:00:00.000-0400
string
null
Returns timestamp
value if the value is timestamp
, otherwise, returns null
.
asTimestamp(value)
Parameter
Type
Description
Required
value
timestamp
required
The data type of the returned value is timestamp
.
data record(timestamp = timestamp(2019, 8, 1, 13, 30, 0)),record(timestamp = 1564666200000000000),record(timestamp = "2019-08-01T09:30:00.000-0400")| fieldsAdd type(timestamp), asTimestamp(timestamp)
Query result:
timestamp
type(timestamp)
asTimestamp(timestamp)
2019-08-01T13:30:00.000Z
timestamp
2019-08-01T13:30:00.000Z
1,564,666,200,000,000,000
long
null
2019-08-01T09:30:00.000-0400
string
null
Returns a uid
value if the value is uid
, otherwise returns null
.
asUid(value)
Parameter
Type
Description
Required
value
uid
The value to cast.
required
The data type of the returned value is uid
.
data record(a = uid64(123)), record(a = 123)| fields asUid(a)
Query result:
asUid(a)
asUid(a)
000000000000007b
null
The decode function allows encoding binary data and strings into a string representation, and the opposite way. There are two types of decode functions, BASE64 and BASE16.
decodeBase64ToBinary(expression)
decodeBase64ToString(expression)
decodeBase16ToBinary(expression)
decodeBase16ToString(expression)
Parameter
Type
Description
Required
expression
string
An encoded string that needs to be decoded to a plain string or binary. Retrieves null
if the encoding format does not match the outcome format.
required
The data type of the returned value is binary
or string
.
data record(content = "RFFMIGlzIGF3ZXNvbWUh"),record(content = "RHluYXRyYWNlIFF1ZXJ5IExhbmd1YWdl")| fieldsAdd decodeBase64ToString(content)
Query result:
content
decodeBase64ToString(content)
RFFMIGlzIGF3ZXNvbWUh
DQL is awesome!
RHluYXRyYWNlIFF1ZXJ5IExhbmd1YWdl
Dynatrace Query Language
data record(content = "44514c20697320617765736f6d6521"),record(content = "44796e617472616365205175657279204c616e6775616765")| fieldsAdd decodeBase16ToString(content)
Query result:
content
decodeBase16ToString(content)
44514c20697320617765736f6d6521
DQL is awesome!
44796e617472616365205175657279204c616e6775616765
Dynatrace Query Language
The encode function allows encoding binary data and strings into a string representation, and the opposite way. There are two types of encode functions, BASE64 and BASE16.
Parameter
Type
Description
Required
expression
string, binary
A string or binary expression to encode.
required
The data type of the returned value is string
.
data record(content = "DQL is awesome!"),record(content = "Dynatrace Query Language")| fieldsAdd encodeBase16(content),encodeBase64(content)
Query result:
content
encodeBase16(content)
encodeBase64(content)
DQL is awesome!
44514c20697320617765736f6d6521
RFFMIGlzIGF3ZXNvbWUh
Dynatrace Query Language
44796e617472616365205175657279204c616e6775616765
RHluYXRyYWNlIFF1ZXJ5IExhbmd1YWdl
Converts a hexadecimal string to a number.
hexStringToNumber(expression)
Parameter
Type
Description
Required
expression
string expression
The string expression that will be converted to a number.
required
The data type of the returned value is double
or long
.
data record(a = "0x7f"),record(a = "100"),record(a = "0X80000000")| fieldsAdd hexStringToNumber(a)
Query result:
a
hexStringToNumber(a)
0x7f
127
100
256
0X80000000
2,147,483,648
Converts a number to a hexadecimal string.
numberToHexString(expression)
Parameter
Type
Descriptiont
Required
expression
numeric expression
The numeric expression that will be converted to a hexadecimal string.
required
The data type of the returned value is string
.
data record(a = 127),record(a = 256),record(a = 2147483648)| fieldsAdd numberToHexString(a)
Query result:
a
numberToHexString(a)
127
7f
256
100
2,147,483,648
80000000
Returns the value if it is an array
. Otherwise, converts a value to the single element array holding that value.
toArray(value)
Parameter
Type
Description
Required
value
array, boolean, double, duration, ip, long, record, string, timeframe, timestamp
required
The data type of the returned value is array
.
data record(a = array(2, 3, 7, 7, 1)),record(a = "DQL is awesome!"),record(a = 3.14)| fieldsAdd type(a), toArray(a)
Query result:
a
type(a)
toArray(a)
[2, 3, 7, 7, 1]
array
[2, 3, 7, 7, 1]
DQL is awesome!
string
[DQL is awesome!]
3.14
double
[3.14]
Converts a value to Boolean if the value is of a suitable type. If the argument is an array, the element at position 0 is converted.
Use asBoolean(value)
function to return if the value is boolean
or variant<boolean>
, otherwise null
.
Converts string values true
or TRUE
to a Boolean true
.The comparison is case insensitive. Converts other values to Boolean false
. Converts numeric value 0 to Boolean false
. Converts other numeric values to Boolean true
.
toBoolean(value)
Parameter
Type
Description
Required
value
boolean, double, long, string, array
required
The data type of the returned value is boolean
.
data record(a = true),record(a = "true"),record(a = "yes"),record(a = 0),record(a = 1),record(a = 2)| fieldsAdd type(a), toBoolean(a)
Query result:
a
type(a)
toBoolean(a)
true
boolean
true
true
string
true
yes
string
null
0
long
false
1
long
true
2
long
true
Converts a value to double
if the value is of a suitable type. If the argument is an array
, the element at position 0 is converted.
Use asDouble(value)
function to return if the value is double
or variant<double>
, otherwise null
.
toDouble(value)
Parameter
Type
Description
Required
value
double, long, string, boolean, ip, timestamp, duration, array
required
The data type of the returned value is double
.
data record(a = 3),record(a = 3.14),record(a = "3.14"),record(a = true),record(a = toTimestamp("2019-08-01T09:30:00.000-0400")),record(a = 15s),record(a = ip("10.0.0.1"))| fieldsAdd type(a), toDouble(a)
Query result:
a
type(a)
toDouble(a)
3
long
3
3.14
double
3.14
3.14
string
3.14
true
boolean
1
2019-08-01T13:30:00.000Z
timestamp
1,564,666,200,000,000,000
15 s
duration
15,000,000,000
10.0.0.1
ip
167,772,161
Converts a value to duration
if the value is of a suitable type. If the argument is an array
, the element at position 0 is converted.
toDuration(value)
Parameter
Type
Description
Required
value
duration, double, long, string, timeframe, array
required
The data type of the returned value is duration
.
data record(a = 15s),record(a = 3.14),record(a = timeframe(from: "2019-08-01T09:30:00.000-0400", to: "2019-08-01T16:00:00.000-0400")),record(a = "42"),record(a = "42s")| fieldsAdd type(a), toDuration(a)
Query result:
a
type(a)
toDuration(a)
15 s
duration
15 s
3.14
double
3 ns
start: 2019-08-01T13:30:00.000Z
end: 2019-08-01T20:00:00.000Z
timeframe
6.5 h
42
string
42 ns
42s
string
null
You can use this function to convert an expression to an IP address.
toIp(expression)
Parameter
Type
Description
Required
expression
string expression, ip address
The expression to convert an expression to an IP address.
required
The data type of the returned value is ip
.
data record(a = ip("127.0.0.1")),record(a = "10.0.0.1"),record(a = "300.0.0.1"),record(a = 1234567890)| fieldsAdd type(a), toIp(a)
Query result:
a
type(a)
toIp(a)
127.0.0.1
ip
127.0.0.1
10.0.0.1
string
10.0.0.1
300.0.0.1
string
null
1,234,567,890
long
73.150.2.210
Converts a value to long
if the value is of a suitable type. If the argument is an array
, the element at position 0 is converted.
toLong(value)
Parameter
Type
Description
Required
value
long, double, string, boolean, ip, timestamp, duration, array
required
The data type of the returned value is long
.
data record(a = 3),record(a = 3.14),record(a = "3"),record(a = true),record(a = false),record(a = ip("10.0.0.1")),record(a = 15s),record(a = toTimestamp("2019-08-01T09:30:00.000-0400"))| fieldsAdd type(a), toLong(a)
Query result:
a
type(a)
toLong(a)
3
long
3
3.14
double
3
3
string
3
true
boolean
1
false
boolean
0
10.0.0.1
ip
167,772,161
15 s
duration
15,000,000,000
2019-08-01T13:30:00.000Z
timestamp
1,564,666,200,000,000,000
Returns the string representation of a value.
toString(value)
Parameter
Type
Description
Required
value
double, boolean, timestamp, timeframe, duration, ip, array, record
Parameter that should be transformed into text form.
required
The data type of the returned value is string
.
data record(a = array(1, 2, 3)),record(a = true),record(a = 3),record(a = 3.14),record(a = 5m),record(a = toIp("127.0.0.1")),record(a = "DQL is awesome!"),record(a = timeframe(from: now() - 5m, to: now())),record(a = toTimestamp("2019-08-01T09:30:00.000-0400")),record(a = record(content = "A nested record"))| fieldsAdd type(a), toString(a)
Query result:
a
type(a)
toString(a)
[1, 2, 3]
array
[1, 2, 3]
true
boolean
true
3
long
3
3.14
double
3.14
5 min
duration
"05:00.000000000"
127.0.0.1
ip
"127.0.0.1"
DQL is awesome!
string
DQL is awesome!
start: 2023-11-17T10:00:43.724Z
end: 2023-11-17T10:05:43.724Z
timeframe
"2023-11-17T10:00:43.724031180 +0000/2023-11-17T10:05:43.724031180 +0000"
2019-08-01T13:30:00.000Z
timestamp
"2019-08-01T13:30:00.000000000 +0000"
content: A nested record
record
{"content":"A nested record"}
Converts a value to timeframe
if the value is of a suitable type. If the argument is an array
, the element at position 0 is converted.
toTimeframe(value)
Parameter
Type
Description
Required
value
timeframe, string, array
required
The data type of the returned value is timeframe
.
data record(timeframe = timeframe(from: "2019-08-01T09:30:00.000-0400", to: "2019-08-01T16:00:00.000-0400")),record(timeframe = timeframe(from: - 24h, to: - 2h)),record(timeframe = "2019-08-01T09:30:00.000-0400/2019-08-01T16:00:00.000-0400")| fieldsAdd type(timeframe), toTimeframe(timeframe)
Query result:
timeframe
type(timeframe)
toTimeframe(timeframe)
start: 2019-08-01T13:30:00.000Z
end: 2019-08-01T20:00:00.000Z
timeframe
start: 2019-08-01T13:30:00.000Z
end: 2019-08-01T20:00:00.000Z
start: 2023-11-16T10:05:43.784Z
end: 2023-11-17T08:05:43.784Z
timeframe
start: 2023-11-16T10:05:43.784Z
end: 2023-11-17T08:05:43.784Z
2019-08-01T09:30:00.000-0400/2019-08-01T16:00:00.000-0400
string
start: 2019-08-01T13:30:00.000Z
end: 2019-08-01T20:00:00.000Z
Converts a value to timestamp
if the value is of a suitable type. If the argument is an ARRAY, the element at position 0 is converted.
Use asTimestamp(<value>)
function to return if the value is timestamp
or variant<timestamp>
, otherwise null
.
toTimestamp(value)
Parameter
Type
Description
Required
value
timestamp, double, long , string, array
required
The data type of the returned value is timestamp
.
data record(timestamp = toTimestamp("2019-08-01T09:30:00.000-0400")),record(timestamp = 1564666200000000000),record(timestamp = "2019-08-01T09:30:00.000-0400")| fieldsAdd type(timestamp), toTimestamp(timestamp)
Query result:
timestamp
type(timestamp)
toTimestamp(timestamp)
2019-08-01T13:30:00.000Z
timestamp
2019-08-01T13:30:00.000Z
1,564,666,200,000,000,000
long
2019-08-01T13:30:00.000Z
2019-08-01T09:30:00.000-0400
string
2019-08-01T13:30:00.000Z
Converts a value to uid
if the value is of a suitable type.
toUid(value)
Parameter
Type
Description
Required
value
number, string, uid, array
Any convertible value. If the argument is an array
, the element at position 0 is converted.
required
The data type of the returned value is uid
.
data record(a = "550e8400-e29b-41d4-a716-446655440000", b = 123, c = uid64(456), d=array(123))| fields toUid(a), toUid(b), toUid(c), toUid(d)
Query result:
toUid(a)
toUid(b)
toUid(c)
toUid(d)
550e8400-e29b-41d4-a716-446655440000
000000000000007bt
00000000000001c8
000000000000007b
Returns the type of a value as a string
.
type(expression)
Parameter
Type
Description
Required
expression
array, boolean, double, duration, ip, long, record, string, timeframe, timestamp
required
The data type of the returned value is string
.
data record(a = array(1, 2, 3)),record(a = true),record(a = 3),record(a = 3.14),record(a = 5m),record(a = toIp("127.0.0.1")),record(a = "DQL is awesome!"),record(a = timeframe(from: now() - 5m, to: now())),record(a = toTimestamp("2019-08-01T09:30:00.000-0400")),record(a = record(content = "A nested record"))| fieldsAdd type(a)
Query result:
a
type(a)
[1, 2, 3]
array
true
boolean
3
long
3.14
double
5 min
duration
127.0.0.1
ip
DQL is awesome!
string
start: 2023-11-17T10:00:43.967Z
end: 2023-11-17T10:05:43.967Z
timeframe
2019-08-01T13:30:00.000Z
timestamp
content: A nested record
record
Creates a uid
from the given two long expressions.
uid128(firstExpression, secondExpression)
Parameter
Type
Description
Required
expression
long
The first long expression for a uid.
required
expression
long
The second long expression for a uid.
required
The data type of the returned value is uid
.
data record(a = 123, b = 456)| fields uid128(a, b)
Query result:
uid128(a, b)
000000000000007b00000000000001c8
Creates a uid
from the given long expression.
uid64(expression)
Parameter
Type
Description
Required
expression
long
The long expression for a uid.
required
The data type of the returned value is uid
.
data record(a = 123)| fields uid64(a)
Query result:
uid64(a)
000000000000007b