Function Reference

filter

Filters objects matching a condition. For example, filter by city and temperature:

.filter( (sensor) -> sensor.city == 'NY' and sensor.temp > 50 ) 

or:

.filter( (sensor) -> sensor.city == 'NY' and (sensor.temp < 50 or sensor.temp > 100) ) 

map

Transforms each object in the stream to a different object. For example, converting temperature from Celsius to Fahrenheit:

.map( (sensor) -> {tempFahrenheit: (sensor.temp * 9) / 5 + 32 } )

flatMap

Transforms object to a different object and produces a stream of nested objects:

.flatMap( (sensor) -> sensor.readings )

For example if we have a sensor with multiple readings in nested objects:

{"readings": {"temp": {"val": 20},  "humidity": {"val": 50}} }

then the above flatMap will produce two json objects:

{"temp":         {"val": 20} }
{"humidity":     {"val": 50} } 

count

Count number of objects returned:

.count()

min

Compute minimum value for a property:

.min( property )

max

Compute maximum value for a property:

.max( property )

sum

Compute a sum of all property values:

.sum( property )

avg

Compute an average of all property values:

.avg( property )

stats

Returns min/max/count/sum/avg together in one object:

 .stats( property )

statsEx

Same as stats but also returns sample standard deviation:

 .statsEx( property )

reduce

Reduce combines a collections of JSON objects into one. The only parameter is an associative reduce function in the form:

.reduce( (a, b) -> c )

It takes two objects and produces a third object c. Object c will be passed to the reduce function again with the next object as an argument. The following examples computes a result object where the temperatures of all sensors are summed up:

.reduce( (a, b) -> {temp: a.temp + b.temp} )

reduceBy

Compute an aggregate value for a property:

.reduceBy(Function, property)

where Function is one of: Math.max, Math.min, Num.sum, Num.avg, Num.stats or a user defined reduce function for two property values. The function needs to be associative. For example, to compute a product of all property values:

.reduceBy( (a, b) -> a * b, "property")

aggregateBy

Groups objects by a property and computes an aggregate based on another property:

.aggregateBy("group by prop", Function, "prop")

where Function is the same as in reduceBy.

hyperLogLog

Count distinct values (estimated) for a property:

.hll("city")

topK

Computes top K most common values of a property:

.topK("city", 10)

percentile

Estimates a percentile for a property. Percentile is in the range 0-100:

.percentile("temp", 50)

rollup

Rollup splits historical data into specified periods and computes statistics for each period. To compute statistics for every day run:

.rollup(1, "day") 

Other available time periods are: "second", "minute", "hour"