Struct FtReducer

Source
pub struct FtReducer { /* private fields */ }
Available on crate feature redis-search only.
Expand description

Reducer for the groupby aggregate option

Implementations§

Source§

impl FtReducer

Source

pub fn count() -> FtReducer

Count the number of records in each group

Source

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.

Source

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.

Source

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.

Source

pub fn min<P: SingleArg>(property: P) -> FtReducer

Return the minimal value of a property, whether it is a string, number or NULL.

Source

pub fn max<P: SingleArg>(property: P) -> FtReducer

Return the maximal value of a property, whether it is a string, number or NULL.

Source

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.

Source

pub fn stddev<P: SingleArg>(property: P) -> FtReducer

Return the standard deviation of a numeric property in the group.

Source

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

Source

pub fn tolist<P: SingleArg>(property: P) -> FtReducer

Merge all distinct values of a given property into a single array.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Trait Implementations§

Source§

impl ToArgs for FtReducer

Source§

fn write_args(&self, args: &mut CommandArgs)

Write this Rust type as one ore multiple args into CommandArgs. Read more
Source§

fn num_args(&self) -> usize

Number arguments generated by this Rust type

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MultipleArgsCollection<T> for T
where T: ToArgs,