Class: HBase::Row

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

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#<=>(other) ⇒ Object

Compares two Result instances on their row keys



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

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(column) ⇒ BigDecimal

Returns column values as Bigdecimals

Returns the latest column value as a BigDecimal

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (BigDecimal)


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

def bigdecimal col
  decode_value :bigdecimal, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, BigDecimal>)


227
228
229
# File 'lib/hbase-jruby/row.rb', line 227

def bigdecimals col
  decode_value :bigdecimal, col, true
end

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

Returns column values as Booleans

Returns the latest column value as a boolean value

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (true, false)


256
257
258
# File 'lib/hbase-jruby/row.rb', line 256

def boolean col
  decode_value :boolean, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, true|false>)


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

def booleans col
  decode_value :boolean, col, true
end

#byte(column) ⇒ Fixnum

Returns 1-byte column values as Fixnums

Returns the latest column value as a Fixnum

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Fixnum)


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

def byte col
  decode_value :byte, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, Fixnum>)


153
154
155
# File 'lib/hbase-jruby/row.rb', line 153

def bytes col
  decode_value :byte, 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

Returns:

  • (Boolean)


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

def empty?
  @result.empty?
end

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

Returns 8-byte column values as Fixnums

Returns the latest 8-byte column value as a Fixnum

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Fixnum)


198
199
200
# File 'lib/hbase-jruby/row.rb', line 198

def fixnum col
  decode_value :fixnum, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, Fixnum>)


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

def fixnums col
  decode_value :fixnum, col, true
end

#float(column) ⇒ Float Also known as: double

Returns column values as Floats

Returns the latest column value as a Float

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Float)


236
237
238
# File 'lib/hbase-jruby/row.rb', line 236

def float col
  decode_value :float, col
end

#floats(column) ⇒ Hash<Fixnum, Float> Also known as: doubles

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, Float>)


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

def floats col
  decode_value :float, col, true
end

#int(column) ⇒ Fixnum

Returns 4-byte column values as Fixnums

Returns the latest 4-byte column value as a Fixnum

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Fixnum)


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

def int col
  decode_value :int, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, Fixnum>)


189
190
191
# File 'lib/hbase-jruby/row.rb', line 189

def ints col
  decode_value :int, col, true
end

#raw(column) ⇒ byte[]

Returns column values as byte arrays

Returns the latest column value as a byte array

Parameters:

  • col (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (byte[])

    Byte array representation of the latest value



86
87
88
# File 'lib/hbase-jruby/row.rb', line 86

def raw col
  get_value col
end

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

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

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

Parameters:

  • col (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, byte[]>)


95
96
97
# File 'lib/hbase-jruby/row.rb', line 95

def raws col
  get_value col, true
end

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

Returns the rowkey of the row

Parameters:

  • type (Symbol) (defaults to: :raw)

    The type of the rowkey Can be one of :string, :symbol, :fixnum, :float, :short, :int, :bigdecimal, :boolean and :raw.

Returns:



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

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

#short(column) ⇒ Fixnum

Returns 2-byte column values as Fixnums

Returns the latest 2-byte column value as a Fixnum

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Fixnum)


162
163
164
# File 'lib/hbase-jruby/row.rb', line 162

def short col
  decode_value :short, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, Fixnum>)


171
172
173
# File 'lib/hbase-jruby/row.rb', line 171

def shorts col
  decode_value :short, col, true
end

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

Returns column values as Strings

Returns the latest column value as a String

Parameters:

  • col (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (String)


104
105
106
# File 'lib/hbase-jruby/row.rb', line 104

def string col
  decode_value :string, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, String>)


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

def strings col
  decode_value :string, col, true
end

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

Returns column values as Symbols

Returns the latest column value as a Symbol

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Symbol)


124
125
126
# File 'lib/hbase-jruby/row.rb', line 124

def symbol col
  decode_value :symbol, col
end

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

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

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

Parameters:

  • column (String, Array)

    Column name as String or 2-element Array of family and qualifier

Returns:

  • (Hash<Fixnum, Symbol>)


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

def symbols col
  decode_value :symbol, col, true
end

#to_HHash Also known as: to_hash_with_versions

Returns:

  • (Hash)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/hbase-jruby/row.rb', line 60

def to_H
  HASH_TEMPLATE.clone.tap do |ret|
    @result.getMap.each do |cf, cqmap|
      cf = cf.to_s
      cqmap.each do |cq, tsmap|
        f, q, t = @table.lookup_schema(cq.to_s)
        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
  end
end

#to_hHash Also known as: to_hash

Only supports string column qualifiers

Returns:

  • (Hash)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hbase-jruby/row.rb', line 43

def to_h
  HASH_TEMPLATE.clone.tap do |ret|
    @result.getNoVersionMap.each do |cf, cqmap|
      cf = cf.to_s
      cqmap.each do |cq, val|
        f, q, t = @table.lookup_schema(cq.to_s)
        t = nil if f != cf
        name = t ? q : [cf.to_sym, ByteArray[cq]]

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