forward-rbase 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rbase/client.rb +37 -0
- data/lib/rbase/table.rb +29 -0
- data/lib/rbase/thrift/hbase.rb +2312 -0
- data/lib/rbase/thrift/hbase_constants.rb +16 -0
- data/lib/rbase/thrift/hbase_types.rb +226 -0
- data/lib/rbase.rb +6 -0
- metadata +87 -0
data/lib/rbase/client.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rbase
|
2
|
+
class Client
|
3
|
+
attr_reader :client
|
4
|
+
|
5
|
+
def initialize(server,port=9090)
|
6
|
+
socket = Thrift::Socket.new(server, port.to_s)
|
7
|
+
transport = Thrift::BufferedTransport.new(socket)
|
8
|
+
transport.open
|
9
|
+
|
10
|
+
protocol = Thrift::BinaryProtocol.new(transport)
|
11
|
+
@tables = {}
|
12
|
+
@client = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(protocol)
|
13
|
+
end
|
14
|
+
|
15
|
+
def table_names
|
16
|
+
client.getTableNames
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_table(table_name, *column_family_names)
|
20
|
+
column_families = column_family_names.map do |family_name|
|
21
|
+
Apache::Hadoop::Hbase::Thrift::ColumnDescriptor.new(:name => family_name)
|
22
|
+
end
|
23
|
+
client.createTable(table_name, column_families)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_table(table_name)
|
27
|
+
@client.disableTable(table_name)
|
28
|
+
@client.deleteTable(table_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](table_name)
|
32
|
+
table_name = table_name.to_sym
|
33
|
+
@tables[table_name] ||= Rbase::Table.new(client, table_name)
|
34
|
+
@tables[table_name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/rbase/table.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rbase
|
2
|
+
class Table
|
3
|
+
def initialize(client, table_name)
|
4
|
+
@client = client
|
5
|
+
@table_name = table_name.to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
def find(row)
|
9
|
+
@client.getRow(@table_name,row).map do |row|
|
10
|
+
ret_val = {}
|
11
|
+
row.columns.each do |column,val|
|
12
|
+
family, key = *column.split(":")
|
13
|
+
ret_val[family] ||= {}
|
14
|
+
ret_val[family][key] = val.value
|
15
|
+
end
|
16
|
+
ret_val
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def insert(row, hash)
|
21
|
+
hash.each do |family,value|
|
22
|
+
mutations = value.map do |column,val|
|
23
|
+
Apache::Hadoop::Hbase::Thrift::Mutation.new(:column => "#{family}:#{column}", :value => val)
|
24
|
+
end
|
25
|
+
@client.mutateRow(@table_name,row,mutations)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|