hbase-jruby 0.2.6-java → 0.3.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +16 -0
- data/README.md +303 -207
- data/hbase-jruby.gemspec +1 -1
- data/lib/hbase-jruby/byte_array.rb +25 -5
- data/lib/hbase-jruby/cell.rb +21 -10
- data/lib/hbase-jruby/dependency.rb +1 -5
- data/lib/hbase-jruby/hbase.rb +16 -1
- data/lib/hbase-jruby/row.rb +123 -260
- data/lib/hbase-jruby/schema.rb +115 -0
- data/lib/hbase-jruby/scoped/aggregation.rb +14 -0
- data/lib/hbase-jruby/scoped.rb +30 -23
- data/lib/hbase-jruby/table.rb +44 -22
- data/lib/hbase-jruby/util.rb +39 -5
- data/lib/hbase-jruby/version.rb +1 -1
- data/lib/hbase-jruby.rb +13 -13
- data/test/helper.rb +7 -1
- data/test/test_aggregation.rb +1 -1
- data/test/test_byte_array.rb +1 -1
- data/test/test_cell.rb +4 -5
- data/test/test_schema.rb +275 -0
- data/test/test_scoped.rb +33 -30
- data/test/test_table.rb +49 -86
- data/test/test_table_admin.rb +3 -3
- data/test/test_util.rb +7 -7
- metadata +5 -5
- data/lib/hbase-jruby/column_key.rb +0 -72
- data/test/test_column_key.rb +0 -49
data/test/test_schema.rb
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
4
|
+
require 'helper'
|
5
|
+
require 'set'
|
6
|
+
|
7
|
+
class TestSchema < TestHBaseJRubyBase
|
8
|
+
def teardown
|
9
|
+
@hbase.schema[@table.name] = {}
|
10
|
+
|
11
|
+
# Same
|
12
|
+
@hbase.schema.delete @table.name
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_schema
|
16
|
+
@hbase.schema = {
|
17
|
+
@table.name => {
|
18
|
+
:cf1 => {
|
19
|
+
:a => :fixnum,
|
20
|
+
:b => :symbol,
|
21
|
+
:c => :int,
|
22
|
+
/^d/i => :float,
|
23
|
+
'd2' => :short,
|
24
|
+
},
|
25
|
+
# Every column from cf2 is :string
|
26
|
+
:cf2 => { :e => :string },
|
27
|
+
|
28
|
+
# cf3:f is a 8-byte integer
|
29
|
+
:cf3 => { :f => :fixnum },
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
data = {
|
34
|
+
:a => 100,
|
35
|
+
:b => :symb,
|
36
|
+
:c => 200,
|
37
|
+
:d => 3.14,
|
38
|
+
:d2 => 300,
|
39
|
+
:e => 'Hello',
|
40
|
+
:f => 400,
|
41
|
+
[:cf1, HBase::ByteArray['x']] => 500
|
42
|
+
}
|
43
|
+
|
44
|
+
# PUT
|
45
|
+
@table.put 1, 'cf1:a' => data[:a], 'cf1:b' => data[:b], 'cf1:c' => data[:c],
|
46
|
+
'cf1:d' => data[:d], 'cf1:d2' => data[:d2], 'cf2:e' => data[:e],
|
47
|
+
'cf3:f' => data[:f], 'cf1:x' => data[[:cf1, HBase::ByteArray['x']]]
|
48
|
+
@table.put 2, data
|
49
|
+
|
50
|
+
# GET
|
51
|
+
row = @table.get(2)
|
52
|
+
assert_equal Set[ *@table.get(1).to_h.values.map { |b| HBase::ByteArray.new b }],
|
53
|
+
Set[ * row.to_h.values.map { |b| HBase::ByteArray.new b }]
|
54
|
+
assert_equal Set[ *@table.get(1).to_h.keys ], Set[ *row.to_h.keys ]
|
55
|
+
assert_equal Set[ *data.keys ], Set[ *row.to_h.keys ]
|
56
|
+
|
57
|
+
assert_equal data[:a], row[:a]
|
58
|
+
assert_equal data[:a], row['a']
|
59
|
+
|
60
|
+
assert_equal data[:b], row[:b]
|
61
|
+
assert_equal data[:b], row['b']
|
62
|
+
|
63
|
+
assert_equal data[:c], row[:c]
|
64
|
+
assert_equal data[:c], row['c']
|
65
|
+
|
66
|
+
assert_equal data[:d], row[:d]
|
67
|
+
assert_equal data[:d], row['d']
|
68
|
+
|
69
|
+
assert_equal data[:d2], row[:d2]
|
70
|
+
assert_equal data[:d2], row['d2']
|
71
|
+
|
72
|
+
assert_equal data[:e], row['cf2:e']
|
73
|
+
assert_equal data[:f], row['cf3:f']
|
74
|
+
|
75
|
+
assert_equal data[[:cf1, HBase::ByteArray['x']]], HBase::Util.from_bytes(:long, row['cf1:x'])
|
76
|
+
|
77
|
+
data1 = @table.get(1).to_h
|
78
|
+
data1[:a] *= 2
|
79
|
+
data1[:b] = :new_symbol
|
80
|
+
@table.put 3, data1
|
81
|
+
@table.increment 3, :a => 5
|
82
|
+
|
83
|
+
# PUT again
|
84
|
+
assert_equal data[:a] * 2 + 5, @table.get(3)[:a]
|
85
|
+
assert_equal :new_symbol, @table.get(3)[:b]
|
86
|
+
assert_equal :new_symbol, @table.get(3)['b']
|
87
|
+
assert_equal :new_symbol, @table.get(3)['cf1:b']
|
88
|
+
|
89
|
+
# PROJECT
|
90
|
+
assert_equal [:a, :c, :e, :f],
|
91
|
+
@table.project(:a, 'cf1:c', :cf2, :cf3).first.to_h.keys
|
92
|
+
|
93
|
+
# FILTER
|
94
|
+
assert_equal 1, @table.filter(:b => :new_symbol).count
|
95
|
+
assert_equal 2, @table.filter(:b => data[:b]).count
|
96
|
+
|
97
|
+
assert_equal 2, @table.filter( 'cf1:a' => 50..110).count
|
98
|
+
assert_equal 2, @table.filter( 'a' => 50..110).count
|
99
|
+
assert_equal 2, @table.filter( :a => 50..110).count
|
100
|
+
assert_equal 1, @table.filter(:a => { :gt => 150 }).count
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_schema_readme
|
104
|
+
@hbase.schema[@table.name] = {
|
105
|
+
:cf1 => {
|
106
|
+
:name => :string,
|
107
|
+
:age => :fixnum,
|
108
|
+
:sex => :symbol,
|
109
|
+
:height => :float,
|
110
|
+
:weight => :float,
|
111
|
+
:alive => :boolean
|
112
|
+
},
|
113
|
+
:cf2 => {
|
114
|
+
:description => :string,
|
115
|
+
/^score.*/ => :float
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
data = {
|
120
|
+
:name => 'John Doe',
|
121
|
+
:age => 20,
|
122
|
+
:sex => :male,
|
123
|
+
:height => 6.0,
|
124
|
+
:weight => 175,
|
125
|
+
:description => 'N/A',
|
126
|
+
:score1 => 8.0,
|
127
|
+
:score2 => 9.0,
|
128
|
+
:score3 => 10.0,
|
129
|
+
:alive => true
|
130
|
+
}
|
131
|
+
|
132
|
+
@table.put(100 => data)
|
133
|
+
|
134
|
+
john = @table.get(100)
|
135
|
+
|
136
|
+
data.each do |k, v|
|
137
|
+
assert_equal v, john[k]
|
138
|
+
assert_equal v, john[k.to_s]
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_equal 20, john[:age]
|
142
|
+
assert_equal 10.0, john[:score3]
|
143
|
+
|
144
|
+
assert_equal data, john.to_h
|
145
|
+
assert_equal data, Hash[ john.to_H.map { |k, v| [k, v.first.last] } ]
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_schema_book
|
149
|
+
table = @table
|
150
|
+
|
151
|
+
@hbase.schema[table.name] = {
|
152
|
+
# Columns in cf1 family
|
153
|
+
:cf1 => {
|
154
|
+
:title => :string,
|
155
|
+
:author => :string,
|
156
|
+
:category => :string,
|
157
|
+
:year => :short,
|
158
|
+
:pages => :fixnum,
|
159
|
+
:price => :bigdecimal,
|
160
|
+
:weight => :float,
|
161
|
+
:in_print => :boolean
|
162
|
+
},
|
163
|
+
# Columns in cf2 family
|
164
|
+
:cf2 => {
|
165
|
+
:summary => :string,
|
166
|
+
:reviews => :fixnum,
|
167
|
+
:stars => :fixnum,
|
168
|
+
/^comment\d+/ => :string
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
# Put data (rowkey: 1)
|
173
|
+
data = {
|
174
|
+
:title => 'The Golden Bough: A Study of Magic and Religion',
|
175
|
+
:author => 'Sir James G. Frazer',
|
176
|
+
:category => 'Occult',
|
177
|
+
:year => 1890,
|
178
|
+
:pages => 1006,
|
179
|
+
:price => BigDecimal('21.50'),
|
180
|
+
:weight => 3.0,
|
181
|
+
:in_print => true,
|
182
|
+
:summary => 'A wide-ranging, comparative study of mythology and religion',
|
183
|
+
:reviews => 52,
|
184
|
+
:stars => 226,
|
185
|
+
:comment1 => 'A must-have',
|
186
|
+
:comment2 => 'Rewarding purchase'
|
187
|
+
}
|
188
|
+
table.put 1, data
|
189
|
+
|
190
|
+
# Get data (rowkey: 1)
|
191
|
+
book = table.get 1
|
192
|
+
|
193
|
+
assert_equal data, book.to_h
|
194
|
+
assert_equal data[:title], book['title']
|
195
|
+
assert_equal data[:comment2], book['comment2']
|
196
|
+
|
197
|
+
assert_equal true, book.to_H.values.map(&:keys).flatten.all? { |e| e.is_a? Fixnum }
|
198
|
+
|
199
|
+
# Scan table
|
200
|
+
table.range(0..100).
|
201
|
+
filter(:year => 1880...1900,
|
202
|
+
:in_print => true,
|
203
|
+
:category => ['Comics', 'Fiction', /cult/i],
|
204
|
+
:price => { :lt => BigDecimal('30.00') },
|
205
|
+
:summary => /myth/i).
|
206
|
+
project(:cf1, :reviews).
|
207
|
+
each do |book|
|
208
|
+
|
209
|
+
assert_equal data[:title], book[:title]
|
210
|
+
assert_equal data[:reviews], book[:reviews]
|
211
|
+
assert_equal nil, book[:summary]
|
212
|
+
|
213
|
+
# Update price
|
214
|
+
table.put book.rowkey => { :price => book[:price] + BigDecimal('1') }
|
215
|
+
|
216
|
+
# Atomic increment
|
217
|
+
table.increment book.rowkey, :reviews => 1, :stars => 5
|
218
|
+
end
|
219
|
+
|
220
|
+
assert_equal data[:price] + 1.0, table.get(1)[:price]
|
221
|
+
assert_equal data[:reviews] + 1, table.get(1)[:reviews]
|
222
|
+
assert_equal data[:stars] + 5, table.get(1)[:stars]
|
223
|
+
|
224
|
+
# Coprocessor
|
225
|
+
table.enable_aggregation!
|
226
|
+
table.put 2, :reviews => 100, :stars => 500
|
227
|
+
assert_equal data[:reviews] + 1 + data[:stars] + 5 + 100 + 500,
|
228
|
+
table.project(:reviews, :stars).aggregate(:sum)
|
229
|
+
#table.disable_aggregation!
|
230
|
+
|
231
|
+
# Undefined columns
|
232
|
+
table.put 1, 'cf1:x' => 1000
|
233
|
+
table.put 1, [:cf1, :y] => 2000
|
234
|
+
table.put 1, [:cf1, 2013] => 3000
|
235
|
+
assert_equal 1000, table.get(1).fixnum('cf1:x')
|
236
|
+
|
237
|
+
[
|
238
|
+
[:cf1, HBase::ByteArray['x']],
|
239
|
+
['cf1', HBase::ByteArray['x']],
|
240
|
+
[:cf1, :x],
|
241
|
+
[:cf1, 'x'],
|
242
|
+
['cf1', :x],
|
243
|
+
%w[cf1 x],
|
244
|
+
'cf1:x'
|
245
|
+
].each do |param|
|
246
|
+
assert_equal 1000, HBase::Util.from_bytes(:fixnum, table.get(1)[param])
|
247
|
+
assert_equal 1000, HBase::Util.from_bytes(:fixnum, table.get(1)[*param])
|
248
|
+
assert_equal 1000, HBase::Util.from_bytes(:fixnum, table.get(1).to_h[param])
|
249
|
+
end
|
250
|
+
|
251
|
+
assert_equal 2000, HBase::Util.from_bytes(:fixnum, table.get(1)[:cf1, :y])
|
252
|
+
assert_equal 3000, HBase::Util.from_bytes(:fixnum, table.get(1)[:cf1, 2013])
|
253
|
+
assert_equal 3000, HBase::Util.from_bytes(:fixnum, table.get(1)[[:cf1, 2013]])
|
254
|
+
assert_equal 3000, HBase::Util.from_bytes(:fixnum, table.get(1).to_h[[:cf1, HBase::ByteArray[2013]]])
|
255
|
+
assert_equal 3000, HBase::Util.from_bytes(:fixnum, table.get(1).to_h[[:cf1, 2013]])
|
256
|
+
|
257
|
+
# Delete :title column of book 1
|
258
|
+
table.delete 1, :title
|
259
|
+
assert_equal nil, table.get(1)[:title]
|
260
|
+
assert_equal data[:author], table.get(1)[:author]
|
261
|
+
|
262
|
+
# Delete column family
|
263
|
+
table.delete 1, :cf1
|
264
|
+
assert_equal nil, table.get(1)[:author]
|
265
|
+
assert_equal data[:summary], table.get(1)[:summary]
|
266
|
+
|
267
|
+
# Delete book 1
|
268
|
+
table.delete 1
|
269
|
+
assert_equal nil, table.get(1)
|
270
|
+
|
271
|
+
# Drop table for subsequent tests
|
272
|
+
table.drop!
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
data/test/test_scoped.rb
CHANGED
@@ -57,12 +57,12 @@ class TestScoped < TestHBaseJRubyBase
|
|
57
57
|
@table.put(i, 'cf1:a' => i, 'cf2:b' => i, 'cf3:c' => i * 3)
|
58
58
|
end
|
59
59
|
|
60
|
-
assert_instance_of HBase::Scoped, @table.
|
61
|
-
|
62
|
-
assert_equal scoped, scoped.each
|
60
|
+
assert_instance_of HBase::Scoped, @table.scoped
|
61
|
+
assert_instance_of Enumerator, @table.each
|
63
62
|
|
64
63
|
assert_equal 50, @table.count
|
65
64
|
assert_equal 50, @table.each.count
|
65
|
+
assert_equal 50, @table.each.take_while { true }.count
|
66
66
|
assert_equal 50, @table.to_a.length # each
|
67
67
|
|
68
68
|
# Start key
|
@@ -147,21 +147,25 @@ class TestScoped < TestHBaseJRubyBase
|
|
147
147
|
end
|
148
148
|
insert.call
|
149
149
|
|
150
|
-
assert_instance_of HBase::Scoped, @table.
|
150
|
+
assert_instance_of HBase::Scoped, @table.scoped
|
151
|
+
|
152
|
+
get_cols = lambda do |hsh|
|
153
|
+
hsh.keys.map { |e| [e[0], e[1].decode(:string)].join ':' }
|
154
|
+
end
|
151
155
|
|
152
156
|
# Test both for HBase::Table and HBase::Scoped
|
153
|
-
[@table, @table.
|
157
|
+
[@table, @table.scoped].each do |table|
|
154
158
|
# project
|
155
159
|
project_cols = ['cf1:a', 'cf3:c']
|
156
160
|
assert table.project(*project_cols).all? { |result|
|
157
|
-
result.
|
161
|
+
get_cols.call(result.to_h) == project_cols
|
158
162
|
}
|
159
163
|
|
160
164
|
# project: additive
|
161
|
-
assert_equal project_cols + ['cf3:d'], table.project(*project_cols).project('cf3:d').first.
|
165
|
+
assert_equal project_cols + ['cf3:d'], get_cols.call( table.project(*project_cols).project('cf3:d').first.to_h )
|
162
166
|
|
163
167
|
# project: family
|
164
|
-
assert_equal %w[cf1:a cf3:c cf3:d cf3:e], table.project('cf1:a', 'cf3').first.
|
168
|
+
assert_equal %w[cf1:a cf3:c cf3:d cf3:e], get_cols.call( table.project('cf1:a', 'cf3').first.to_h )
|
165
169
|
|
166
170
|
# filter: Hash
|
167
171
|
# to_a.length instead of count :)
|
@@ -189,16 +193,18 @@ class TestScoped < TestHBaseJRubyBase
|
|
189
193
|
# filter: Java filter
|
190
194
|
# Bug: https://issues.apache.org/jira/browse/HBASE-6954
|
191
195
|
import org.apache.hadoop.hbase.filter.ColumnPaginationFilter
|
192
|
-
assert_equal 3, table.filter(ColumnPaginationFilter.new(3, 1)).first.
|
196
|
+
assert_equal 3, table.filter(ColumnPaginationFilter.new(3, 1)).first.to_h.keys.length
|
193
197
|
|
194
198
|
# filter: Java filter list
|
195
199
|
import org.apache.hadoop.hbase.filter.FilterList
|
196
200
|
import org.apache.hadoop.hbase.filter.ColumnRangeFilter
|
197
201
|
assert_equal %w[cf2:b cf3:c],
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
+
get_cols.call(
|
203
|
+
table.filter(FilterList.new [
|
204
|
+
ColumnRangeFilter.new('a'.to_java_bytes, true, 'd'.to_java_bytes, true),
|
205
|
+
ColumnPaginationFilter.new(2, 1),
|
206
|
+
]).first.to_h
|
207
|
+
)
|
202
208
|
|
203
209
|
|
204
210
|
# limit with filter
|
@@ -212,10 +218,10 @@ class TestScoped < TestHBaseJRubyBase
|
|
212
218
|
end
|
213
219
|
|
214
220
|
insert.call
|
215
|
-
[@table, @table.
|
221
|
+
[@table, @table.scoped].each do |table|
|
216
222
|
# versions
|
217
|
-
assert table.all? { |result| result.
|
218
|
-
assert table.versions(1).all? { |result| result.
|
223
|
+
assert table.all? { |result| result.to_H[%w[cf1 a]].length == 2 }
|
224
|
+
assert table.versions(1).all? { |result| result.to_H[%w[cf1 a]].length == 1 }
|
219
225
|
end
|
220
226
|
end
|
221
227
|
|
@@ -233,7 +239,7 @@ class TestScoped < TestHBaseJRubyBase
|
|
233
239
|
@table.put rk.to_s, 'cf1:a' => rk
|
234
240
|
end
|
235
241
|
assert_equal 20, @table.range('1'..'9').count
|
236
|
-
assert_equal %w[1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9], @table.range('1'..'9').map
|
242
|
+
assert_equal %w[1 10 11 12 13 14 15 16 17 18 19 2 20 3 4 5 6 7 8 9], @table.range('1'..'9').map { |e| e.rowkey :string }
|
237
243
|
|
238
244
|
assert_equal 19, @table.range('1'...'9').count
|
239
245
|
|
@@ -249,21 +255,18 @@ class TestScoped < TestHBaseJRubyBase
|
|
249
255
|
end
|
250
256
|
|
251
257
|
def test_non_string_column_name
|
252
|
-
@table.put 'rowkey', Hash[ (1..20).map { |cq| [
|
258
|
+
@table.put 'rowkey', Hash[ (1..20).map { |cq| [['cf1', cq], cq] } ]
|
253
259
|
|
254
|
-
assert((1..20).all? { |cq| @table.get('rowkey').fixnum(
|
260
|
+
assert((1..20).all? { |cq| @table.get('rowkey').fixnum(['cf1', cq]) == cq })
|
255
261
|
|
256
262
|
assert @table.project(['cf1', 10], ['cf1', 20]).map { |r|
|
257
|
-
[r.fixnum(
|
263
|
+
[r.fixnum(['cf1', 10]), r.fixnum(['cf1', 20])]
|
258
264
|
}.all? { |e| e == [10, 20] }
|
259
265
|
|
260
|
-
hash = @table.get('rowkey').
|
261
|
-
|
262
|
-
|
263
|
-
)
|
264
|
-
assert_equal 1, hash[HBase::ColumnKey(:cf1, 1)]
|
265
|
-
assert_equal 2, hash[HBase::ColumnKey(:cf1, 2)]
|
266
|
-
assert_equal 3, HBase::Util.from_bytes(:fixnum, hash[HBase::ColumnKey(:cf1, 3)])
|
266
|
+
hash = @table.get('rowkey').to_h
|
267
|
+
assert_equal 1, HBase::Util.from_bytes(:fixnum, hash[[:cf1, 1]])
|
268
|
+
assert_equal 2, HBase::Util.from_bytes(:fixnum, hash[[:cf1, 2]])
|
269
|
+
assert_equal 3, HBase::Util.from_bytes(:fixnum, hash[[:cf1, 3]])
|
267
270
|
end
|
268
271
|
|
269
272
|
def test_table_descriptor
|
@@ -289,14 +292,14 @@ class TestScoped < TestHBaseJRubyBase
|
|
289
292
|
(1..100).each do |rk|
|
290
293
|
data = {}
|
291
294
|
(1..200).each do |cq|
|
292
|
-
data[
|
295
|
+
data[[:cf1, cq]] = rk + cq
|
293
296
|
end
|
294
297
|
all_data[rk] = data
|
295
298
|
end
|
296
299
|
@table.put all_data
|
297
300
|
|
298
301
|
# One simple filter (Rowkey 10 ~ 19)
|
299
|
-
scoped1 = @table.filter(
|
302
|
+
scoped1 = @table.filter(['cf1', 100] => 110...120)
|
300
303
|
ret = scoped1.get((1..100).to_a)
|
301
304
|
assert_equal 100, ret.count
|
302
305
|
assert_equal 10, ret.compact.count
|
@@ -304,7 +307,7 @@ class TestScoped < TestHBaseJRubyBase
|
|
304
307
|
# Two filters
|
305
308
|
scoped2 = scoped1.filter(
|
306
309
|
# Rowkey 10 ~ 19 & 9 ~ 14 = 10 ~ 14
|
307
|
-
|
310
|
+
['cf1', 1] => 10..15
|
308
311
|
)
|
309
312
|
ret = scoped2.get((1..100).to_a)
|
310
313
|
assert_equal 100, ret.count
|
data/test/test_table.rb
CHANGED
@@ -36,28 +36,28 @@ class TestTable < TestHBaseJRubyBase
|
|
36
36
|
def test_put_then_get
|
37
37
|
# Single record put
|
38
38
|
assert_equal 1, @table.put('row1',
|
39
|
-
'cf1:a'
|
40
|
-
'cf1:b'
|
41
|
-
'cf1:c'
|
42
|
-
'cf1:d'
|
43
|
-
'cf1:f'
|
44
|
-
'cf1:g'
|
45
|
-
'cf1:byte' => { :byte
|
39
|
+
'cf1:a' => 2,
|
40
|
+
'cf1:b' => 'b',
|
41
|
+
'cf1:c' => 6.28,
|
42
|
+
'cf1:d' => false,
|
43
|
+
'cf1:f' => :bol,
|
44
|
+
'cf1:g' => BigDecimal.new("456.123"),
|
45
|
+
'cf1:byte' => { :byte => 100 },
|
46
46
|
'cf1:short' => { :short => 200 },
|
47
|
-
'cf1:int' => { :int
|
48
|
-
'cf1:str1'
|
47
|
+
'cf1:int' => { :int => 300 },
|
48
|
+
'cf1:str1' => "Goodbye", 'cf1:str2' => "Cruel world")
|
49
49
|
assert_equal 1, @table.put('row1',
|
50
|
-
'cf1:a'
|
51
|
-
'cf1:b'
|
52
|
-
'cf1:c'
|
53
|
-
'cf1:d'
|
54
|
-
'cf1:f'
|
55
|
-
'cf1:g'
|
56
|
-
'cf1:byte' => { :byte
|
50
|
+
'cf1:a' => 1,
|
51
|
+
'cf1:b' => 'a',
|
52
|
+
'cf1:c' => 3.14,
|
53
|
+
'cf1:d' => true,
|
54
|
+
'cf1:f' => :sym,
|
55
|
+
'cf1:g' => BigDecimal.new("123.456"),
|
56
|
+
'cf1:byte' => { :byte => 101 },
|
57
57
|
'cf1:short' => { :short => 201 },
|
58
|
-
'cf1:int' => { :int
|
59
|
-
'cf1:int2' => { :int
|
60
|
-
'cf1:str1'
|
58
|
+
'cf1:int' => { :int => 301 },
|
59
|
+
'cf1:int2' => { :int => 401 },
|
60
|
+
'cf1:str1' => "Hello", 'cf1:str2' => "World")
|
61
61
|
# Batch put
|
62
62
|
assert_equal 2, @table.put(
|
63
63
|
'row2' => { 'cf1:a' => 2, 'cf1:b' => 'b', 'cf1:c' => 6.28 },
|
@@ -65,10 +65,12 @@ class TestTable < TestHBaseJRubyBase
|
|
65
65
|
|
66
66
|
# single-get (latest version)
|
67
67
|
result = @table.get('row1')
|
68
|
-
|
68
|
+
# Test enumerator
|
69
|
+
assert_equal result.to_a, result.each.each.to_a
|
70
|
+
assert_equal result.to_a, result.each.take_while { true }.to_a
|
69
71
|
|
70
|
-
assert_equal 'row1', @table.get('row1').rowkey
|
71
|
-
assert_equal 'row1', @table.get('row1').rowkey
|
72
|
+
assert_equal 'row1', @table.get('row1').rowkey(:string)
|
73
|
+
assert_equal 'row1', @table.get('row1').rowkey(:string)
|
72
74
|
assert_equal 1, @table.get('row1').fixnum('cf1:a')
|
73
75
|
assert_equal 'a', @table.get('row1').string('cf1:b')
|
74
76
|
assert_equal 'a', String.from_java_bytes(@table.get('row1').raw('cf1:b'))
|
@@ -80,9 +82,9 @@ class TestTable < TestHBaseJRubyBase
|
|
80
82
|
assert_equal 201, @table.get('row1').short('cf1:short')
|
81
83
|
assert_equal 301, @table.get('row1').int('cf1:int')
|
82
84
|
|
83
|
-
# single-get-multi-col
|
84
|
-
assert_equal %w[Hello World], @table.get('row1').string(['cf1:str1', 'cf1:str2'])
|
85
|
-
assert_equal [301, 401], @table.get('row1').int(['cf1:int', 'cf1:int2'])
|
85
|
+
# single-get-multi-col (deprecated since 0.3)
|
86
|
+
# assert_equal %w[Hello World], @table.get('row1').string(['cf1:str1', 'cf1:str2'])
|
87
|
+
# assert_equal [301, 401], @table.get('row1').int(['cf1:int', 'cf1:int2'])
|
86
88
|
|
87
89
|
# single-get-multi-ver
|
88
90
|
assert_equal [1, 2], @table.get('row1').fixnums('cf1:a').values
|
@@ -100,13 +102,13 @@ class TestTable < TestHBaseJRubyBase
|
|
100
102
|
|
101
103
|
assert @table.get('row1').fixnums('cf1:a').keys.all? { |k| k.instance_of? Fixnum }
|
102
104
|
|
103
|
-
# single-get-multi-col-multi=ver
|
104
|
-
rets = @table.get('row1').strings(['cf1:str1', 'cf1:str2'])
|
105
|
-
assert_equal ['Hello', 'World'], rets.map(&:values).map(&:first)
|
106
|
-
assert_equal ['Goodbye', 'Cruel world'], rets.map(&:values).map(&:last)
|
105
|
+
# single-get-multi-col-multi=ver (deprecated since 0.3)
|
106
|
+
# rets = @table.get('row1').strings(['cf1:str1', 'cf1:str2'])
|
107
|
+
# assert_equal ['Hello', 'World'], rets.map(&:values).map(&:first)
|
108
|
+
# assert_equal ['Goodbye', 'Cruel world'], rets.map(&:values).map(&:last)
|
107
109
|
|
108
110
|
# multi-get
|
109
|
-
assert_equal %w[row1 row2 row3], @table.get(['row1', 'row2', 'row3']).map { |r| r.rowkey }
|
111
|
+
assert_equal %w[row1 row2 row3], @table.get(['row1', 'row2', 'row3']).map { |r| r.rowkey :string }
|
110
112
|
assert_equal [1, 2, 4 ], @table.get(['row1', 'row2', 'row3']).map { |r| r.fixnum('cf1:a') }
|
111
113
|
assert_equal [3.14, 6.28, 6.28], @table.get(['row1', 'row2', 'row3']).map { |r| r.float('cf1:c') }
|
112
114
|
assert_equal [nil, nil ], @table.get(['xxx', 'yyy'])
|
@@ -154,54 +156,6 @@ class TestTable < TestHBaseJRubyBase
|
|
154
156
|
assert_equal ['B1'], @table.get(rowkey).strings('cf1:b').values
|
155
157
|
end
|
156
158
|
|
157
|
-
def test_to_hash
|
158
|
-
data = {
|
159
|
-
'cf1:a' => 'Hello',
|
160
|
-
'cf1:b' => 200,
|
161
|
-
'cf1:c' => 3.14,
|
162
|
-
'cf2:d' => :world,
|
163
|
-
'cf2:e' => false,
|
164
|
-
'cf3:f' => BigDecimal.new('1234567890123456789012345678901234567890'),
|
165
|
-
'cf3' => true
|
166
|
-
}
|
167
|
-
schema = {
|
168
|
-
'cf1:a' => :string,
|
169
|
-
'cf1:b' => :fixnum,
|
170
|
-
'cf1:c' => :float,
|
171
|
-
HBase::ColumnKey(:cf2, :d) => :symbol,
|
172
|
-
HBase::ColumnKey(:cf2, :e) => :boolean,
|
173
|
-
HBase::ColumnKey(:cf3, :f) => :bigdecimal,
|
174
|
-
'cf3' => :boolean
|
175
|
-
}
|
176
|
-
@table.put('row1', data)
|
177
|
-
@table.put('row2', 'cf1:a' => 'Goodbye')
|
178
|
-
|
179
|
-
assert_equal data, @table.get('row1').to_hash(schema).map { |k, v| { k.to_s => v } }.inject(:merge)
|
180
|
-
assert_equal 1, @table.get('row1').to_hash_with_versions(schema)['cf1:a'].length
|
181
|
-
assert_equal 1, @table.get('row1').to_hash_with_versions(schema)[HBase::ColumnKey(:cf1, :a)].length
|
182
|
-
|
183
|
-
# Better testing for versioned values
|
184
|
-
@table.put('row1', data)
|
185
|
-
assert_equal data, @table.get('row1').to_hash(schema).map { |k, v| { k.to_s => v } }.inject(:merge)
|
186
|
-
|
187
|
-
assert_equal 2, @table.get('row1').to_hash_with_versions(schema)['cf1:a'].length
|
188
|
-
assert_equal 1, @table.get('row1').to_hash_with_versions(schema)['cf3:f'].length
|
189
|
-
|
190
|
-
# get option: :versions
|
191
|
-
assert_equal 1, @table.versions(1).get('row1').to_hash_with_versions(schema)['cf1:a'].length
|
192
|
-
|
193
|
-
# scoped get with filters
|
194
|
-
assert_equal 2, @table.get(['row1', 'row2']).count
|
195
|
-
assert_equal 2, @table.range('row1'...'row2').get(['row1', 'row2']).count
|
196
|
-
assert_equal 2, @table.range('row1'..'row2').get(['row1', 'row2']).compact.count
|
197
|
-
assert_equal 1, @table.range('row1'...'row2').get(['row1', 'row2']).compact.count
|
198
|
-
assert_equal 1, @table.range(:prefix => 'row2').get(['row1', 'row2']).compact.count
|
199
|
-
assert_equal 1, @table.filter('cf1:a' => 'Hello').get(['row1', 'row2']).compact.count
|
200
|
-
|
201
|
-
# scoped get with projection
|
202
|
-
assert_equal %w[cf3 cf3:f], @table.project('cf3').get('row1').to_hash.keys.map(&:to_s)
|
203
|
-
end
|
204
|
-
|
205
159
|
def test_increment
|
206
160
|
@table.put('row1', 'cf1:counter' => 1, 'cf1:counter2' => 100)
|
207
161
|
assert_equal 1, @table.get('row1').fixnum('cf1:counter')
|
@@ -216,6 +170,15 @@ class TestTable < TestHBaseJRubyBase
|
|
216
170
|
@table.increment('row1', 'cf1:counter' => 4, 'cf1:counter2' => 100)
|
217
171
|
assert_equal 8, @table.get('row1').fixnum('cf1:counter')
|
218
172
|
assert_equal 200, @table.get('row1').fixnum('cf1:counter2')
|
173
|
+
|
174
|
+
# Multi-row multi-column increment
|
175
|
+
@table.put('row2', 'cf1:counter' => 1, 'cf1:counter2' => 100)
|
176
|
+
@table.increment 'row1' => { 'cf1:counter' => 4, 'cf1:counter2' => 100 },
|
177
|
+
'row2' => { 'cf1:counter' => 1, 'cf1:counter2' => 100 }
|
178
|
+
assert_equal 12, @table.get('row1').fixnum('cf1:counter')
|
179
|
+
assert_equal 300, @table.get('row1').fixnum('cf1:counter2')
|
180
|
+
assert_equal 2, @table.get('row2').fixnum('cf1:counter')
|
181
|
+
assert_equal 200, @table.get('row2').fixnum('cf1:counter2')
|
219
182
|
end
|
220
183
|
|
221
184
|
def test_delete
|
@@ -224,34 +187,34 @@ class TestTable < TestHBaseJRubyBase
|
|
224
187
|
@table.put('row1', 'cf2:d' => 5)
|
225
188
|
sleep 0.1
|
226
189
|
@table.put('row1', 'cf2:d' => 6)
|
227
|
-
versions = @table.get('row1').
|
190
|
+
versions = @table.get('row1').to_H[%w[cf2 d]].keys
|
228
191
|
assert versions[0] > versions[1]
|
229
192
|
assert versions[1] > versions[2]
|
230
193
|
|
231
194
|
# Deletes a version (Fixnum and Time as timestamps)
|
232
195
|
@table.delete('row1', 'cf2:d', versions[0], Time.at(versions[2] / 1000.0))
|
233
|
-
new_versions = @table.get('row1').
|
196
|
+
new_versions = @table.get('row1').to_H[%w[cf2 d]].keys
|
234
197
|
assert_equal new_versions, [versions[1]]
|
235
198
|
|
236
199
|
# Deletes a column
|
237
200
|
assert_equal 3, @table.get('row1').fixnum('cf2:c')
|
238
201
|
@table.delete('row1', 'cf2:c')
|
239
|
-
assert_nil @table.get('row1').
|
202
|
+
assert_nil @table.get('row1').to_h['cf2:c']
|
240
203
|
|
241
204
|
# Deletes a column with empty qualifier
|
242
205
|
assert_equal 0, @table.get('row1').fixnum('cf1')
|
243
206
|
@table.delete('row1', 'cf1:')
|
244
207
|
assert_equal 1, @table.get('row1').fixnum('cf1:a')
|
245
208
|
assert_equal 2, @table.get('row1').fixnum('cf1:b')
|
246
|
-
assert_nil @table.get('row1').
|
247
|
-
assert_nil @table.get('row1').
|
209
|
+
assert_nil @table.get('row1').to_h['cf1']
|
210
|
+
assert_nil @table.get('row1').to_h['cf1:']
|
248
211
|
|
249
212
|
# Deletes a column family
|
250
213
|
assert_equal 1, @table.get('row1').fixnum('cf1:a')
|
251
214
|
assert_equal 2, @table.get('row1').fixnum('cf1:b')
|
252
215
|
@table.delete('row1', 'cf1') # No trailing colon
|
253
|
-
assert_nil @table.get('row1').
|
254
|
-
assert_nil @table.get('row1').
|
216
|
+
assert_nil @table.get('row1').to_h['cf1:a']
|
217
|
+
assert_nil @table.get('row1').to_h['cf1:b']
|
255
218
|
|
256
219
|
# Deletes a row
|
257
220
|
@table.delete('row1')
|
@@ -263,7 +226,7 @@ class TestTable < TestHBaseJRubyBase
|
|
263
226
|
|
264
227
|
@table.delete ['row2'], ['row3', 'cf1:a']
|
265
228
|
assert_nil @table.get('row2')
|
266
|
-
assert_nil @table.get('row3').
|
229
|
+
assert_nil @table.get('row3').to_h['cf1:a']
|
267
230
|
assert_equal 2, @table.get('row3').fixnum('cf1:b')
|
268
231
|
end
|
269
232
|
|
data/test/test_table_admin.rb
CHANGED
@@ -205,8 +205,8 @@ class TestTableAdmin < TestHBaseJRubyBase
|
|
205
205
|
rprops = @table.raw_properties
|
206
206
|
assert_equal true.to_s, rprops['DEFERRED_LOG_FLUSH']
|
207
207
|
assert_equal false.to_s, rprops['READONLY']
|
208
|
-
assert_equal
|
209
|
-
assert_equal
|
208
|
+
assert_equal((64 * 1024 ** 2).to_s, rprops['MEMSTORE_FLUSHSIZE'])
|
209
|
+
assert_equal((512 * 1024 ** 2).to_s, rprops['MAX_FILESIZE'])
|
210
210
|
|
211
211
|
# Column family properties
|
212
212
|
cf = @table.families['cf']
|
@@ -278,7 +278,7 @@ class TestTableAdmin < TestHBaseJRubyBase
|
|
278
278
|
|
279
279
|
@hbase.snapshots.each do |snapshot|
|
280
280
|
assert_equal @table.name, snapshot[:table]
|
281
|
-
assert_match
|
281
|
+
assert_match(/hbase_jruby_test_snapshot[12]/, snapshot[:name])
|
282
282
|
end
|
283
283
|
|
284
284
|
@hbase.admin do |admin|
|