Class: HBase::Row

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hbase-jruby/row.rb

Overview

Author:

Defined Under Namespace

Modules: HashExtension

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Compares two Result instances on their row keys



273
274
275
# File 'lib/hbase-jruby/row.rb', line 273

def <=> other
  Bytes.compareTo(rowkey(:raw), other.rowkey(:raw))
end

#[](*col) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/hbase-jruby/row.rb', line 31

def [] *col
  col = col.length == 1 ? col[0] : col
  cf, cq, type = @table.lookup_schema(col)
  if cf
    self.send type, [cf, cq]
  else
    self.raw col
  end
end

#bigdecimal(col) ⇒ BigDecimal

Returns the latest column value as a BigDecimal



217
218
219
# File 'lib/hbase-jruby/row.rb', line 217

def bigdecimal col
  decode_value :bigdecimal, col
end

#bigdecimals(col) ⇒ Hash<Fixnum, BigDecimal>

Returns all versions of column values as BigDecimals in a Hash indexed by their timestamps



224
225
226
# File 'lib/hbase-jruby/row.rb', line 224

def bigdecimals col
  decode_value :bigdecimal, col, true
end

#boolean(col) ⇒ true, false Also known as: bool

Returns the latest column value as a boolean value



259
260
261
# File 'lib/hbase-jruby/row.rb', line 259

def boolean col
  decode_value :boolean, col
end

#booleans(col) ⇒ Hash<Fixnum, true|false> Also known as: bools

Returns all versions of column values as boolean values in a Hash indexed by their timestamps



267
268
269
# File 'lib/hbase-jruby/row.rb', line 267

def booleans col
  decode_value :boolean, col, true
end

#byte(col) ⇒ Fixnum

Returns the latest 1-byte column value as a Fixnum



159
160
161
# File 'lib/hbase-jruby/row.rb', line 159

def byte col
  decode_value :byte, col
end

#byte_array(col) ⇒ byte[]

Returns the latest column value as a HBase::ByteArray instance



113
114
115
# File 'lib/hbase-jruby/row.rb', line 113

def byte_array col
  decode_value :byte_array, col
end

#byte_arrays(col) ⇒ byte[]

Returns all versions of column values as HBase::ByteArray instances in a Hash indexed by their timestamps



120
121
122
# File 'lib/hbase-jruby/row.rb', line 120

def byte_arrays col
  decode_value :byte_array, col, true
end

#bytes(col) ⇒ Hash<Fixnum, Fixnum>

Returns all versions of 1-byte column values as Fixnums in a Hash indexed by their timestamps



166
167
168
# File 'lib/hbase-jruby/row.rb', line 166

def bytes col
  decode_value :byte, col, true
end

#double(col) ⇒ Float

Returns the latest 8-byte column value as a Float



245
246
247
# File 'lib/hbase-jruby/row.rb', line 245

def double col
  decode_value :double, col
end

#doubles(col) ⇒ Hash<Fixnum, Float>

Returns all versions of 8-byte column values as Floats in a Hash indexed by their timestamps



252
253
254
# File 'lib/hbase-jruby/row.rb', line 252

def doubles col
  decode_value :double, col, true
end

#eachObject

Enumerates through cells



24
25
26
27
28
29
# File 'lib/hbase-jruby/row.rb', line 24

def each
  return enum_for(:each) unless block_given?
  @result.raw.each do |kv|
    yield Cell.new(@table, kv)
  end
end

#empty?Boolean

Returns if the returned row is empty



11
12
13
# File 'lib/hbase-jruby/row.rb', line 11

def empty?
  @result.empty?
end

#fixnum(col) ⇒ Fixnum Also known as: long

Returns the latest 8-byte column value as a Fixnum



201
202
203
# File 'lib/hbase-jruby/row.rb', line 201

def fixnum col
  decode_value :fixnum, col
end

#fixnums(col) ⇒ Hash<Fixnum, Fixnum> Also known as: longs

Returns all versions of 8-byte column values as Fixnums in a Hash indexed by their timestamps



209
210
211
# File 'lib/hbase-jruby/row.rb', line 209

def fixnums col
  decode_value :fixnum, col, true
end

#float(col) ⇒ Float

Returns the latest 4-byte column value as a Float



231
232
233
# File 'lib/hbase-jruby/row.rb', line 231

def float col
  decode_value :float, col
end

#floats(col) ⇒ Hash<Fixnum, Float>

