Conversion and casting functions
Conversion functions convert the expression or value from one data type to another type.
Converting data types
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)
as*T | asNumber | asInteger | asLong | asDouble | asString | asBoolean | asTimestamp | asDuration | asTimeframe | asGeopoint | asIpAddress | asSummaryStats | asBinary | asArray | asRecord |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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> |
asArray
Returns array value if the value is array
, otherwise, returns null
.
Syntax
asArray(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | array | required |
Returns
The data type of the returned value is array
.
Examples
Example 1
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:
a | type(a) | asArray(a) |
---|---|---|
[2, 3, 7, 7, 1] | array | [2, 3, 7, 7, 1] |
DQL is awesome! | string | null |
3.14 | double | null |
asBinary
Returns binary value (byte array) if the value is binary
, otherwise, returns null
.
Syntax
asBinary(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | binary | required |
Returns
The data type of the returned value is binary
.
Examples
Example 1
data record(a = 3.14),record(a = "dynatrace"),record(a = true),record(a = decodeBase64ToBinary("ZHluYXRyYWNl"))| fieldsAdd type(a), asBinary(a)
Query result:
a | type(a) | asBinary(a) |
---|---|---|
3.14 | double | null |
dynatrace | string | null |
true | boolean | null |
ZHluYXRyYWNl | binary | ZHluYXRyYWNl |
asBoolean
Returns boolean value if the value is boolean
, otherwise, returns null
.
Syntax
asBoolean(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | boolean | required |
Returns
The data type of the returned value is boolean
.
Examples
Example 1
data record(a = true),record(a = "true"),record(a = 1)| fieldsAdd type(a), asBoolean(a)
Query result:
a | type(a) | asBoolean(a) |
---|---|---|
|
|
|
|
| null |
|
| null |
asDouble
Returns double
value if the value is double
, otherwise, returns null
.
Syntax
asDouble(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | double | required |
Returns
The data type of the returned value is double
.
Examples
Example 1
data record(a = 3),record(a = 3.14),record(a = "3.14")| fieldsAdd type(a), asDouble(a)
Query result:
a | type(a) | asDouble(a) |
---|---|---|
|
| null |
|
|
|
|
| null |
asDuration
Returns duration value if the value is duration
, otherwise, returns null
.
Syntax
asDuration(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | duration | required |
Returns
The data type of the returned value is duration
.
Examples
Example 1
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:
a | type(a) | asDuration(a) |
---|---|---|
15 s | duration | 15 s |
3.14 | double | null |
start: 2019-08-01T13:30:00.000Z end: 2019-08-01T20:00:00.000Z | timeframe | null |
42 | string | null |
42s | string | null |
asIp
You can use this function to cast to an IP address.
Syntax
asIp(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | string expression, ip address | The expression to cast an expression to an IP address. | required |
Returns
The data type of the returned value is ip
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
| null |
asLong
Returns long
value if the value is long
, otherwise null
.
Syntax
asLong(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | long | required |
Returns
The data type of the returned value is long
.
Examples
Example 1
data record(a = 3),record(a = 3.14),record(a = "3")| fieldsAdd type(a), asLong(a)
Query result:
a | type(a) | asLong(a) |
---|---|---|
|
|
|
|
| null |
|
| null |
asNumber
Returns the same value if the value is integer
, long
, double
, otherwise, returns null
.
Syntax
asNumber(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | double, long | required |
Returns
The data type of the returned value is double
or long
.
Examples
Example 1
data record(a = 3),record(a = 3.14),record(a = "3.14")| fieldsAdd type(a), asNumber(a)
Query result:
a | type(a) | asNumber(a) |
---|---|---|
|
|
|
|
|
|
|
| null |
asRecord
Returns record value if the value is record
, otherwise, returns null
.
Syntax
asRecord(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | record | required |
Returns
The data type of the returned value is record
.
Examples
Example 1
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:
a | type(a) | asRecord(a) |
---|---|---|
b: 3 | record | b: 3 |
3.14 | double | null |
3 | string | null |
[2, 3, 7, 7, 1] | array | null |
asString
Returns string value if the value is string
, otherwise, returns null
.
Syntax
asString(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | string | required |
Returns
The data type of the returned value is string
.
Examples
Example 1
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:
a | type(a) | asString(a) |
---|---|---|
[1, 2, 3] | array | null |
3.14 | double | null |
DQL is awesome! | string | DQL is awesome! |
content: A nested record | record | null |
asTimeframe
Returns timeframe
value if the value is timeframe
, otherwise returns null
.
Syntax
asTimeframe(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | timeframe | required |
Returns
The data type of the returned value is timeframe
.
Examples
Example 1
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: |
| start: |
start: |
| start: |
|
| null |
asTimestamp
Returns timestamp
value if the value is timestamp
, otherwise, returns null
.
Syntax
asTimestamp(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | timestamp | required |
Returns
The data type of the returned value is timestamp
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
| null |
|
| null |
asUid
Returns a uid
value if the value is uid
, otherwise returns null
.
Syntax
asUid(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | uid | The value to cast. | required |
Returns
The data type of the returned value is uid
.
Examples
Example 1
data record(a = uid64(123)), record(a = 123)| fields asUid(a)
Query result:
asUid(a) | asUid(a) |
---|---|
|
|
decode
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.
Syntax
decodeBase64ToBinary(expression)
decodeBase64ToString(expression)
decodeBase16ToBinary(expression)
decodeBase16ToString(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | string | An encoded string that needs to be decoded to a plain string or binary. Retrieves | required |
Returns
The data type of the returned value is binary
or string
.
Examples
Example 1
data record(content = "RFFMIGlzIGF3ZXNvbWUh"),record(content = "RHluYXRyYWNlIFF1ZXJ5IExhbmd1YWdl")| fieldsAdd decodeBase64ToString(content)
Query result:
content | decodeBase64ToString(content) |
---|---|
|
|
|
|
Example 2
data record(content = "44514c20697320617765736f6d6521"),record(content = "44796e617472616365205175657279204c616e6775616765")| fieldsAdd decodeBase16ToString(content)
Query result:
content | decodeBase16ToString(content) |
---|---|
|
|
|
|
encode
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.
Syntax
encodeBase64(expression)
encodeBase16(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | string, binary | A string or binary expression to encode. | required |
Returns
The data type of the returned value is string
.
Examples
Example 1
data record(content = "DQL is awesome!"),record(content = "Dynatrace Query Language")| fieldsAdd encodeBase16(content),encodeBase64(content)
Query result:
content | encodeBase16(content) | encodeBase64(content) |
---|---|---|
|
|
|
|
|
|
hexStringToNumber
Converts a hexadecimal string to a number.
Syntax
hexStringToNumber(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | string expression | The string expression that will be converted to a number. | required |
Returns
The data type of the returned value is double
or long
.
Examples
Example 1
data record(a = "0x7f"),record(a = "100"),record(a = "0X80000000")| fieldsAdd hexStringToNumber(a)
Query result:
a | hexStringToNumber(a) |
---|---|
|
|
|
|
|
|
numberToHexString
Converts a number to a hexadecimal string.
Syntax
numberToHexString(expression)
Parameters
Parameter | Type | Descriptiont | Required |
---|---|---|---|
expression | numeric expression | The numeric expression that will be converted to a hexadecimal string. | required |
Returns
The data type of the returned value is string
.
Examples
Example 1
data record(a = 127),record(a = 256),record(a = 2147483648)| fieldsAdd numberToHexString(a)
Query result:
a | numberToHexString(a) |
---|---|
|
|
|
|
|
|
toArray
Returns the value if it is an array
. Otherwise, converts a value to the single element array holding that value.
Syntax
toArray(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | array, boolean, double, duration, ip, long, record, string, timeframe, timestamp | required |
Returns
The data type of the returned value is array
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
|
|
toBoolean
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
.
Syntax
toBoolean(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | boolean, double, long, string, array | required |
Returns
The data type of the returned value is boolean
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
| null |
|
|
|
|
|
|
|
|
|
toDouble
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
.
Syntax
toDouble(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | double, long, string, boolean, ip, timestamp, duration, array | required |
Returns
The data type of the returned value is double
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toDuration
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.
Syntax
toDuration(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | duration, double, long, string, timeframe, array | required |
Returns
The data type of the returned value is duration
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
start: |
|
|
|
|
|
|
| null |
toIp
You can use this function to convert an expression to an IP address.
Syntax
toIp(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | string expression, ip address | The expression to convert an expression to an IP address. | required |
Returns
The data type of the returned value is ip
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
| null |
|
|
|
toLong
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.
Syntax
toLong(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | long, double, string, boolean, ip, timestamp, duration, array | required |
Returns
The data type of the returned value is long
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toString
Returns the string representation of a value.
Syntax
toString(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | double, boolean, timestamp, timeframe, duration, ip, array, record | Parameter that should be transformed into text form. | required |
Returns
The data type of the returned value is string
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start: |
|
|
|
|
|
content: |
|
|
toTimeframe
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.
Syntax
toTimeframe(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | timeframe, string, array | required |
Returns
The data type of the returned value is timeframe
.
Examples
Example 1
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: |
| start: |
start: |
| start: |
|
| start: |
toTimestamp
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
.
Syntax
toTimestamp(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | timestamp, double, long , string, array | required |
Returns
The data type of the returned value is timestamp
.
Examples
Example 1
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) |
---|---|---|
|
|
|
|
|
|
|
|
|
toUid
Converts a value to uid
if the value is of a suitable type.
Syntax
toUid(value)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
value | number, string, uid, array | Any convertible value. If the argument is an | required |
Returns
The data type of the returned value is uid
.
Examples
Example 1
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) |
---|---|---|---|
|
|
|
|
type
Returns the type of a value as a string
.
Syntax
type(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | array, boolean, double, duration, ip, long, record, string, timeframe, timestamp | required |
Returns
The data type of the returned value is string
.
Examples
Example 1
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) |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start: |
|
|
|
content: |
|
uid128
Creates a uid
from the given two long expressions.
Syntax
uid128(firstExpression, secondExpression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | long | The first long expression for a uid. | required |
expression | long | The second long expression for a uid. | required |
Returns
The data type of the returned value is uid
.
Examples
Example 1
data record(a = 123, b = 456)| fields uid128(a, b)
Query result:
uid128(a, b) |
---|
|
uid64
Creates a uid
from the given long expression.
Syntax
uid64(expression)
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
expression | long | The long expression for a uid. | required |
Returns
The data type of the returned value is uid
.
Examples
Example 1
data record(a = 123)| fields uid64(a)
Query result:
uid64(a) |
---|
|