forward-rbase 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rbase/client.rb CHANGED
@@ -16,6 +16,10 @@ module Rbase
16
16
  client.getTableNames
17
17
  end
18
18
 
19
+ def table_exists?(table_name)
20
+ table_names.include?(table_name)
21
+ end
22
+
19
23
  def create_table(table_name, *column_family_names)
20
24
  column_families = column_family_names.map do |family_name|
21
25
  Apache::Hadoop::Hbase::Thrift::ColumnDescriptor.new(:name => family_name)
data/lib/rbase/table.rb CHANGED
@@ -6,16 +6,13 @@ module Rbase
6
6
  end
7
7
 
8
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
9
+ @client.getRow(@table_name,row).map { |row| row_to_hash(row) }
10
+ end
11
+
12
+ def first(row)
13
+ find(row).first
18
14
  end
15
+ alias_method :[], :first
19
16
 
20
17
  def insert(row, hash)
21
18
  hash.each do |family,value|
@@ -25,5 +22,37 @@ module Rbase
25
22
  @client.mutateRow(@table_name,row,mutations)
26
23
  end
27
24
  end
25
+ alias_method :[]=, :insert
26
+
27
+ def each_batch(batch_size=100, columns=[])
28
+ columns = [columns] unless columns.is_a?(Array)
29
+ scanner_id = @client.scannerOpen(@table_name, '', columns)
30
+ loop do
31
+ results = @client.scannerGetList(scanner_id, batch_size)
32
+ break if results.length == 0
33
+ yield results.map {|r| row_to_hash(r) }
34
+ end
35
+ @client.scannerClose(scanner_id)
36
+ end
37
+
38
+ def each(batch_size=100, columns=[])
39
+ each_batch(batch_size, columns) do |results|
40
+ results.each do |result|
41
+ yield(result)
42
+ end
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def row_to_hash(row)
49
+ ret_val = {}
50
+ row.columns.each do |column,val|
51
+ family, key = *column.split(":")
52
+ ret_val[family] ||= {}
53
+ ret_val[family][key] = val.value
54
+ end
55
+ ret_val
56
+ end
28
57
  end
29
58
  end
@@ -2043,9 +2043,8 @@ require File.join(File.dirname(__FILE__), 'hbase_types')
2043
2043
  IO => {:type => ::Thrift::Types::STRUCT, :name => 'io', :class => Apache::Hadoop::Hbase::Thrift::IOError}
2044
2044
  }
2045
2045
 
2046
- def struct_fields; FIELDS; __END__
2046
+ def struct_fields; FIELDS; end
2047
2047
 
2048
-
2049
2048
  def validate
2050
2049
  end
2051
2050
 
@@ -2308,5 +2307,4 @@ require File.join(File.dirname(__FILE__), 'hbase_types')
2308
2307
  end
2309
2308
  end
2310
2309
  end
2311
- end
2312
- end
2310
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forward-rbase
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Forward Internet Group