Module: HBase::Operation::RowOperation

Included in:
Client
Defined in:
lib/hbase/operation/row_operation.rb

Constant Summary collapse

Converter =
{
  '&' => '&',
  '<' => '&lt;',
  '>' => '&gt;',
  "'" => '&apos;',
  '"' => '&quot;'
}

Instance Method Summary collapse

Instance Method Details

#create_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hbase/operation/row_operation.rb', line 33

def create_row(table_name, name, timestamp = nil, columns = nil)
  begin
    request = Request::RowRequest.new(table_name, name, timestamp)
    data = []
    if columns.instance_of? Array
      data = columns
    elsif columns.instance_of? Hash
      data = [columns]
    else
      raise StandardError, "Only Array or Hash data accepted"
    end
    xml_data ="<?xml version='1.0' encoding='UTF-8'?><columns>"
    data.each do |d|
      escape_name = d[:name].gsub(/[&<>'"]/) { |match| Converter[match] }
      xml_data << "<column><name>#{escape_name}</name>"
      xml_data << "<value>#{[d[:value]].pack("m") rescue ''}</value></column>"
    end
    xml_data << "</columns>"

    Response::RowResponse.new(post(request.create, xml_data))
  rescue Net::ProtocolError => e
    if e.to_s.include?("Table")
      raise TableNotFoundError, "Table '#{table_name}' Not Found"
    elsif e.to_s.include?("Row")
      raise RowNotFoundError, "Row '#{name}' Not Found"
    end
  end
end

#delete_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hbase/operation/row_operation.rb', line 62

def delete_row(table_name, name, timestamp = nil, columns = nil)
  begin
    request = Request::RowRequest.new(table_name, name, timestamp)
    Response::RowResponse.new(delete(request.delete(columns)))
  rescue Net::ProtocolError => e
    if e.to_s.include?("Table")
      raise TableNotFoundError, "Table '#{table_name}' Not Found"
    elsif e.to_s.include?("Row")
      raise RowNotFoundError, "Row '#{name}' Not Found"
    end
  end
end

#row_timestamps(table_name, name) ⇒ Object

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/hbase/operation/row_operation.rb', line 12

def row_timestamps(table_name, name)
  raise NotImplementedError, "Currently not supported in native hbase client"
end

#show_row(table_name, name, timestamp = nil, columns = nil, version = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hbase/operation/row_operation.rb', line 16

def show_row(table_name, name, timestamp = nil, columns = nil, version = nil)
  begin
    request = Request::RowRequest.new(table_name, name, timestamp)
    row = Response::RowResponse.new(get(request.show(columns, version))).parse
    row.table_name = table_name
    row.name = name
    row.timestamp = timestamp
    row
  rescue Net::ProtocolError => e
    if e.to_s.include?("Table")
      raise TableNotFoundError, "Table '#{table_name}' Not Found"
    elsif e.to_s.include?("Row")
      raise RowNotFoundError, "Row '#{name}' Not Found"
    end
  end
end