class Redis::TimeSeries::Aggregation

An aggregation is a combination of a mathematical function, and a time window over which to apply that function. In RedisTimeSeries, aggregations are used to downsample data from a source series to a destination series, using compaction rules.

@see Redis::TimeSeries#create_rule @see Redis::TimeSeries::Rule @see oss.redislabs.com/redistimeseries/commands/#aggregation-compaction-downsampling

Constants

TYPES

Attributes

aggregation_type[R]

@return [String] the type of aggregation to apply @see TYPES

duration[R]

@return [Integer] the time window to apply the aggregation over, in milliseconds

time_bucket[R]

@return [Integer] the time window to apply the aggregation over, in milliseconds

type[R]

@return [String] the type of aggregation to apply @see TYPES

Public Class Methods

new(type, duration) click to toggle source

Create a new Aggregation given a type and duration. @param type [String, Symbol] one of the valid aggregation {TYPES} @param duration [Integer, ActiveSupport::Duration]

A time window to apply this aggregation over.
If you're using ActiveSupport, duration objects (e.g. +10.minutes+) will be automatically coerced.

@return [Aggregation] @raise [AggregationError] if the given aggregation type is not valid

# File lib/redis/time_series/aggregation.rb, line 55
def initialize(type, duration)
  type = type.to_s.downcase
  unless TYPES.include? type
    raise AggregationError, "#{type} is not a valid aggregation type!"
  end
  @type = type
  if defined?(ActiveSupport::Duration) && duration.is_a?(ActiveSupport::Duration)
    @duration = duration.in_milliseconds
  else
    @duration = duration.to_i
  end
end
parse(agg) click to toggle source

Parse a method argument into an aggregation.

@param agg [Array, Aggregation] an aggregation object, or an array of type and duration +[:avg, 60000]+ @return [Aggregation] the parsed aggregation, or the original argument if already an aggregation @raise [AggregationError] when given an unparseable value

# File lib/redis/time_series/aggregation.rb, line 41
def self.parse(agg)
  return unless agg
  return agg if agg.is_a?(self)
  return new(agg.first, agg.last) if agg.is_a?(Array) && agg.size == 2
  raise AggregationError, "Couldn't parse #{agg} into an aggregation rule!"
end

Public Instance Methods

==(other) click to toggle source

Compares aggregations based on type and duration. @return [Boolean] whether the given aggregations are equivalent

# File lib/redis/time_series/aggregation.rb, line 82
def ==(other)
  parsed = self.class.parse(other)
  type == parsed.type && duration == parsed.duration
end
to_a() click to toggle source

@api private @return [Array]

# File lib/redis/time_series/aggregation.rb, line 70
def to_a
  ['AGGREGATION', type, duration]
end
to_s() click to toggle source

@api private @return [String]

# File lib/redis/time_series/aggregation.rb, line 76
def to_s
  to_a.join(' ')
end