Strings
A String is a sequence of characters, such as letters, numbers, or symbols, that is treated as a single data type. Strings frequently contain words or text. Deephaven queries use strings ubiquitously. The Deephaven engine uses java.lang.String
.
Java strings in queries
String columns in Deephaven tables are stored as java.lang.String
objects. This provides three powerful ways to manipulate text in query strings:
- Native Java string methods (like
length
,substring
, etc.) - Deephaven's built-in string functions
- String-specific operators (such as
+
for concatenation)
String concatenation
java.lang.String
objects can be concatenated with the +
operator:
source = emptyTable(1).update("StrCol1 = `Hello, `", "StrCol2 = `Deephaven!`", "StrCol3 = StrCol1 + StrCol2")
sourceMeta = source.meta()
String methods
java.lang.String
methods can be called from query strings and can yield very powerful queries:
source = emptyTable(1).update(
"StrCol1 = `Learning `",
"StrCol2 = `about `",
"StrCol3 = ` strings.`",
"StrCol4 = StrCol1 + StrCol2 + StrCol3"
)
result = source.update(
"IndexOfSubstring = StrCol4.indexOf(`ings.`)",
"StringIsEmpty = StrCol2.isEmpty()",
"Substring = StrCol4.substring(4, 14)",
"UpperCase = StrCol1.toUpperCase()",
"LowerCase = StrCol3.toLowerCase()"
)
String filtering
A common use of string methods is for string filtering:
source = newTable(
stringCol("X", "Aa", "Ba", "Bb", "Ca", "Bc", "Ab", "Bd", "Be", "Cb")
)
result = source.where("X.startsWith(`C`)")
Built-in functions
Many built-in functions work with strings. For instance, you can parse the numeric values in strings:
source = emptyTable(1).update(
"StringInt = `4`",
"StringFloat = `4.5`",
"StringDouble = `3.14159`",
"StringBool = `true`",
)
result = source.update(
"Int = parseInt(StringInt)",
"Float = parseFloat(StringFloat)",
"Double = parseDouble(StringDouble)",
"Bool = parseBoolean(StringBool)",
)
resultMeta = result.meta()