Class: Redis::Commands::Search::Reducers
- Inherits:
-
Object
- Object
- Redis::Commands::Search::Reducers
- Defined in:
- lib/redis/commands/modules/search/aggregation.rb
Overview
Factory for the REDUCE functions used inside AggregateRequest#group_by.
Each class method returns a Reducers instance carrying the function name, its
arguments, and an optional result alias.
Instance Attribute Summary collapse
- #alias_name ⇒ String, ... readonly
- #args ⇒ String, ... readonly
- #name ⇒ String, ... readonly
Class Method Summary collapse
-
.avg(property, alias_name: nil) ⇒ Reducers
Build an
AVGreducer. -
.collect(fields:, distinct: false, sort_by: nil, limit: nil, alias_name: nil) ⇒ Reducers
Build a
COLLECTreducer, which gathers each group's rows, projects a chosen set of fields, optionally deduplicates, sorts and limits them, and emits them as an array of per-entry maps under the reducer alias. -
.count(alias_name: nil) ⇒ Reducers
Build a
COUNTreducer. -
.count_distinct(property, alias_name: nil) ⇒ Reducers
Build a
COUNT_DISTINCTreducer. -
.count_distinctish(property, alias_name: nil) ⇒ Reducers
Build a
COUNT_DISTINCTISH(approximate distinct count) reducer. -
.first_value(property, alias_name: nil, sort_by: nil, sort_order: nil) ⇒ Reducers
Build a
FIRST_VALUEreducer, optionally ordered by another property. -
.max(property, alias_name: nil) ⇒ Reducers
Build a
MAXreducer. -
.min(property, alias_name: nil) ⇒ Reducers
Build a
MINreducer. -
.quantile(property, quantile, alias_name: nil) ⇒ Reducers
Build a
QUANTILEreducer. -
.random_sample(property, sample_size, alias_name: nil) ⇒ Reducers
Build a
RANDOM_SAMPLEreducer. -
.stddev(property, alias_name: nil) ⇒ Reducers
Build a
STDDEV(standard deviation) reducer. -
.sum(property, alias_name: nil) ⇒ Reducers
Build a
SUMreducer. -
.tolist(property, alias_name: nil) ⇒ Reducers
Build a
TOLISTreducer (collects distinct values into a list).
Instance Method Summary collapse
-
#as(alias_name) ⇒ self
Set the result alias (+AS+) for this reducer.
-
#initialize(name, *args, alias_name: nil) ⇒ Reducers
constructor
A new instance of Reducers.
Constructor Details
#initialize(name, *args, alias_name: nil) ⇒ Reducers
Returns a new instance of Reducers.
379 380 381 382 383 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 379 def initialize(name, *args, alias_name: nil) @name = name @args = args @alias_name = alias_name end |
Instance Attribute Details
#alias_name ⇒ String, ... (readonly)
374 375 376 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 374 def alias_name @alias_name end |
#args ⇒ String, ... (readonly)
374 375 376 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 374 def args @args end |
#name ⇒ String, ... (readonly)
374 375 376 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 374 def name @name end |
Class Method Details
.avg(property, alias_name: nil) ⇒ Reducers
Build an AVG reducer.
252 253 254 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 252 def self.avg(property, alias_name: nil) new("AVG", property, alias_name: alias_name) end |
.collect(fields:, distinct: false, sort_by: nil, limit: nil, alias_name: nil) ⇒ Reducers
Build a COLLECT reducer, which gathers each group's rows, projects a chosen set of
fields, optionally deduplicates, sorts and limits them, and emits them as an array of
per-entry maps under the reducer alias.
Field and sort-key names must carry an @ prefix on the wire (like the other reducers,
the caller supplies it); output map keys are the same names with the @ stripped.
339 340 341 342 343 344 345 346 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 339 def self.collect(fields:, distinct: false, sort_by: nil, limit: nil, alias_name: nil) tokens = collect_fields_tokens(fields) tokens << "DISTINCT" if distinct tokens.concat(collect_sortby_tokens(sort_by)) tokens.concat(["LIMIT", *limit]) if limit new("COLLECT", *tokens, alias_name: alias_name) end |
.count(alias_name: nil) ⇒ Reducers
Build a COUNT reducer.
198 199 200 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 198 def self.count(alias_name: nil) new("COUNT", alias_name: alias_name) end |
.count_distinct(property, alias_name: nil) ⇒ Reducers
Build a COUNT_DISTINCT reducer.
207 208 209 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 207 def self.count_distinct(property, alias_name: nil) new("COUNT_DISTINCT", property, alias_name: alias_name) end |
.count_distinctish(property, alias_name: nil) ⇒ Reducers
Build a COUNT_DISTINCTISH (approximate distinct count) reducer.
216 217 218 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 216 def self.count_distinctish(property, alias_name: nil) new("COUNT_DISTINCTISH", property, alias_name: alias_name) end |
.first_value(property, alias_name: nil, sort_by: nil, sort_order: nil) ⇒ Reducers
Build a FIRST_VALUE reducer, optionally ordered by another property.
291 292 293 294 295 296 297 298 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 291 def self.first_value(property, alias_name: nil, sort_by: nil, sort_order: nil) args = [property] if sort_by args << "BY" << sort_by args << (sort_order || "ASC").to_s.upcase end new("FIRST_VALUE", *args, alias_name: alias_name) end |
.max(property, alias_name: nil) ⇒ Reducers
Build a MAX reducer.
243 244 245 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 243 def self.max(property, alias_name: nil) new("MAX", property, alias_name: alias_name) end |
.min(property, alias_name: nil) ⇒ Reducers
Build a MIN reducer.
234 235 236 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 234 def self.min(property, alias_name: nil) new("MIN", property, alias_name: alias_name) end |
.quantile(property, quantile, alias_name: nil) ⇒ Reducers
Build a QUANTILE reducer.
271 272 273 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 271 def self.quantile(property, quantile, alias_name: nil) new("QUANTILE", property, quantile, alias_name: alias_name) end |
.random_sample(property, sample_size, alias_name: nil) ⇒ Reducers
Build a RANDOM_SAMPLE reducer.
306 307 308 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 306 def self.random_sample(property, sample_size, alias_name: nil) new("RANDOM_SAMPLE", property, sample_size, alias_name: alias_name) end |
.stddev(property, alias_name: nil) ⇒ Reducers
Build a STDDEV (standard deviation) reducer.
261 262 263 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 261 def self.stddev(property, alias_name: nil) new("STDDEV", property, alias_name: alias_name) end |
.sum(property, alias_name: nil) ⇒ Reducers
Build a SUM reducer.
225 226 227 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 225 def self.sum(property, alias_name: nil) new("SUM", property, alias_name: alias_name) end |
.tolist(property, alias_name: nil) ⇒ Reducers
Build a TOLIST reducer (collects distinct values into a list).
280 281 282 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 280 def self.tolist(property, alias_name: nil) new("TOLIST", property, alias_name: alias_name) end |
Instance Method Details
#as(alias_name) ⇒ self
Set the result alias (+AS+) for this reducer.
389 390 391 392 |
# File 'lib/redis/commands/modules/search/aggregation.rb', line 389 def as(alias_name) @alias_name = alias_name self end |