Boolean and numeric literals in query strings
A literal value is one that is explicitly defined in code rather than computed or derived from other values. In the Deephaven Query Language (DQL), you use literals to define constant values in expressions. This guide covers boolean and numeric literals in query strings.
Query strings use Java syntax for literals, which can differ from Groovy's. For example, an unsuffixed decimal such as 3.14 is a double in a query string but a BigDecimal in Groovy. The engine also departs from Java in a few cases, described under Numeric literals.
Boolean literals
In DQL, there are only two boolean literal values: true and false (lowercase).
The following code uses both boolean literals, then shows the column types with meta:
In sourceMeta, both columns are java.lang.Boolean, the type Deephaven uses for boolean columns.
Numeric literals
Numeric literals in DQL can be integers or floating-point numbers. By default, the engine treats an integer literal as a 32-bit signed integer (Java primitive int) and a floating-point literal as a 64-bit floating-point number (Java primitive double).
Java rejects an integer literal that is too large for an int. The engine makes it a long instead. For a hexadecimal or binary literal, the engine compares the unsigned value with the int maximum, so 0xFFFFFFFF is the long 4294967295, not the int -1 that Java produces.
You can specify the type of a numeric literal by appending a suffix to the number:
Lorlfor a 64-bit signed integer (Java primitivelong).ffor a 32-bit floating-point number (Java primitivefloat). The suffix must be lowercase. With an uppercaseF, as in3.14F, the engine creates adoublecolumn that holds thefloat-rounded value 3.140000104904175.dorDfor a 64-bit floating-point number (Java primitivedouble). This suffix is optional on a literal that already has a decimal point or exponent, sincedoubleis the default there. On a whole number,5dis adouble, while5is anint.
Groovy's G and I suffixes are not valid in DQL. A query string that uses either one fails to compile.
Numeric literals can also be written in these forms:
- Hexadecimal: prefix the digits with
0xor0X, as in0xABCD(43981). - Binary: prefix the digits with
0bor0B, as in0b1010(10). - Octal: start the digits with
0, so0123is the octal number 83, not 123. - Scientific notation: use
eorEfor a decimal exponent, as in1.23e3(1230.0). - Hexadecimal floating point: use
porPfor a binary exponent after0x-prefixed hexadecimal digits, as in0x1.23p3(9.09375). - Underscores: place
_between digits for readability, as in1_000_000. The underscores don't change the value.
The following example constructs a column for each default type, suffix, and form above, then shows the table metadata with meta:
In sourceMeta, each column's type follows the rules above. PromotedLongLiteral and PromotedHexadecimalLiteral have no suffix, but they are long columns because their values are too large for an int. DoubleSuffixLiteral is a double column. In source, PromotedHexadecimalLiteral holds 4294967295 and IntOctalLiteral holds 83.