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:

  • L or l for a 64-bit signed integer (Java primitive long).
  • f for a 32-bit floating-point number (Java primitive float). The suffix must be lowercase. With an uppercase F, as in 3.14F, the engine creates a double column that holds the float-rounded value 3.140000104904175.
  • d or D for a 64-bit floating-point number (Java primitive double). This suffix is optional on a literal that already has a decimal point or exponent, since double is the default there. On a whole number, 5d is a double, while 5 is an int.

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 0x or 0X, as in 0xABCD (43981).
  • Binary: prefix the digits with 0b or 0B, as in 0b1010 (10).
  • Octal: start the digits with 0, so 0123 is the octal number 83, not 123.
  • Scientific notation: use e or E for a decimal exponent, as in 1.23e3 (1230.0).
  • Hexadecimal floating point: use p or P for a binary exponent after 0x-prefixed hexadecimal digits, as in 0x1.23p3 (9.09375).
  • Underscores: place _ between digits for readability, as in 1_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.