Strings
A string is a sequence of characters, such as letters, numbers, or symbols, that a program handles as a single value. Deephaven queries use strings for column values, filters, and formulas.
The Deephaven engine represents strings as java.lang.String. This guide shows how to use Groovy strings and Java strings in query strings.
Groovy strings in queries
You can use Groovy string variables in query strings directly. A Groovy string literal such as "Deephaven!" is already a java.lang.String, so the resulting column is a java.lang.String column.
Inside a query string, a string literal usually goes between backticks, which avoids escaping double quotes.
Let's add the literal `Hello, ` to the variable myStr. The sourceMeta table, from meta, lists each column's name and type. Its DataType column shows java.lang.String:
An interpolated string such as "Hello ${name}" is a Groovy GString, not a java.lang.String. In a query string, it makes a GStringImpl column. A match filter such as "S = myStr" on a String column then finds no rows and raises no error. To get a String, call toString on it when you assign it, for example myStr = "Hello ${name}".toString().
You can also call Groovy closures that return strings from query strings. The engine sees every closure call as returning Object, so cast the result to String to get a String column:
Java strings in queries
Deephaven stores string columns as java.lang.String objects, so you work with them in query strings the way Java does:
- String concatenation with the
+operator, which concatenates when either operand is a string - Native
java.lang.Stringmethods, such asindexOfandsubstring - Deephaven's built-in functions that work with strings
String concatenation
The + operator concatenates java.lang.String objects:
String methods
You can call java.lang.String methods directly from query strings to search, slice, and change the case of text without leaving the query:
In Learning about strings., the text ings. starts at index 18, so IndexOfSubstring is 18. Substring is ning about, the characters from index 4 up to but not including index 14.
String filtering
A common use of string methods is string filtering:
result keeps only the rows whose X value starts with C: Ca and Cb.
Built-in functions
Many built-in functions work with strings. For instance, the parse functions convert strings to numeric and boolean values:
resultMeta shows that Int is an int column, Float a float column, Double a double column, and Bool a java.lang.Boolean column.
Related documentation
- Filter table data
- Create static tables
- An overview of query strings
- String and char literals in query strings
- Groovy variables in query strings
- Groovy closures in queries
- Casting
- Java objects and classes in query strings
- Built-in query language functions
- Filters
- Formulas
- Operators
- Strings
emptyTablenewTablestringColupdatewheremeta- Parse functions
emptyTableJavadocnewTableJavadocstringColJavadocupdateJavadocwhereJavadocmetaJavadoc