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 Not applicable ) 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
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Long
Long
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Double
Double
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
String
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Boolean
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Timestamp
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Duration
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Timeframe
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Geopoint
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
IpAddress
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Not applicable
Not applicable
Binary
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Not applicable
Array
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
Not applicable
Record
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Not applicable
Applicable
V<Integer>
V<Integer>
Applicable
V<Long>
V<Long>
Applicable
V<Double>
V<Double>
Applicable
V<String>
Applicable
V<Boolean>
Applicable
V<Timestamp>
Applicable
V<Duration>
Applicable
V<Timeframe>
Applicable
V<Geopoint>
Applicable
V<IpAddress>
Applicable
V<SummaryStats>
Applicable
V<Binary>
Applicable
V<Array>
Applicable
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)

true

boolean

true

true

string

null

1

long

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)

3

long

null

3.14

double

3.14

3.14

string

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)

127.0.0.1

ip

127.0.0.1

10.0.0.1

string

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)

3

long

3

3.14

double

null

3

string

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)

3

long

3

3.14

double

3.14

3.14

string

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: 2019-08-01T13:30:00.000Zend: 2019-08-01T20:00:00.000Z

timeframe

start: 2019-08-01T13:30:00.000Zend: 2019-08-01T20:00:00.000Z

start: 2023-11-16T10:05:42.927Zend: 2023-11-17T08:05:42.927Z

timeframe

start: 2023-11-16T10:05:42.927Zend: 2023-11-17T08:05:42.927Z

2019-08-01T15:30:00.000-0400/2019-08-01T22:00:00.000-0400

string

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)

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

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)

000000000000007b

null

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 null if the encoding format does not match the outcome format.

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)

RFFMIGlzIGF3ZXNvbWUh

DQL is awesome!

RHluYXRyYWNlIFF1ZXJ5IExhbmd1YWdl

Dynatrace Query Language

Example 2
data record(content = "44514c20697320617765736f6d6521"),
record(content = "44796e617472616365205175657279204c616e6775616765")
| fieldsAdd decodeBase16ToString(content)

Query result:

content

decodeBase16ToString(content)

44514c20697320617765736f6d6521

DQL is awesome!

44796e617472616365205175657279204c616e6775616765

Dynatrace Query Language

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

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)

DQL is awesome!

44514c20697320617765736f6d6521

RFFMIGlzIGF3ZXNvbWUh

Dynatrace Query Language

44796e617472616365205175657279204c616e6775616765

RHluYXRyYWNlIFF1ZXJ5IExhbmd1YWdl

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)

0x7f

127

100

256

0X80000000

2,147,483,648

isUid128

Tests if a uid value is of subtype uid128.

Syntax

isUid128(expression)

Parameters

Parameter

Type

Description

Required

expression

uid

The uid expression that will be checked if it is of subtype uid128.

required

Returns

The data type of the returned value is boolean.

Examples

Example 1
data record(a = uid64(123)),
record(a = toUid("000000000000007c")),
record(a = uid128(123, 456)),
record(a = toUid("000000000000007c00000000000001c8")),
record(a = uuid(123, 456)),
record(a = toUid("00000000-0000-007c-0000-0000000001c8"))
| fieldsAdd isUid128(a)

Query result:

a

isUid128(a)

000000000000007b

false

000000000000007c

false

000000000000007b00000000000001c8

true

000000000000007c00000000000001c8

true

00000000-0000-007b-0000-0000000001c8

false

00000000-0000-007c-0000-0000000001c8

false

isUid64

Tests if a uid value is of subtype uid64.

Syntax

isUid64(expression)

Parameters

Parameter

Type

Description

Required

expression

uid

The uid expression that will be checked if it is of subtype uid64.

required

Returns

The data type of the returned value is boolean.

Examples

Example 1
data record(a = uid64(123)),
record(a = toUid("000000000000007c")),
record(a = uid128(123, 456)),
record(a = toUid("000000000000007c00000000000001c8")),
record(a = uuid(123, 456)),
record(a = toUid("00000000-0000-007c-0000-0000000001c8"))
| fieldsAdd isUid64(a)

