Operators

An operator is a symbol, like + or -, that tells a program to perform a specific action on values or variables. Operators can be used to construct filters and formulas. Deephaven provides access to most of Java's operators. A complete list of supported operators is provided below.

The following code block uses a variety of operators to create new columns of values.

from deephaven import empty_table


class MyObj:
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

    def compute(self, value1):
        return self.a + value1


obj = MyObj(1, 2, 3)

result = empty_table(10).update(
    formulas=[
        "A = i",
        "B = A * A",
        "C = A / 2",
        "D = A % 3",
        "E = (int)C",
        "F = A_[i-2]",
        "G = obj.a",
        "H = obj.compute(A)",
        "I = sqrt(A)",
    ]
)

In the example below, comparison operators are used to filter data from the source table.

from deephaven import new_table
from deephaven.column import int_col

source = new_table([int_col("Value", [0, 1, 2, 3, 4, 5, 6])])

greater_than = source.where(filters=["Value > 3"])
greater_than_or_equal = source.where(filters=["Value >= 3"])
less_than = source.where(filters=["Value < 3"])
less_than_or_equal = source.where(filters=["Value <= 3"])

Available operators

There are many operators available in the Deephaven Query Language (DQL). They are organized by category in the subsections below.

Arithmetic operators

SymbolNameDescription
+AdditionAdds values.
-SubtractionSubtracts the right value from the left value.
*MultiplicationMultiplies the left and right values.
/DivisionDivides the left value by the right value.
%ModulusDivides the left value by the right value and returns the remainder.

Access operators

SymbolNameDescription
_UnderscoreAccesses an array of all values within the column.
[]IndexIndexes array elements.
.DotAccesses members of a package or a class.

Note

The _ operator is Deephaven-specific; it is not part of standard Java syntax.

Comparison operators

SymbolNameDescription
==Equal toCompares two values to see if they are equal.
!=Not equal toCompares two values to see if they are not equal.
>Greater thanCompares two values to see if the left value is greater than the right value.
>=Greater than or equalCompares two values to see if the left value is greater than or equal to the right value.
<Less thanCompares two values to see if the left value is less than the right value.
<=Less than or equalCompares two values to see if the left value is less than or equal to the right value.

Assignment operators

SymbolNameDescription
=AssignmentAssigns a value to a variable.

Logical operators

SymbolNameDescription
!Logical NOTInverts the value of a boolean.
&Bitwise ANDPerforms a bitwise AND operation.
|Bitwise ORPerforms a bitwise OR operation.
&&Logical ANDReturns true if both operands are true.
||Logical ORReturns true if either operand is true.

Bitwise operators

SymbolNameDescription
~Bitwise complementA unary operator that "flips" bits.
&Bitwise ANDCompares each bit of the first operand to the corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.
<<Left shiftThe left operand's value is shifted left by the number of bits set by the right operand.
>>Right shiftThe left operand's value is shifted right by the number of bits set by the right operand.
^Bitwise XORCompares each bit of the first operand to the corresponding bit of the second operand. If the bits are different, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Other Java operators

SymbolNameDescription
(type)CastingCasts from one type to another.
()Function callCalls a function.
?:Ternary conditionalReturns one of two values depending on the value of a boolean expression.
instanceofInstance ofReturns true if the object is an instance of the class.