Arithmetic Functions
Arithmetic expressions perform mathematical computations on numeric values, enabling calculations such as addition, subtraction, multiplication, and division. These expressions are fundamental for data transformation and can be used in various query operations, including projections and filters. Arithmetic operations are defined within the Expression object and can be combined with other expressions to create complex calculations. They support both scalar values and column references, allowing dynamic computations within queries.
Usage
Each arithmetic expression uses:
$fn: the name of the function (e.g."add","divide","least")$operands: a list of expressions to compute with
Functions such as add, subtract, multiply, and divide expect two operands. Functions like least or greatest accept more than two values and evaluate all of them.
Operands can be scalar values, column references, or nested expressions. The $variadic form supports multiple operands for applicable functions.
All operands must be numeric. Some functions like modulo, bitwise operations, or shifts require integer types.
$add
Added in: indicate.dsl.dql@1.0.0
Performs addition on two or more expressions.
{
"$fn": "add",
"$operands": [
{ object (Expression) },
{ object (Expression) },
...
]
}
- JSON
- SQL
{
"$variadic": {
"$fn": "add",
"$operands": [
{
"$qualifier": { "$table": "orders" },
"$identifier": "price"
},
{
"$scalar": 10
}
]
}
}
"orders"."price" + 10
$subtract
Added in: indicate.dsl.dql@1.0.0
Performs subtraction between two or more expressions.
{
"$fn": "subtract",
"$operands": [
{ object (Expression) },
{ object (Expression) },
...
]
}
- JSON
- SQL
{
"$variadic": {
"$fn": "subtract",
"$operands": [
{
"$qualifier": { "$table": "orders" },
"$identifier": "discount"
},
{
"$scalar": 5
}
]
}
}
"orders"."discount" - 5
$multiply
Added in: indicate.dsl.dql@1.0.0
Performs multiplication between two or more expressions.
{
"$fn": "multiply",
"$operands": [
{ object (Expression) },
{ object (Expression) },
...
]
}
- JSON
- SQL
{
"$variadic": {
"$fn": "multiply",
"$operands": [
{
"$qualifier": { "$table": "sales" },
"$identifier": "quantity"
},
{
"$qualifier": { "$table": "sales" },
"$identifier": "price"
}
]
}
}
"sales"."quantity" * "sales"."price"
$divide
Added in: indicate.dsl.dql@1.0.0
Performs division between two or more expressions.
{
"$fn": "divide",
"$operands": [
{ object (Expression) },
{ object (Expression) },
...
]
}
- JSON
- SQL
{
"$variadic": {
"$fn": "divide",
"$operands": [
{
"$qualifier": { "$table": "invoices" },
"$identifier": "total"
},
{
"$qualifier": { "$table": "invoices" },
"$identifier": "count"
}
]
}
}
"invoices"."total" / "invoices"."count"
$modulo
Added in: indicate.dsl.dql@1.0.0
Computes the remainder of a division operation.
{
"$fn": "modulo",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "modulo",
"$left": {
"$qualifier": { "$table": "transactions" },
"$identifier": "amount"
},
"$right": {
"$scalar": 100
}
}
}
"transactions"."amount" % 100
$exponent
Added in: indicate.dsl.dql@1.0.0
Raises the first expression to the power of the second expression.
{
"$fn": "exponent",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "exponent",
"$left": {
"$qualifier": { "$table": "orders" },
"$identifier": "quantity"
},
"$right": {
"$scalar": 2
}
}
}
"orders"."quantity" ^ 2
$least
Added in: indicate.dsl.dql@1.0.0
Returns the smallest value among the given expressions.
{
"$fn": "least",
"$operands": [
{ object (Expression) },
{ object (Expression) },
...
]
}
- JSON
- SQL
{
"$variadic": {
"$fn": "least",
"$operands": [
{
"$qualifier": { "$table": "products" },
"$identifier": "price"
},
{
"$scalar": 10
},
{
"$scalar": 20
}
]
}
}
LEAST("products"."price", 10, 20)
$greatest
Added in: indicate.dsl.dql@1.0.0
Returns the largest value among the given expressions.
{
"$fn": "greatest",
"$operands": [
{ object (Expression) },
{ object (Expression) },
...
]
}
- JSON
- SQL
{
"$variadic": {
"$fn": "greatest",
"$operands": [
{
"$qualifier": { "$table": "products" },
"$identifier": "price"
},
{
"$scalar": 10 },
{
"$scalar": 20
}
]
}
}
GREATEST("products"."price", 10, 20)
$bitwiseAnd
Added in: indicate.dsl.dql@1.0.0
Performs a a binary operation that compares the corresponding bits of two numbers. Returns 1 for each bit position where both operands have a 1. Used to mask bits.
{
"$fn": "bitwiseAnd",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "bitwiseAnd",
"$left": {
"$qualifier": { "$table": "settings" },
"$identifier": "flags"
},
"$right": {
"$scalar": 2
}
}
}
"settings"."flags" & 2
$bitwiseOr
Added in: indicate.dsl.dql@1.0.0
Performs a a binary operation that compares the corresponding bits of two numbers. Returns 1 for each bit position where at least one operand has a 1. Used to set bits.
{
"$fn": "bitwiseOr",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "bitwiseOr",
"$left": {
"$qualifier": { "$table": "settings" },
"$identifier": "flags"
},
"$right": {
"$scalar": 4
}
}
}
"settings"."flags" | 4
$bitwiseXor
Added in: indicate.dsl.dql@1.0.0
Performs a a binary operation that compares the corresponding bits of two numbers. Returns 1 for each bit position where exactly one operand has a 1. Used to toggle bits.
{
"$fn": "bitwiseXor",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "bitwiseXor",
"$left": {
"$qualifier": { "$table": "settings" },
"$identifier": "flags"
},
"$right": {
"$scalar": 8
}
}
}
"settings"."flags" # 8
$shiftLeft
Added in: indicate.dsl.dql@1.0.0
Shifts the bits of a number to the left.
{
"$fn": "shiftLeft",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "shiftLeft",
"$left": {
"$qualifier": { "$table": "settings" },
"$identifier": "flags"
},
"$right": {
"$scalar": 9
}
}
}
"settings"."flags" << 9
$shiftRight
Added in: indicate.dsl.dql@1.0.0
Shifts the bits of a number to the right.
{
"$fn": "shiftRight",
"$operands": [
{ object (Expression) },
{ object (Expression) }
]
}
- JSON
- SQL
{
"$binary": {
"$fn": "shiftRight",
"$left": {
"$qualifier": { "$table": "settings" },
"$identifier": "flags"
},
"$right": {
"$scalar": 3
}
}
}
"settings"."flags" >> 3