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.
i
is a row index, as a primitive int.ii
is a row index, as a primitive long.k
is a Deephaven internal indexing value, as a primitive long.
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.
k
does not correspond to traditional row numbers and should only be used in limited circumstances, such as debugging or advanced query operations.
These variables are unreliable within a ticking table. Inconsistent results occur since previously created row indexes do not automatically update.
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.
result = emptyTable(10).update("I = i", "II = ii", "K = k")
meta = result.meta()
- result
- meta
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.
Because i
and ii
are used, this example will not reliably work on dynamic tables.
source = emptyTable(10).update("X = i")
result = source.update("A = X_[i-1]", "B = X_[i+1]", "C = X_[i+2]", "D = sqrt(X_[i-1] + X_[i+1])")
- source
- result
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
.