Module: Stargate::Operation::TableOperation

Included in:
Client
Defined in:
lib/stargate/operation/table_operation.rb

Instance Method Summary collapse

Instance Method Details

#alter_table(name, *args) ⇒ Object

Raises:

  • (StandardError)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/stargate/operation/table_operation.rb', line 48

def alter_table(name, *args)
  raise StandardError, "Table name must be of type String" unless name.instance_of? String

  request = Request::TableRequest.new(name)

  begin
    xml_data = construct_xml_stream(name, *args)
    Response::TableResponse.new(put(request.update, xml_data))
  rescue Net::ProtocolError => e
    if e.to_s.include?("TableNotFoundException")
      raise TableNotFoundError, "Table '#{name}' not exists"
    else
      raise TableFailCreateError, e.message
    end
  end
end

#create_table(name, *args) ⇒ Object

Raises:

  • (StandardError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stargate/operation/table_operation.rb', line 13

def create_table(name, *args)
  request = Request::TableRequest.new(name)

  raise StandardError, "Table name must be of type String" unless name.instance_of? String

  begin
    xml_data = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><TableSchema name='#{name}' IS_META='false' IS_ROOT='false'>"
    for arg in args
      if arg.instance_of? String
        xml_data << "<ColumnSchema name='#{arg}' />"
      elsif arg.instance_of? Hash
        xml_data << "<ColumnSchema "

        arg.each do |k,v|
          if Model::ColumnDescriptor::AVAILABLE_OPTS.include? k
            xml_data << "#{Model::ColumnDescriptor::AVAILABLE_OPTS[k]}='#{v}' "
          end
        end

        xml_data << "/>"
      else
        raise StandardError, "#{arg.class.to_s} of #{arg.to_s} is not of Hash Type"
      end
    end
    xml_data << "</TableSchema>"
    Response::TableResponse.new(post(request.create, xml_data))
  rescue Net::ProtocolError => e
    if e.to_s.include?("TableExistsException")
      raise TableExistsError, "Table '#{name}' already exists"
    else
      raise TableFailCreateError, e.message
    end
  end
end

#delete_table(name, columns = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/stargate/operation/table_operation.rb', line 65

def delete_table(name, columns = nil)
  begin
    request = Request::TableRequest.new(name)
    Response::TableResponse.new(delete(request.delete(columns)))
  rescue Net::ProtocolError => e
    if e.to_s.include?("TableNotFoundException")
      raise TableNotFoundError, "Table '#{name}' not exists"
    elsif e.to_s.include?("TableNotDisabledException")
      raise TableNotDisabledError, "Table '#{name}' not disabled"
    end
  end
end

#destroy_table(name, columns = nil) ⇒ Object



78
79
80
# File 'lib/stargate/operation/table_operation.rb', line 78

def destroy_table(name, columns = nil)
  delete_table(name, columns)
end

#disable_table(name) ⇒ Object



86
87
88
# File 'lib/stargate/operation/table_operation.rb', line 86

def disable_table(name)
  warn "[DEPRECATION] Explicitly disabling tables isn't required anymore. HBase Stargate will enable/disable as needed."
end

#enable_table(name) ⇒ Object



82
83
84
# File 'lib/stargate/operation/table_operation.rb', line 82

def enable_table(name)
  warn "[DEPRECATION] Explicitly enabling tables isn't required anymore. HBase Stargate will enable/disable as needed."
end

#show_table(name) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/stargate/operation/table_operation.rb', line 4

def show_table(name)
  begin
    request = Request::TableRequest.new(name)
    Response::TableResponse.new(get(request.show)).parse
  rescue Net::ProtocolError
    raise TableNotFoundError, "Table '#{name}' Not found"
  end
end

#table_regions(name, start_row = nil, end_row = nil) ⇒ Object



90
91
# File 'lib/stargate/operation/table_operation.rb', line 90

def table_regions(name, start_row = nil, end_row = nil)
end