Special variables and constants
Deephaven provides special variables and constants to increase ease of access to row indexes and save users time when writing queries.
Special variables
Special variables inside the query language allow access to the row index of a table.
iis a row index, as a primitive int.iiis a row index, as a primitive long.kis a Deephaven internal indexing value, as a primitive long.
Note
The variables i and ii both represent row numbers. Integers are limited to values up to 2^31-1 (2,147,483,647), while longs can represent values up to 2^63-1. In other words, to avoid precision problems, use the ii variable, unless an int needs to be passed to another function. Using the i variable in a table with more than 2 billion rows will result in an error.
[!WARNING] >
kdoes not correspond to traditional row numbers and should only be used in limited circumstances, such as debugging or advanced query operations.
Refreshing table restrictions
The engine validates usage of these variables and throws an IllegalArgumentException if used unsafely on refreshing tables:
The following table summarizes when each variable is safe to use:
| Variable | Safe on | Throws error on |
|---|---|---|
i, ii | static, append-only, blink | add-only, ticking |
k | static, add-only, blink | append-only, ticking |
Simple constant offset (Column_[i-1]) | all tables | — |
Complex array expressions (Column_[(i)-1]) | static, blink | any refreshing table |
Note
The engine detects simple constant offset array access patterns like Column_[i-1] and handles them correctly on all table types. However, semantically equivalent but syntactically different expressions like Column_[(i)-1] are not recognized and will throw an error on refreshing tables.
For refreshing tables where you need more complex positional access, see Alternatives for refreshing tables.
Row numbers i and ii are frequently used with the _ and [] operators to retrieve values from prior or future rows in the table. For example, Column_[ii-1] references the value in Column one row prior to the current row.
Examples
In the following example, a table is created with the row index as an i int, ii long and k long. The meta-data is assessed to see the variable types.
In the following example, row indices, i and ii, are used to access the rows before and after the current row in the table by using the _ and [] operators.
Caution
Because i and ii are used, this example will not reliably work on dynamic tables. On other refreshing tables, the engine throws an IllegalArgumentException.
Constants
The deephaven.util.QueryConstants class defines the global constants including Deephaven’s special numerical values. Other constants are defined at the individual module level because they are only locally applicable.
Deephaven provides the following global constants:
MAX_BYTE: The maximum value of typebyte.MAX_CHAR: The maximum value of typechar.MAX_DOUBLE: The maximum value of typedouble.MAX_FINITE_DOUBLE: The maximum finite value of typedouble.MAX_FINITE_FLOAT: The maximum finite value of typefloat.MAX_FLOAT: The maximum value of typefloat.MAX_INT: The maximum value of typeint.MAX_LONG: The maximum value of typelong.MAX_SHORT: The maximum value of typeshort.MIN_BYTE: The minimum value of typebyte.MIN_CHAR: The minimum value of typechar.MIN_DOUBLE: The minimum value of typedouble.MIN_FINITE_DOUBLE: The minimum finite value of typedouble.MIN_FINITE_FLOAT: The minimum finite value of typefloat.MIN_FLOAT: The minimum value of typefloat.MIN_INT: The minimum value of typeint.MIN_LONG: The minimum value of typelong.MIN_POS_DOUBLE: The minimum positive value of typedouble.MIN_POS_FLOAT: The minimum positive value of typefloat.MIN_SHORT: The minimum value of typeshort.NAN_DOUBLE: Not-a-number (NaN) value of typedouble.NAN_FLOAT: Not-a-number (NaN) value of typefloat.NEG_INFINITY_DOUBLE: Negative infinity value of typedouble.NEG_INFINITY_FLOAT: Negative infinity value of typefloat.NULL_BOOLEAN: Null value of typebool.NULL_BYTE: Null value of typebyte.NULL_BYTE_BOXED: Null boxed value of typebyte.NULL_CHAR: Null value of typechar.NULL_CHAR_BOXED: Null boxed value of typechar.NULL_DOUBLE: Null value of typedouble.NULL_DOUBLE_BOXED: Null boxed value of typedouble.NULL_FLOAT: Null value of typefloat.NULL_FLOAT_BOXED: Null boxed value of typefloat.NULL_INT: Null value of typeint.NULL_INT_BOXED: Null boxed value of typeint.NULL_LONG: Null value of typelong.NULL_LONG_BOXED: Null boxed value of typelong.NULL_SHORT: Null value of typeshort.NULL_SHORT_BOXED: Null boxed value of typeshort.POS_INFINITY_DOUBLE: Positive infinity value of typedouble.POS_INFINITY_FLOAT: Positive infinity value of typefloat.