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. It converts Python strings for you, so your Python string variables work in queries with no extra steps.
This guide shows how to use Python strings and Java strings in query strings.
Python strings in queries
You can use Python string variables in query strings directly. The engine converts them to java.lang.String objects.
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 my_str. The source_meta table, from meta_table, lists each column's name and type. Its DataType column shows java.lang.String:
Python functions that return strings work too, as long as they have a str return type hint. The hint tells the engine to make a String column:
Without the hint, the column doesn't hold strings. It holds PyObject or java.lang.Object values instead.
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, just as it concatenates Python strings:
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. Because the column holds java.lang.String values, use Java method names such as toUpperCase, not Python ones such as upper:
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:
result_meta 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
- Python variables in query strings
- Python functions in query strings
- Handle PyObjects in tables
- Java objects and classes in query strings
- Built-in query language functions
- Filters
- Formulas
- Operators
- Strings
empty_tablenew_tablestring_colupdatewheremeta_table- Parse functions
empty_tablePydocnew_tablePydocstring_colPydocupdatePydocwherePydocmeta_tablePydoc