Skip to main content
Version: Python

Operators

Operators can be used to construct formulas. Deephaven gives users access to all of Java's operators, including:

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.

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.
+=Addition assignmentAdds the right operand to the left operand and assigns the result to the left operand.
-=Subtraction assignmentSubtracts the right operand from the left operand and assigns the result to the left operand.
++IncrementAdds one to the value of the operand.
--DecrementSubtracts one from the value of the operand.
*=Multiplication assignmentMultiplies the left operand by the right operand and assigns the result to the left operand.
/=Division assignmentDivides the left operand by the right operand and assigns the result to the left operand.
%=Modulus assignmentDivides the left operand by the right operand and assigns the remainder to the left operand.

Logical operators

SymbolNameDescription
!Logical NOTInverts the value of a boolean.
&&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.
&=Bitwise AND assignmentPerforms a bitwise AND on the left and right operands and assigns the result to the left operand.
^=Bitwise XOR assignmentPerforms a bitwise XOR on the left and right operands and assigns the result to the left operand.

Other Java operators

SymbolNameDescription
(type)CastingCasts from one type to another.
()Function callCalls a function.
->Java LambdaDefines a Java lambda 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.

Example

In this example, operators are used with objects 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 this example, comparison operators are used to grab specific integers from a 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"])