class Riak::Client::BeefcakeProtobuffsBackend::TimeSeriesQueryOperator

Public Class Methods

new(backend, convert_timestamp) click to toggle source
# File lib/riak/client/beefcake/time_series_query_operator.rb, line 10
def initialize(backend, convert_timestamp)
  super(backend)
  @convert_timestamp = convert_timestamp
end

Public Instance Methods

query(base, interpolations = { }) click to toggle source
# File lib/riak/client/beefcake/time_series_query_operator.rb, line 15
def query(base, interpolations = {  })
  interpolator = TsInterpolation.new base: base
  interpolator.interpolations = pairs_for interpolations

  request = TsQueryReq.new query: interpolator

  result = backend.protocol do |p|
    p.write :TsQueryReq, request
    p.expect :TsQueryResp, TsQueryResp, empty_body_acceptable: true
  end

  return [] if :empty == result

  codec = TsCellCodec.new(@convert_timestamp)

  collection = Riak::TimeSeries::Collection.
               new(result.rows.map do |row|
                     Riak::TimeSeries::Row.new codec.scalars_for row.cells
                   end)

  collection.columns = result.columns

  collection
end

Private Instance Methods

pairs_for(interpolations) click to toggle source
# File lib/riak/client/beefcake/time_series_query_operator.rb, line 41
def pairs_for(interpolations)
  interpolations.map do |key, value|
    RpbPair.new key: key.to_s, value: value.to_s
  end
end