String functions
String functions allow you to create expressions that manipulate text strings in a variety of ways.
All string matching functions are case-sensitive per default. If otherwise required, the caseSensitive
parameter provides the ability to change the behavior.
1...2| fieldsAdd str_found = contains(content, "FlushCommand", caseSensitive:false)
concat
Concatenates the expressions into a single string.
-
Syntax
concat(expression, …)
-
Parameters
Name Type Mandatory Default Constraints Description expression
double, long, string
yes
A numeric or string expressions that should be concatenated with others.
-
Example
1data record(a = "DQL", b = "is awesome!")2| fieldsAdd concat(a, " ", b)Query result
a b concat(a, " ", b) DQL
is awesome!
DQL is awesome!
contains
Searches the string expression for a substring. Returns true
if the substring was found, false
otherwise.
-
Syntax
contains(expression, substring [, caseSensitive])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The field or expression to check.
substring
string
yes
The substring that should be contained.
-
Example
In this example, we add a field that checks if field
content
contains theFlushCommand
string.1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd contains(content, "DQL"),4 contains(content, "dql", caseSensitive: false),5 contains(content, "Query")Query result
content contains(content, "DQL") contains(content, "dql", caseSensitive:FALSE) contains(content, "Query") DQL is awesome!
true
true
false
Dynatrace Query Language
false
false
true
decodeUrl
Returns a URL-decoded string.
-
Syntax
decodeUrl(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression that will be decoded.
-
Example
1data record(content = "https%3A%2F%2Fwww.dynatrace.com%2Fplatform%2Fgrail"),2 record(content = "https://www.dynatrace.com/platform/grail")3| fieldsAdd decodeUrl(content)Query result
content decodeUrl(content) https%3A%2F%2Fwww.dynatrace.com%2Fplatform%2Fgrail
https://www.dynatrace.com/platform/grail
https://www.dynatrace.com/platform/grail
https://www.dynatrace.com/platform/grail
encodeUrl
Encodes a URL string by replacing characters that aren't numbers or letters with percentage symbols and hexadecimal numbers.
-
Syntax
encodeUrl(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression that will be encoded.
-
Example
1data record(content = "https://www.dynatrace.com/platform/grail")2| fieldsAdd encodeUrl(content)Query result
content encodeUrl(content) https://www.dynatrace.com/platform/grail
https%3A%2F%2Fwww.dynatrace.com%2Fplatform%2Fgrail
endsWith
Checks if a string expression ends with a suffix. Returns true
if does, false
otherwise.
-
Syntax
endsWith(expression, suffix [, caseSensitive])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression that will be checked.
suffix
string
yes
The suffix string with which the expression should end.
caseSensitive
boolean
no
Whether the check should be done in a case-sensitive way.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd endsWith(content, "awesome!"),4 endsWith(content, "AWESOME!", caseSensitive: false),5 endsWith(content, "Language")Query result
content endsWith(content, "awesome!") endsWith(content, "AWESOME!", caseSensitive:FALSE) endsWith(content, "Language") DQL is awesome!
true
true
false
Dynatrace Query Language
false
false
true
getCharacter
Returns the character at a given position from a string expression. Negative values for the position parameter are counted from the end of the string. If a position refers to a position outside the string, the function returns NULL.
-
Syntax
getCharacter(expression, position)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
position
long
yes
The position at which to get the character.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd getCharacter(content, 1),4 getCharacter(content, 17),5 getCharacter(content, -1)Query result
content getCharacter(content, 1) getCharacter(content, 17) getCharacter(content, -1) DQL is awesome!
Q
null
!
Dynatrace Query Language
y
a
e
indexOf
Returns the index of the first occurrence of a substring in a string expression.
Starts to search forward from a given index. Negative values for the from
parameter are counted from the end of the string.
The default value for from
is 0
(the search from the start of the string).
The search is case-sensitive.
If the defined substring is not found, the function returns -1
.
-
Syntax
indexOf(expression, substring [, from])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression in which the substring is searched for.
substring
string
yes
The substring expression to search for in the expression.
from
long
yes
The index from which to start the forward search for the first occurrence of the substring within the expression. Negative values are counted from the end of the string.
-
Example
In this example, we search for the first occurrence of an
ab
substring in theababcd
expression. The count starts from1
.1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd indexOf(content, "a"),4 indexOf(content, "a", from: 10),5 indexOf(content, "Query")Query result
content indexOf(content, "a") indexOf(content, "a", from:10) indexOf(content, "Query") DQL is awesome!
7
-1
-1
Dynatrace Query Language
3
17
10
lastIndexOf
Returns the index of the last occurrence of a substring in a string expression. Starts to search backward from a given index. Negative values for the from parameter are counted from the end of the string. The default value for from is -1 (search from the end of the string). The search is case-sensitive. If the substring is not found, the function returns -1
.
-
Syntax
lastIndexOf(expression, substring [, from])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression in which the substring is searched for.
substring
string
yes
The substring expression to search for in the expression.
from
long
no
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd lastIndexOf(content, "a"),4 lastIndexOf(content, "a", from: 10),5 lastIndexOf(content, "Query")Query result
content lastIndexOf(content, "a") lastIndexOf(content, "a", from:10) lastIndexOf(content, "Query") DQL is awesome!
7
7
-1
Dynatrace Query Language
21
6
10
levenshteinDistance
Computes the Levenshtein distance between two input strings.
-
Syntax
levenshteinDistance(expression, expression)
-
Parameters
Name Type Mandatory Default Constraints Description first expression
string
yes
The first string expression to compute the Levenshtein distance from.
second
string
yes
The second string expression to compute the Levenshtein distance from.
-
Example
1data record(a = "DQL is awesome!", b = "Grail is awesome!"),2 record(a = "Dynatrace Query Language", b = "DQL"),3 record(a = "Dynatrace Query Language", b = "dynatrace query language")4| fieldsAdd levenshteinDistance(a, b)Query result
a b levenshteinDistance(a, b) DQL is awesome!
Grail is awesome!
5
Dynatrace Query Language
DQL
21
Dynatrace Query Language
dynatrace query language
3
like
Tests if a string expression matches a pattern. If the pattern does not contain percent signs, like()
acts as the ==
operator (equality check). A percent character in the pattern (%)
matches any sequence of zero or more characters. An underscore in the pattern (\_)
matches a single character.
-
Syntax
like(expression, pattern)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
pattern
string
yes
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd like(content, "%DQL%"),4 like(content, "D%L%"),5 like(content, "D_L%")Query result
content like(content, "%DQL%") like(content, "D%L%") like(content, "D_L%") DQL is awesome!
true
true
true
Dynatrace Query Language
false
true
false
lower
Converts a string to lowercase.
-
Syntax
lower(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression to convert to lowercase.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd lower(content)Query result
content lower(content) DQL is awesome!
dql is awesome!
Dynatrace Query Language
dynatrace query language
matchesPhrase
Matches a phrase against the input string expression using token matchers.
-
Syntax
matchesPhrase(<fieldName>, <string>, [caseSensitive])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string, array
yes
The expression (string or array of strings) that should be checked.
phrase
string
yes
The phrase to search for.
caseSensitive
boolean
no
false
Whether the match should be done case-sensitive.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language"),3 record(content = array("DQL", "is", "awesome", "!", "Dynatrace Query Language"))4| fieldsAdd matchesPhrase(content, "DQL"),5 matchesPhrase(content, "Dyna"),6 matchesPhrase(content, "query"),7 matchesPhrase(content, "query", caseSensitive: true)Query result
content matchesPhrase(content, "DQL") matchesPhrase(content, "Dyna") matchesPhrase(content, "query") matchesPhrase(content, "query", caseSensitive:TRUE) DQL is awesome!
true
false
false
false
Dynatrace Query Language
false
false
true
false
[DQL, is, awesome, !, Dynatrace Query Language]
true
false
true
false
matchesValue
Searches records for a specific value in a given attribute. Returns true
or false
.
-
Syntax
matchesValue(expression, value [, caseSensitive])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string, array
yes
The expression (string or array of strings) that should be checked.
value
string
yes
The value to search for using patterns.
caseSensitive"=
boolean
no
false
Whether the match should be done case-sensitive
-
Example 1
Values are matched case-insensitive by default:
1data record(content = "User 'käärmanü' failed to login from 192.168.0.1")2| fieldsAdd matchesValue(content, "User*"),3 matchesValue(content, "user*"),4 matchesValue(content, "user*", caseSensitive: true)Query result
content matchesValue(content, "User*") matchesValue(content, "user*") matchesValue(content, "user*", caseSensitive:TRUE) User 'käärmanü' failed to login from 192.168.0.1
true
true
false
-
Example 2
Values are matched from the beginning. To match parts of the value, use
*
as wildcard symbol:1data record(content = "User 'käärmanü' failed to login from 192.168.0.1")2| fieldsAdd matchesValue(content, "192.168.0.1"),3 matchesValue(content, "*192.168.0.1"),4 matchesValue(content, "*failed to log*")Query result
content matchesValue(content, "192.168.0.1") matchesValue(content, "*192.168.0.1") matchesValue(content, "*failed to log*") User 'käärmanü' failed to login from 192.168.0.1
false
true
true
-
Example 3
Only ASCII characters are matched case-insensitive:
1data record(content = "Österreich")2| fieldsAdd matchesValue(content, "österreich"),3 matchesValue(content, "Österreich")Query result
content matchesValue(content, "österreich") matchesValue(content, "Österreich") Österreich
false
true
-
Example 4
The function handles values of arrays in "any-match" manner.
1data record(technologies = array("Java11", "java17"))2| fieldsAdd matchesValue(technologies, "Java11"),3 matchesValue(technologies, "java"),4 matchesValue(technologies, "java*")Query result
technologies matchesValue(technologies, "Java11") matchesValue(technologies, "java") matchesValue(technologies, "java*") [Java11, java17]
true
false
true
punctuation
Extracts punctuation characters out of an input string.
-
Syntax
punctuation(expression, [, count] [, withSpace])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression from which the punctuation characters are extracted.
count
positive integer
no
32
The maximum number of returned punctuation characters.
withSpace
boolean
no
false
Whether space characters should be included.
-
Example
In this example, we extract the punctuation characters from each input string.
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language"),3 record(content = "${placeholder}")4| fieldsAdd punctuation(content),5 punctuation(content, count: 2),6 punctuation(content, count: 2, withSpace: true)Query result
content punctuation(content) punctuation(content, count:2) punctuation(content, count:2, withSpace:TRUE) DQL is awesome!
!
!
__
Dynatrace Query Language
empty string
empty string
__
${placeholder}
${}
${
${
replaceString
Replaces each substring of a string with a given string. This function replaces only exactly matched substrings from the original string to the replacement. Matching is case-sensitive and doesn't use any wildcards. All found patterns will be replaced if they do not intersect. For instance, replacing abcabca
in a string with abca
pattern produces only one replacement. Only the first occurrence at the beginning of the string will be replaced.
-
Syntax
replaceString(expression, substring, replacement)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The field or expression where substrings should be replaced.
substring
string
yes
The substring that should be replaced.
replacement
string
yes
The string that should replace the found substrings.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language"),3 record(content = "abcabca")4| fieldsAdd replaceString(content, "awesome", "simple"),5 replaceString(content, "abca", "xyz")Query result
content replaceString(content, "awesome", "simple") replaceString(content, "abca", "xyz") DQL is awesome!
DQL is simple!
DQL is awesome!
Dynatrace Query Language
Dynatrace Query Language
Dynatrace Query Language
abcabca
abcabca
xyzbca
splitString
Splits a string according to the parameters set.
Retrieves an array of substrings of the specified expression that are adjacent to occurrences of the given pattern.
Parameters are interpreted literally. For example, splitting www.dynatrace.org
by .
results in www
and dynatrace
and org
.
Using an empty string as a pattern splits the string into one-byte substrings. For example, a split of four characters becomes an array of four strings having one byte each (splitting the "1234"
expression results in array("1", "2", "3", "4")
).
The non-ASCII characters are represented by multiple bytes. Splitting a string containing such characters by ""
breaks these bytes apart into separate invalid strings.
If the pattern is not found in the expression, it returns an array that contains only the input expression.
If the expression starts with one or more occurrences of the pattern, an empty string will be added for each occurrence. For example, split("abc", "a")
results in "", "bc"
. Analogically, empty strings are added if the pattern is found at the end of the expression.
An empty string is also added for adjacent occurrences of the pattern that do not border the start or end of the string. For example, split("abbc", "b")
results in "a", "", "c"
.
If the pattern is empty, it splits the expression into one-byte substrings. For example, split("abc", "")
results in "a", "b", "c"
.
-
Syntax
splitString(expression, pattern)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression to split up into an array.
pattern
string
yes
The pattern to split the string expression at, or the empty string to split into one-byte strings.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd splitString(content, " "),4 splitString(content, "is"),5 splitString(content, ""),6 splitString(content, "XYZ")Query result
content splitString(content, " ") splitString(content, "is") splitString(content, "") splitString(content, "XYZ") DQL is awesome!
[DQL, is, awesome!]
[DQL , awesome!]
[D, Q, L, , i, s, , a, w, e, s, o, m, e, !]
[DQL is awesome!]
Dynatrace Query Language
[Dynatrace, Query, Language]
[Dynatrace Query Language]
[D, y, n, a, t, r, a, c, e, , Q, u, e, r, y, , L, a, n, g, u, a, g, e]
[Dynatrace Query Language]
startsWith
Checks if a string expression starts with a prefix. Returns true
if does, false
otherwise.
-
Syntax
startsWith(expression, prefix [, caseSensitive])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression that will be checked.
prefix
string
yes
The prefix string with which the expression should start.
caseSensitive
boolean
no
Whether the check should be done in a case-sensitive way.
-
Example
In this example, we test the
logs on Grail
string to see if it begins with thelog
string or theGrail
string. The results are displayed in thestr1_start
andstr2_start
fields.1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd startsWith(content, "D"),4 startsWith(content, "dql", caseSensitive: false)Query result
content startsWith(content, "D") startsWith(content, "dql", caseSensitive:FALSE) DQL is awesome!
true
true
Dynatrace Query Language
true
false
stringLength
Returns the length of a string expression. Length is defined as the number of UTF-16 code units, which is often the same as the number of characters in the string. In some cases, the number of characters is smaller than the number of UTF-16 code units, for example when Combining Diacritical Marks are used, or if characters outside the Basic Multilingual Plane (BMP), such as Emoji, are present.
If your use case requires consistent length for the same characters, consider ingesting strings after Unicode normalization.
No specific normalization form is guaranteed for Dynatrace-provided strings.
-
Syntax
stringLength(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression to get the number of UTF-16 code units for.
-
Example
In this example, we return the length of the
content
field in logs, sorted from shortest to longest log lines.1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language"),3 record(content = "🐕🦺")4| fieldsAdd stringLength(content)Query result
content stringLength(content) DQL is awesome!
15
Dynatrace Query Language
24
🐕🦺
5
substring
Gets a code unit range using a start index (inclusive) and an end index (exclusive).
Returns an empty string if from >=
to.
Indexes >=0
are relative to the start of the string and address consecutive characters from left to right, starting from the index position.
Indexes <=-1
are relative to the last character of the string and are used to address characters from the right side of an expression, for example, -2
is the penultimate character.
Positive indexes
beyond the bounds of the string are assigned to the string length.
Negative indexes
beyond the bounds of the string are equal to 0
. For example, in the 321
string, the index -4
is beyond the bounds of the string therefore it equals 0
. However, the index -2
is located within the bounds of that string and extracts 21
if used as a from
the index.
The returned substring never starts or ends with an incomplete UTF-16 surrogate pair. Instead of that, it starts or ends with a question mark. This safeguards against the creation of invalid Unicode strings.
-
Syntax
substring(expression [, from] [, to])
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression to get a substring of.
from
long
no
Index of first code unit to include in sub-string, inclusive, relative to start of
expression
if positive, relative to end if negative. Clamped at string bounds.to
long
no
Index of last code unit to include in sub-string, exclusive, relative to start of
expression
if positive, relative to end if negative. Clamped at string bounds. -
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd substring(content, from: 4),4 substring(content, from: -2),5 substring(content, from: 4, to: 9),6 substring(content, from: -42, to: 42)Query result
content substring(content, from:4) substring(content, from:-2) substring(content, from:4, to:9) substring(content, from:-42, to:42) DQL is awesome!
is awesome!
e!
is aw
DQL is awesome!
Dynatrace Query Language
trace Query Language
ge
trace
Dynatrace Query Language
trim
Removes leading and trailing whitespaces. Any code point <= ASCII 32 in decimal is considered a whitespace, where ASCII 32 is a blank space.
-
Syntax
trim(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression to remove leading and trailing white-space from.
-
Example
1data record(content = " DQL is awesome!"),2 record(content = " Dynatrace Query Language ")3| fieldsAdd trim(content)Query result
content trim(content) " DQL is awesome!"
DQL is awesome!
" Dynatrace Query Language "
Dynatrace Query Language
unescapeHtml
Unescapes HTML in a string by replacing ASCII characters with HTML syntax.
-
Syntax
unescapeHtml(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression that will be unescaped.
-
Example
1data record(content = "DQL is <bold>awesome</bold>!"),2 record(content = "<a href="https://www.dynatrace.com/platform/grail">Dynatrace Query Language</a>")3| fieldsAdd unescapeHtml(content)Query result
content unescapeHtml(content) DQL is <bold>awesome</bold>!
DQL is <bold>awesome</bold>!
<a href="https://www.dynatrace.com/platform/grail">Dynatrace Query Language</a>
<a href="https://www.dynatrace.com/platform/grail">Dynatrace Query Language</a>
upper
Converts a string to uppercase.
-
Syntax
upper(expression)
-
Parameters
Name Type Mandatory Default Constraints Description expression
string
yes
The string expression to convert to uppercase.
-
Example
1data record(content = "DQL is awesome!"),2 record(content = "Dynatrace Query Language")3| fieldsAdd upper(content)Query result
content upper(content) DQL is awesome!
DQL IS AWESOME!
Dynatrace Query Language
DYNATRACE QUERY LANGUAGE