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
Symbol | Name | Description |
---|---|---|
+ | Addition | Adds values. |
- | Subtraction | Subtracts the right value from the left value. |
* | Multiplication | Multiplies the left and right values. |
/ | Division | Divides the left value by the right value. |
% | Modulus | Divides the left value by the right value and returns the remainder. |
Access operators
Symbol | Name | Description |
---|---|---|
_ | Underscore | Accesses an array of all values within the column. |
[] | Index | Indexes array elements. |
. | Dot | Accesses members of a package or a class. |
Note
The _
operator is Deephaven-specific; it is not part of standard Java syntax.
Comparison operators
Symbol | Name | Description |
---|---|---|
== | Equal to | Compares two values to see if they are equal. |
!= | Not equal to | Compares two values to see if they are not equal. |
> | Greater than | Compares two values to see if the left value is greater than the right value. |
>= | Greater than or equal | Compares two values to see if the left value is greater than or equal to the right value. |
< | Less than | Compares two values to see if the left value is less than the right value. |
<= | Less than or equal | Compares two values to see if the left value is less than or equal to the right value. |
Assignment operators
Symbol | Name | Description |
---|---|---|
= | Assignment | Assigns a value to a variable. |
Logical operators
Symbol | Name | Description |
---|---|---|
! | Logical NOT | Inverts the value of a boolean. |
& | Bitwise AND | Performs a bitwise AND operation. |
| | Bitwise OR | Performs a bitwise OR operation. |
&& | Logical AND | Returns true if both operands are true . |
|| | Logical OR | Returns true if either operand is true . |
Bitwise operators
Symbol | Name | Description |
---|---|---|
~ | Bitwise complement | A unary operator that "flips" bits. |
& | Bitwise AND | Compares 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 shift | The left operand's value is shifted left by the number of bits set by the right operand. |
>> | Right shift | The left operand's value is shifted right by the number of bits set by the right operand. |
^ | Bitwise XOR | Compares 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
Symbol | Name | Description |
---|---|---|
(type) | Casting | Casts from one type to another. |
() | Function call | Calls a function. |
?: | Ternary conditional | Returns one of two values depending on the value of a boolean expression. |
instanceof | Instance of | Returns true if the object is an instance of the class. |