Returns all versions of 4-byte column values as Floats in a Hash indexed by their timestamps



238
239
240
# File 'lib/hbase-jruby/row.rb', line 238

def floats col
  decode_value :float, col, true
end

#inspectObject



277
278
279
# File 'lib/hbase-jruby/row.rb', line 277

def inspect
  "#<HBase::Row:#{object_id} table=#{@table.name} rowkey=#{Bytes.toStringBinary @result.getRow}>"
end

#int(col) ⇒ Fixnum

Returns the latest 4-byte column value as a Fixnum



187
188
189
# File 'lib/hbase-jruby/row.rb', line 187

def int col
  decode_value :int, col
end

#ints(col) ⇒ Hash<Fixnum, Fixnum>

Returns all versions of 4-byte column values as Fixnums in a Hash indexed by their timestamps



194
195
196
# File 'lib/hbase-jruby/row.rb', line 194

def ints col
  decode_value :int, col, true
end

#raw(col) ⇒ byte[]

Returns the latest column value as a Java byte array



99
100
101
# File 'lib/hbase-jruby/row.rb', line 99

def raw col
  get_value col
end

#raws(col) ⇒ Hash<Fixnum, byte[]>

Returns all versions of column values as Java byte arrays in a Hash indexed by their timestamps



106
107
108
# File 'lib/hbase-jruby/row.rb', line 106

def raws col
  get_value col, true
end

#rowkey(type = :raw) ⇒ String, byte[]

Returns the rowkey of the row



19
20
21
# File 'lib/hbase-jruby/row.rb', line 19

def rowkey type = :raw
  Util.from_bytes type, @result.getRow
end

#short(col) ⇒ Fixnum

Returns the latest 2-byte column value as a Fixnum



173
174
175
# File 'lib/hbase-jruby/row.rb', line 173

def short col
  decode_value :short, col
end

#shorts(col) ⇒ Hash<Fixnum, Fixnum>

Returns all versions of 2-byte column values as Fixnums in a Hash indexed by their timestamps



180
181
182
# File 'lib/hbase-jruby/row.rb', line 180

def shorts col
  decode_value :short, col, true
end

#string(col) ⇒ String Also known as: str

Returns the latest column value as a String



127
128
129
# File 'lib/hbase-jruby/row.rb', line 127

def string col
  decode_value :string, col
end

#strings(col) ⇒ Hash<Fixnum, String> Also known as: strs

Returns all versions of column values as Strings in a Hash indexed by their timestamps



135
136
137
# File 'lib/hbase-jruby/row.rb', line 135

def strings col
  decode_value :string, col, true
end

#symbol(col) ⇒ Symbol Also known as: sym

Returns the latest column value as a Symbol



143
144
145
# File 'lib/hbase-jruby/row.rb', line 143

def symbol col
  decode_value :symbol, col
end

#symbols(col) ⇒ Hash<Fixnum, Symbol> Also known as: syms

Returns all versions of column values as Symbols in a Hash indexed by their timestamps



151
152
153
# File 'lib/hbase-jruby/row.rb', line 151

def symbols col
  decode_value :symbol, col, true
end

#to_HHash Also known as: to_hash_with_versions



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/hbase-jruby/row.rb', line 74

def to_H
  ret = {}
  @result.getMap.each do |cf, cqmap|
    cf = Util.from_bytes :string, cf
    cqmap.each do |cq, tsmap|
      cqs = Util.from_bytes(:string, cq) rescue nil
      f, q, t = @table.lookup_schema(cqs)
      t = nil if f != cf
      name = t ? q : [cf.to_sym, ByteArray[cq]]

      ret[name] =
        Hash[
          tsmap.map { |ts, val|
            [ ts, Util.from_bytes(t, val) ]
          }
        ]
    end
  end
  ret.extend(HashExtension)
end

#to_hHash Also known as: to_hash



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hbase-jruby/row.rb', line 56

def to_h
  ret = {}
  @result.getNoVersionMap.each do |cf, cqmap|
    cf = Util.from_bytes :string, cf
    cqmap.each do |cq, val|
      cqs = Util.from_bytes(:string, cq) rescue nil
      f, q, t = @table.lookup_schema(cqs)
      t = nil if f != cf
      name = t ? q : [cf.to_sym, ByteArray[cq]]

      ret[name] = Util.from_bytes(t, val)
    end
  end
  ret.extend(HashExtension)
end