Module: HBase::Operation::RowOperation
- Included in:
- Client
- Defined in:
- lib/hbase/operation/row_operation.rb
Constant Summary collapse
- Converter =
{ '&' => '&', '<' => '<', '>' => '>', "'" => ''', '"' => '"' }
Instance Method Summary collapse
- #create_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
- #delete_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
- #row_timestamps(table_name, name) ⇒ Object
- #show_row(table_name, name, timestamp = nil, columns = nil, options = { }) ⇒ Object
Instance Method Details
#create_row(table_name, name, timestamp = nil, columns = nil) ⇒ Object
32 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 61 |
# File 'lib/hbase/operation/row_operation.rb', line 32 def create_row(table_name, name, = nil, columns = nil) begin request = Request::RowRequest.new(table_name, name, ) data = [] if columns if columns.instance_of? Array data = columns elsif columns.instance_of? Hash data = [columns] else raise StandardError, "Only Array or Hash data accepted" end 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>" 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
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hbase/operation/row_operation.rb', line 63 def delete_row(table_name, name, = nil, columns = nil) begin request = Request::RowRequest.new(table_name, name, ) 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
12 13 14 |
# File 'lib/hbase/operation/row_operation.rb', line 12 def (table_name, name) raise NotImplementedError, "Currently not supported in native hbase client" end |
#show_row(table_name, name, timestamp = nil, columns = nil, options = { }) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hbase/operation/row_operation.rb', line 16 def show_row(table_name, name, = nil, columns = nil, = { }) begin request = Request::RowRequest.new(table_name, name, ) row = Response::RowResponse.new(get(request.show(columns, ))).parse row.table_name = table_name row. = 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 |