Query result:

a

isUid64(a)

000000000000007b

true

000000000000007c

true

000000000000007b00000000000001c8

false

000000000000007c00000000000001c8

false

00000000-0000-007b-0000-0000000001c8

false

00000000-0000-007c-0000-0000000001c8

false

isUuid

Tests if a uid value is of subtype uuid.

Syntax

isUuid(expression)

Parameters

Parameter

Type

Description

Required

expression

uid

The uid expression that will be checked if it is of subtype uuid.

required

Returns

The data type of the returned value is boolean.

Examples

Example 1
data record(a = uid64(123)),
record(a = toUid("000000000000007c")),
record(a = uid128(123, 456)),
record(a = toUid("000000000000007c00000000000001c8")),
record(a = uuid(123, 456)),
record(a = toUid("00000000-0000-007c-0000-0000000001c8"))
| fieldsAdd isUuid(a)

Query result:

a

isUuid(a)

000000000000007b

false

000000000000007c

false

000000000000007b00000000000001c8

false

000000000000007c00000000000001c8

false

00000000-0000-007b-0000-0000000001c8

true

00000000-0000-007c-0000-0000000001c8

true

numberToHexString

Converts a number to a hexadecimal string.

Syntax

numberToHexString(expression)

Parameters

Parameter

Type

Description

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)

127

7f

256

100

2,147,483,648

80000000

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)

[2, 3, 7, 7, 1]

array

[2, 3, 7, 7, 1]

DQL is awesome!

string

[DQL is awesome!]

3.14

double

[3.14]

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)

true

boolean

true

true

string

true

yes

string

null

0

long

false

1

long

true

2

long

true

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)

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

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)

15 s

duration

15 s

3.14

double

3 ns

start: 2019-08-01T13:30:00.000Zend: 2019-08-01T20:00:00.000Z

timeframe

6.5 h

42

string

42 ns

42s

string

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)

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

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)

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

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)

[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.724Zend: 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"}

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: 2019-08-01T13:30:00.000Zend: 2019-08-01T20:00:00.000Z

timeframe

start: 2019-08-01T13:30:00.000Zend: 2019-08-01T20:00:00.000Z

start: 2023-11-16T10:05:43.784Zend: 2023-11-17T08:05:43.784Z

timeframe

start: 2023-11-16T10:05:43.784Zend: 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.000Zend: 2019-08-01T20:00:00.000Z

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)

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

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 array, the element at position 0 is converted.

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)

550e8400-e29b-41d4-a716-446655440000

000000000000007bt

00000000000001c8

000000000000007b

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)

[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.967Zend: 2023-11-17T10:05:43.967Z

timeframe

2019-08-01T13:30:00.000Z

timestamp

content: A nested record

record

uid128

Creates a uid of subtype uid128 from two long expressions.

Syntax

uid128(mostSignificantBits, leastSignificantBits)

Parameters

Parameter

Type

Description

Required

mostSignificantBits

long

The first long expression for the most significant bits of a uid128.

required

leastSignificantBits

long

The second long expression for the least significant bits of a uid128.

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)

000000000000007b00000000000001c8

uid64

Creates a uid of subtype uid64 from a long expression.

Syntax

uid64(expression)

Parameters

Parameter

Type

Description

Required

expression

long

The long expression for a uid64.

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)

000000000000007b

uuid

Creates a uid of subtype uuid from two long expressions.

Syntax

uuid(mostSignificantBits, leastSignificantBits)

Parameters

Parameter

Type

Description

Required

mostSignificantBits

long

The first long expression for the most significant bits of a uuid.

required

leastSignificantBits

long

The second long expression for the least significant bits of a uuid.

required

Returns

The data type of the returned value is uid.

Examples

Example 1
data record(a = 123, b = 456)
| fields uuid(a, b)

Query result:

uuid(a, b)

00000000-0000-007b-0000-0000000001c8