pub struct FtReducer { /* private fields */ }
redis-search
only.Expand description
Reducer for the groupby
aggregate option
Implementations§
Source§impl FtReducer
impl FtReducer
Sourcepub fn count_distinct<P: SingleArg>(property: P) -> FtReducer
pub fn count_distinct<P: SingleArg>(property: P) -> FtReducer
Count the number of distinct values for property.
§Note
The reducer creates a hash-set per group, and hashes each record. This can be memory heavy if the groups are big.
Sourcepub fn count_distinctish<P: SingleArg>(property: P) -> FtReducer
pub fn count_distinctish<P: SingleArg>(property: P) -> FtReducer
Same as count_distinct
- but provide an approximation instead of an exact count,
at the expense of less memory and CPU in big groups.
§Note
The reducer uses HyperLogLog
counters per group,
at ~3% error rate, and 1024 Bytes of constant space allocation per group.
This means it is ideal for few huge groups and not ideal for many small groups.
In the former case, it can be an order of magnitude faster and consume much less memory
than count_distinct
,
but again, it does not fit every user case.
Sourcepub fn sum<P: SingleArg>(property: P) -> FtReducer
pub fn sum<P: SingleArg>(property: P) -> FtReducer
Return the sum of all numeric values of a given property in a group.
Non numeric values if the group are counted as 0.
Sourcepub fn min<P: SingleArg>(property: P) -> FtReducer
pub fn min<P: SingleArg>(property: P) -> FtReducer
Return the minimal value of a property, whether it is a string, number or NULL.
Sourcepub fn max<P: SingleArg>(property: P) -> FtReducer
pub fn max<P: SingleArg>(property: P) -> FtReducer
Return the maximal value of a property, whether it is a string, number or NULL.
Sourcepub fn avg<P: SingleArg>(property: P) -> FtReducer
pub fn avg<P: SingleArg>(property: P) -> FtReducer
Return the average value of a numeric property.
This is equivalent to reducing by sum and count, and later on applying the ratio of them as an APPLY step.
Sourcepub fn stddev<P: SingleArg>(property: P) -> FtReducer
pub fn stddev<P: SingleArg>(property: P) -> FtReducer
Return the standard deviation
of a numeric property in the group.
Sourcepub fn quantile<P: SingleArg>(property: P, quantile: f64) -> FtReducer
pub fn quantile<P: SingleArg>(property: P, quantile: f64) -> FtReducer
Return the value of a numeric property at a given quantile of the results.
Quantile is expressed as a number between 0 and 1. For example, the median can be expressed as the quantile at 0.5, e.g. REDUCE QUANTILE 2 @foo 0.5 AS median . If multiple quantiles are required, just repeat the QUANTILE reducer for each quantile. e.g. REDUCE QUANTILE 2 @foo 0.5 AS median REDUCE QUANTILE 2 @foo 0.99 AS p99
Sourcepub fn tolist<P: SingleArg>(property: P) -> FtReducer
pub fn tolist<P: SingleArg>(property: P) -> FtReducer
Merge all distinct
values of a given property into a single array.
Sourcepub fn first_value<P: SingleArg>(property: P) -> FtReducer
pub fn first_value<P: SingleArg>(property: P) -> FtReducer
Return the first or top value of a given property in the group, optionally by comparing that or another property.
If no BY is specified, we return the first value we encounter in the group. If you with to get the top or bottom value in the group sorted by the same value, you are better off using the MIN/MAX reducers, but the same effect will be achieved by doing REDUCE FIRST_VALUE 4 @foo BY @foo DESC.
Sourcepub fn first_value_by<P: SingleArg, BP: SingleArg>(
property: P,
by_property: BP,
) -> FtReducer
pub fn first_value_by<P: SingleArg, BP: SingleArg>( property: P, by_property: BP, ) -> FtReducer
Return the first or top value of a given property in the group, optionally by comparing that or another property.
Sourcepub fn first_value_by_order<P: SingleArg, BP: SingleArg>(
property: P,
by_property: BP,
order: SortOrder,
) -> FtReducer
pub fn first_value_by_order<P: SingleArg, BP: SingleArg>( property: P, by_property: BP, order: SortOrder, ) -> FtReducer
Return the first or top value of a given property in the group, optionally by comparing that or another property.
Sourcepub fn random_sample<P: SingleArg, BP: SingleArg>(
property: P,
sample_size: usize,
) -> FtReducer
pub fn random_sample<P: SingleArg, BP: SingleArg>( property: P, sample_size: usize, ) -> FtReducer
Perform a reservoir sampling of the group elements with a given size, and return an array of the sampled items with an even distribution.
Sourcepub fn as_name<N: SingleArg>(self, name: N) -> Self
pub fn as_name<N: SingleArg>(self, name: N) -> Self
The reducers can have their own property names using the AS {name} optional argument.
If a name is not given, the resulting name will be the name of the reduce function and the group properties. For example, if a name is not given to COUNT_DISTINCT by property @foo, the resulting name will be count_distinct(@foo).