8. Function & Operators¶
8.1. Aggregate functions¶
QuasarDB supports many server-side operations that can be applied on timeseries data. Below is an overview of the functions available and the value types they can operator on.
Calculations performed using these functions are distributed over the cluster, and many of them are vectorized. Since 3.0.0 QuasarDB uses light-weight indexes to speed up lookups and computations where possible.
Operation
Description
Input value
Return value
Complexity
Vectorized
Basic operations
firstFirst element
Any
Any
Constant
No
lastLast element
Any
Any
Constant
No
minMinimum value
Double, int64
Double, int64
Linear
Yes
maxMaximum value
Double, int64
Double, int64
Linear
Yes
countNumber of elements
Any
Int64
Constant
No
sumSum of values
Double, int64
Double, int64
Linear
Yes
Averages
avgArithmetic mean
Double, int64
Double, int64
Linear
Yes
arithmetic_meanArithmetic mean
Double, int64
Double, int64
Linear
Yes
harmonic_meanHarmonic mean
Double, int64
Double, int64
Linear
No
geometric_meanGeometric mean
Double, int64
Double, int64
Linear
No
maMoving average
Double, int64
Double, int64
Linear
No
moving_averageMoving average
Double, int64
Double, int64
Linear
No
quadratic_meanQuadratic mean
Double, int64
Double, int64
Linear
No
Statistics
distinct_countNumber of distinct elements
Any
Int64
Linear
No
adjacent_countNumber of differences between successive elements
Any
Int64
Linear
No
cumsumCumulative sum
Double, int64
Double, int64
Linear
No
cumulative_sumCumulative sum
Double, int64
Double, int64
Linear
No
productProduct
Double, int64
Double, int64
Linear
Yes
spreadSpread
Double, int64
Double, int64
Linear
Yes
skewnessSkewness
Double, int64
Double, int64
Linear
No
kurtosisKurtosis
Double, int64
Double, int64
Linear
No
abs_minmin(abs(x))
Double, int64
Double, int64
Linear
No
abs_maxmax(abs(x))
Double, int64
Double, int64
Linear
No
sum_of_squaresSum of squares
Double, int64
Double, int64
Linear
Yes
sample_varianceSample variance
Double, int64
Double, int64
Linear
No
sample_stddevSample standard deviation
Double, int64
Double, int64
Linear
No
population_variancePopulation variance
Double, int64
Double, int64
Linear
No
population_stddevPopulation standard deviation
Double, int64
Double, int64
Linear
No
correlationPopulation correlation
Double, int64
Double
Linear
No
covariancePopulation covariance
Double, int64
Double
Linear
No
8.2. Comparison operators¶
For WHERE clauses, QuasarDB supports different boolean operators to filter rows from the results. Below is an overview of the operators available and the value types they can operator on.
Operator
Description
Applies to
=Equal
Any
!=Not equal
Any
<Less than
Double, int64
>Greater than
Double, int64
<=Less than or equal to
Double, int64
>=Greater than or equal to
Double, int64
in find(...)Is contained in the resulting set
Blob, double, int64, string
You can use inline key/value lookups to check if a value is contained in the set of blobs/ints resulting from it. See IN FIND example.
8.3. Logical operators¶
You can compose boolean operators in WHERE clause with logical operators to filter rows from the results. Below is an overview of the operators available.
Operator
Description
andLogical and
orLogical or
notLogical not
8.4. Arithmetic operator¶
Bitwise operators allow you to combine values in SELECT and WHERE clauses. Below is an overview of the operators available.
Operator
Description
Applies to
+Addition
double, int64
-Substraction
double, int64
*Multiplication
double, int64
/Division
double, int64
Aggregations with a single result can be combined with arithmetic, which allows to use expressions like sum(b - min(a)).
8.5. Bitwise operators¶
Bitwise operators allow you to combine values in SELECT and WHERE clauses. Below is an overview of the operators available.
Operator
Description
Applies to
&Bitwise and
int64
8.6. Regular expressions¶
Regular expressions on blobs are possible within WHERE clauses. QuasarDB uses the extended POSIX regular expression grammar.
Operator
Description
Applies to
~Regex case sensitive match
blob
!~Regex case sensitive no match
blob
~*Regex case insensitive match
blob
!~*Regex case insensitive no match
blob
8.8. Geographical functions¶
Built-in functions are available for your convenience to store and query effiently geographical data.
Profile
Description
Input value
Return value
geohash64(double, double) -> int64Transforms a latitude and a longitude into a sub-meter precise geohash.
Latitude and longitude
int64 hash
8.9. Lookup function¶
The Lookup function enables you to map the result of an expression to the key-value store inside QuasarDB.
It stringifies the result of an expression, and prefix it with the provided string. It will then return the content of keys matching the entry.
For example, if the row contains the integer 1, it will be transformed to the string 1, and the provided string will be prefixed.
If the key is of the wrong type or missing, no row will be returned.
Profile
Description
Input value
Return value
lookup(string, expression) -> columnLookup keys based on the result of the expression and the provided prefix.
Prefix and expression
column of blobs
8.9.1. Example¶
For the following table trades:
timestamp
agent
value
2018-01-01T10:01:023
4
2018-01-01T10:01:042
5
2018-01-01T10:01:081
4
And with the following blob keys (added through the key/value API):
Key
Value
‘agentid.1’
‘Bob’
‘agentid.2’
‘Terry’
‘agentid.3’
‘Alice’
The following query:
select lookup('agentid.', agent), value from trades where value=4
Will output:
timestamp
lookup(‘agentid.’, agent)
value
2018-01-01T10:01:02‘Alice’
4
2018-01-01T10:01:08‘Bob’
4
8.10. Cast function¶
The Cast function enables you to transform the result of an expression.
Profile
Description
Input value
Return value
cast(expression as EPOCH_NS) -> int64Number of nanoseconds since 1 January 1970.
timestamp
int64
cast(expression as EPOCH_US) -> int64Number of microseconds since 1 January 1970.
timestamp
int64
cast(expression as EPOCH_MS) -> int64Number of milliseconds since 1 January 1970.
timestamp
int64
cast(expression as EPOCH_S) -> int64Number of seconds since 1 January 1970.
timestamp
int64