Skip to content

Build-in Operators

Aggregating Functions

Aggregating function
What it does
Sum= x, += xSummation of all x
Min= xMinimum of all x
Max= xMaximum of all x
StringAgg= xA comma-separated concatenation of all x's. Also can be used to define concatenations via other symbol: JoinWithDash(x) = StringAgg(x "-"); JoinWithDash will join the x's with a dash.
ArgMin= x -> yOne of x's corresponding to the smallest y
ArgMax= x -> yOne of x's corresponding to the largest y
Count= xApproximate count of the number of distinct x.
List= xAn array of all x's.
Set= xAn array of all distinct x's.
ArgMaxK(x -> y, k)A list of length k containing x's corresponding to largest y's. To be used via defining an auxiliary aggregating function like: ArgMax5(a) = ArgMaxK(a, 5); And then use ArgMax5= x -> y.
ArgMinK(x -> y, k)A list of length k containing x's corresponding to smallest y's.
Array= x -> yAn array of all y's sorted by corresponding x.
Avg= xAverage over values of x.
1= xOne (arbitrary) value from what x runs over. This is useful for left joins.

String Manipulation Functions

Function
What it does
x ++ yConcatenation of x and y
Substr(s, i, l)Substring of s starting at position i of length l. Position starts from 1.
Length(s)Length of string s.
Join(l, c)String join of elements of l interleaved with c. E.g., Join(["a", "b", "c"], "-") == "a-b-c"
Split(s, c)Splits the string s on separator c into an array of string components. E.g., Split("a-b-c", "-") = ["a", "b", "c"]
Like(s, p)Boolean answering whether string s matches pattern p. Corresponds to SQL’s s LIKE p. Pattern p allows % wildcard matching any string.
Upper(s)Turns s into upper case.

Array Manipulation Functions

FunctionWhat it does
Size(a)Length of the array a.
Element(a, i)Element of a at index i. Indices start with 0.
ArrayConcat(a, b)Concatenation of arrays a and b.

Type Casting Functions

FunctionWhat it does
ToInt64(x)Casts x to an integer number.
ToFloat64(x)Casts x to a float number.
ToString(x)Casts x to a string.

Mathematical Functions

FunctionWhat it does
Exp(x)Exponent of x.
Sin(x)Sin of x.
Cos(x)Cos of x.
Log(x)Natural logarithm of x.

Some Other Functions

Function
What it does
IsNull(x)Boolean answering whether x is null.
Constraint(x)A proposition that x is a boolean which is true. Use it in the body of the predicate to filter on a boolean variable or boolean function value. E.g., Q(x, y) :- T(x, y, z), Constraint(z), Constraint(F(x)); Here z is a boolean column and F is a boolean function.
Constraint(x in l)Boolean value that checks that x is an element of a list l.
Range(n)An array of natural numbers from 0 to n - 1.
SqlExpr(s, r)Compiles to an SQL expression equal to Python’s s.format(r) where record r is interpreted as a dictionary.