Class: HBase::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/hbase-jruby/cell.rb

Overview

@return [org.apache.hadoop.hbase.KeyValue]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, key_value) ⇒ Cell

Creates a boxed object for a KeyValue object

Parameters:

  • key_value (org.apache.hadoop.hbase.KeyValue)


10
11
12
13
14
# File 'lib/hbase-jruby/cell.rb', line 10

def initialize table, key_value
  @table = table
  @java = key_value
  @ck   = nil
end

Instance Attribute Details

#javaObject (readonly)

Returns the value of attribute java.



6
7
8
# File 'lib/hbase-jruby/cell.rb', line 6

def java
  @java
end

Instance Method Details

#<=>(other) ⇒ Fixnum

Implements column key order

Parameters:

Returns:

  • (Fixnum)

    -1, 0, or 1



121
122
123
# File 'lib/hbase-jruby/cell.rb', line 121

def <=> other
  KeyValue.COMPARATOR.compare(@java, other.java)
end

#bigdecimalBigDecimal

Returns the column value as a BigDecimal

Returns:

  • (BigDecimal)


100
101
102
# File 'lib/hbase-jruby/cell.rb', line 100

def bigdecimal
  Util.from_bytes :bigdecimal, value
end

#booleantrue, false Also known as: bool

Returns the column value as a boolean value

Returns:

  • (true, false)


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

def boolean
  Util.from_bytes :boolean, value
end

#byteFixnum

Returns the 1-byte column value as a Fixnum

Returns:

  • (Fixnum)


94
95
96
# File 'lib/hbase-jruby/cell.rb', line 94

def byte
  Util.from_bytes :byte, value
end

#eql?(other) ⇒ Boolean Also known as: ==

Checks if the cells are the same

Parameters:

Returns:

  • (Boolean)


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

def eql? other
  (self <=> other) == 0
end

#familyString Also known as: cf

Returns the name of the column family of the cell

Returns:

  • (String)


26
27
28
# File 'lib/hbase-jruby/cell.rb', line 26

def family
  String.from_java_bytes @java.getFamily
end

#fixnumFixnum Also known as: long

Returns the 8-byte column value as a Fixnum

Returns:

  • (Fixnum)


75
76
77
# File 'lib/hbase-jruby/cell.rb', line 75

def fixnum
  Util.from_bytes :fixnum, value
end

#floatFloat Also known as: double

Returns the column value as a Float

Returns:

  • (Float)


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

def float
  Util.from_bytes :float, value
end

#hashObject



132
133
134
# File 'lib/hbase-jruby/cell.rb', line 132

def hash
  @java.hasCode
end

#inspectString

Returns a printable version of this cell

Returns:

  • (String)


138
139
140
# File 'lib/hbase-jruby/cell.rb', line 138

def inspect
  %[#{cf}:#{cq} = "#{string}"@#{ts}]
end

#intFixnum

Returns the 4-byte column value as a Fixnum

Returns:

  • (Fixnum)


82
83
84
# File 'lib/hbase-jruby/cell.rb', line 82

def int
  Util.from_bytes :int, value
end

#qualifier(type = :string) ⇒ Object Also known as: cq

Returns the column qualifier of the cell

Parameters:

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

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

Returns:

  • (Object)


35
36
37
# File 'lib/hbase-jruby/cell.rb', line 35

def qualifier type = :string
  Util.from_bytes type, @java.getQualifier
end

#rawbyte[]

Returns the value of the cell as a Java byte array

Returns:



55
56
57
# File 'lib/hbase-jruby/cell.rb', line 55

def raw
  @java.getValue
end

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

Returns the rowkey of the cell decoded as the given type

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:



20
21
22
# File 'lib/hbase-jruby/cell.rb', line 20

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

#shortFixnum

Returns the 2-byte column value as a Fixnum

Returns:

  • (Fixnum)


88
89
90
# File 'lib/hbase-jruby/cell.rb', line 88

def short
  Util.from_bytes :short, value
end

#stringString Also known as: str

Returns the column value as a String

Returns:

  • (String)


61
62
63
# File 'lib/hbase-jruby/cell.rb', line 61

def string
  Util.from_bytes :string, value
end

#symbolSymbol Also known as: sym

Returns the column value as a Symbol

Returns:

  • (Symbol)


68
69
70
# File 'lib/hbase-jruby/cell.rb', line 68

def symbol
  Util.from_bytes :symbol, value
end

#timestampFixnum Also known as: ts

Returns the timestamp of the cell

Returns:

  • (Fixnum)


42
43
44
# File 'lib/hbase-jruby/cell.rb', line 42

def timestamp
  @java.getTimestamp
end

#valueObject

Returns the value of the cell. If the column in not defined in the schema, returns Java byte array.



48
49
50
51
# File 'lib/hbase-jruby/cell.rb', line 48

def value
  _, _, type = @table.lookup_schema(cq)
  Util.from_bytes(type, raw)
end