Class: Riak::Client::BeefcakeProtobuffsBackend::TimeSeriesQueryOperator

Inherits:
Operator
  • Object
show all
Defined in:
lib/riak/client/beefcake/time_series_query_operator.rb

Instance Attribute Summary

Attributes inherited from Operator

#backend

Instance Method Summary collapse

Constructor Details

#initialize(backend, convert_timestamp) ⇒ TimeSeriesQueryOperator

Returns a new instance of TimeSeriesQueryOperator.



24
25
26
27
# File 'lib/riak/client/beefcake/time_series_query_operator.rb', line 24

def initialize(backend, convert_timestamp)
  super(backend)
  @convert_timestamp = convert_timestamp
end

Instance Method Details

#query(base, interpolations = { }) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/riak/client/beefcake/time_series_query_operator.rb', line 29

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