Class: HBaseRb::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hbaserb/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, port = 9090) ⇒ Client

Returns a new instance of Client.



4
5
6
7
8
9
10
# File 'lib/hbaserb/client.rb', line 4

def initialize(server, port=9090)
  socket = Thrift::Socket.new(server, port)
  @transport = Thrift::BufferedTransport.new(socket)
  @transport.open
  protocol = Thrift::BinaryProtocol.new(@transport)
  @client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
end

Instance Method Details

#closeObject



31
32
33
# File 'lib/hbaserb/client.rb', line 31

def close
  @transport.close
end

#create_table(tablename, *column_family_names) ⇒ Object



25
26
27
28
29
# File 'lib/hbaserb/client.rb', line 25

def create_table(tablename, *column_family_names)
  column_family_names.map! { |name| Apache::Hadoop::Hbase::Thrift::ColumnDescriptor.new(:name => name) }
  @client.createTable tablename, column_family_names
  get_table tablename
end

#get_table(tablename) ⇒ Object



20
21
22
23
# File 'lib/hbaserb/client.rb', line 20

def get_table(tablename)
  raise HBaseRb::NoSuchTable if not has_table? tablename
  HBaseRb::Table.new @client, tablename
end

#has_table?(name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/hbaserb/client.rb', line 16

def has_table?(name)
  table_names.include? name
end

#table_namesObject



12
13
14
# File 'lib/hbaserb/client.rb', line 12

def table_names
  @client.getTableNames
end