Class: Riak::Client::BeefcakeProtobuffsBackend::TimeSeriesGetOperator

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

Instance Attribute Summary

Attributes inherited from Operator

#backend

Instance Method Summary collapse

Constructor Details

#initialize(backend, convert_timestamp) ⇒ TimeSeriesGetOperator

Returns a new instance of TimeSeriesGetOperator.



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

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

Instance Method Details

#get(table_name, key_components, options = {}) ⇒ 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_get_operator.rb', line 29

def get(table_name, key_components, options = {})
  codec = TsCellCodec.new(@convert_timestamp)

  request_options = options.merge(table: table_name,
                                  key: codec.cells_for(key_components))

  request = TsGetReq.new request_options

  result = begin
    backend.protocol do |p|
      p.write :TsGetReq, request
      result = p.expect :TsGetResp, TsGetResp, empty_body_acceptable: true
    end
  rescue Riak::ProtobuffsErrorResponse => e
    raise unless e.code == 10
    return nil
  end

  return nil if result == :empty

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