RethinkDB.Query.Aggregation
ReQL methods for aggregation operations.
All examples assume that use RethinkDB
has been called.
Summary↑
avg(arg) | |
avg(arg, opts) | Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error |
avg(left, right, opts) | |
contains(seq, args) | When called with values, returns |
contains(left, right, opts) | |
count(arg) | |
count(arg, opts) | Counts the number of elements in a sequence. If called with a value, counts
the number of times that value occurs in the sequence. If called with a
predicate function, counts the number of elements in the sequence where that
function returns |
count(left, right, opts) | |
distinct(arg) | |
distinct(seq, opts) | Removes duplicates from elements in a sequence |
group(seq, keys) | Takes a stream and partitions it into multiple groups based on the fields or functions provided |
max(arg) | |
max(seq, opts) | Finds the maximum element of a sequence. The max command can be called with: |
max(left, right, opts) | |
min(arg) | |
min(seq, opts) | Finds the minimum element of a sequence. The min command can be called with: |
min(left, right, opts) | |
reduce(left, right) | |
reduce(left, right, opts) | Produce a single value from a sequence through repeated application of a reduction function |
sum(arg) | |
sum(arg, opts) | Sums all the elements of a sequence. If called with a field name, sums all
the values of that field in the sequence, skipping elements of the sequence
that lack that field. If called with a function, calls that function on every
element of the sequence and sums the results, skipping elements of the sequence
where that function returns |
sum(left, right, opts) | |
ungroup(arg) | |
ungroup(arg, opts) | Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after ungroup will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction |
Functions
Specs:
Specs:
- avg(RethinkDB.Query.reql_array, RethinkDB.Query.reql_string | RethinkDB.Query.reql_func1) :: RethinkDB.Query.t
Averages all the elements of a sequence. If called with a field name, averages all the values of that field in the sequence, skipping elements of the sequence that lack that field. If called with a function, calls that function on every element of the sequence and averages the results, skipping elements of the sequence where that function returns None or a non-existence error.
Produces a non-existence error when called on an empty sequence. You can
handle this case with default
.
Specs:
- contains(RethinkDB.Query.reql_array, RethinkDB.Query.reql_array | RethinkDB.Query.reql_func1 | RethinkDB.Query.t) :: RethinkDB.Query.t
When called with values, returns true
if a sequence contains all the specified
values. When called with predicate functions, returns true
if for each
predicate there exists at least one element of the stream where that predicate
returns true
.
Specs:
- count(RethinkDB.Query.reql_array) :: RethinkDB.Query.t
Specs:
- count(RethinkDB.Query.reql_array, RethinkDB.Query.reql_string | RethinkDB.Query.reql_func1) :: RethinkDB.Query.t
Counts the number of elements in a sequence. If called with a value, counts
the number of times that value occurs in the sequence. If called with a
predicate function, counts the number of elements in the sequence where that
function returns true
.
If count is called on a binary object, it will return the size of the object in bytes.
Specs:
Removes duplicates from elements in a sequence.
The distinct command can be called on any sequence, a table, or called on a table with an index.
Specs:
- group(RethinkDB.Query.reql_array, RethinkDB.Query.reql_func1 | RethinkDB.Query.reql_string | [RethinkDB.Query.reql_func1 | RethinkDB.Query.reql_string]) :: RethinkDB.Query.t
Takes a stream and partitions it into multiple groups based on the fields or functions provided.
With the multi flag single documents can be assigned to multiple groups, similar to the behavior of multi-indexes. When multi is True and the grouping value is an array, documents will be placed in each group that corresponds to the elements of the array. If the array is empty the row will be ignored.
Specs:
- max(RethinkDB.Query.reql_array, RethinkDB.Query.reql_opts | RethinkDB.Query.reql_string | RethinkDB.Query.reql_func1) :: RethinkDB.Query.t
Finds the maximum element of a sequence. The max command can be called with:
- a field name, to return the element of the sequence with the smallest value in that field;
- an index, to return the element of the sequence with the smallest value in that index;
- a function, to apply the function to every element within the sequence and return the element which returns the smallest value from the function, ignoring any elements where the function returns None or produces a non-existence error.
Calling max on an empty sequence will throw a non-existence error; this can be
handled using the default
command.
Specs:
- min(RethinkDB.Query.reql_array, RethinkDB.Query.reql_opts | RethinkDB.Query.reql_string | RethinkDB.Query.reql_func1) :: RethinkDB.Query.t
Finds the minimum element of a sequence. The min command can be called with:
- a field name, to return the element of the sequence with the smallest value in that field;
- an index, to return the element of the sequence with the smallest value in that index;
- a function, to apply the function to every element within the sequence and return the element which returns the smallest value from the function, ignoring any elements where the function returns None or produces a non-existence error.
Calling min on an empty sequence will throw a non-existence error; this can be
handled using the default
command.
Specs:
Produce a single value from a sequence through repeated application of a reduction function.
The reduction function can be called on:
- two elements of the sequence
- one element of the sequence and one result of a previous reduction
- two results of previous reductions
The reduction function can be called on the results of two previous reductions because the reduce command is distributed and parallelized across shards and CPU cores. A common mistaken when using the reduce command is to suppose that the reduction is executed from left to right.
Specs:
Specs:
- sum(RethinkDB.Query.reql_array, RethinkDB.Query.reql_string | RethinkDB.Query.reql_func1) :: RethinkDB.Query.t
Sums all the elements of a sequence. If called with a field name, sums all
the values of that field in the sequence, skipping elements of the sequence
that lack that field. If called with a function, calls that function on every
element of the sequence and sums the results, skipping elements of the sequence
where that function returns nil
or a non-existence error.
Returns 0 when called on an empty sequence.
Specs:
- ungroup(RethinkDB.Query.t) :: RethinkDB.Query.t
Takes a grouped stream or grouped data and turns it into an array of objects representing the groups. Any commands chained after ungroup will operate on this array, rather than operating on each group individually. This is useful if you want to e.g. order the groups by the value of their reduction.
The format of the array returned by ungroup is the same as the default native format of grouped data in the JavaScript driver and data explorer. end