hbase-jruby 0.1.6-java → 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +14 -0
- data/README.md +227 -94
- data/lib/hbase-jruby/admin.rb +3 -1
- data/lib/hbase-jruby/dependency.rb +37 -12
- data/lib/hbase-jruby/hbase.rb +53 -10
- data/lib/hbase-jruby/pom/pom.xml +1 -1
- data/lib/hbase-jruby/scoped.rb +40 -2
- data/lib/hbase-jruby/table/admin.rb +442 -0
- data/lib/hbase-jruby/table/inspection.rb +109 -0
- data/lib/hbase-jruby/table.rb +29 -388
- data/lib/hbase-jruby/util.rb +16 -1
- data/lib/hbase-jruby/version.rb +1 -1
- data/lib/hbase-jruby.rb +2 -0
- data/test/helper.rb +4 -7
- data/test/test_cell.rb +2 -2
- data/test/test_hbase.rb +10 -3
- data/test/test_scoped.rb +35 -0
- data/test/test_table.rb +36 -26
- data/test/test_table_admin.rb +118 -31
- metadata +4 -2
data/test/test_hbase.rb
CHANGED
@@ -6,15 +6,22 @@ require 'helper'
|
|
6
6
|
class TestHBase < TestHBaseJRubyBase
|
7
7
|
def test_tables
|
8
8
|
assert @hbase.table_names.include?(TABLE)
|
9
|
+
assert @hbase.list.include?(TABLE)
|
9
10
|
assert @hbase.tables.map(&:name).include?(TABLE)
|
10
11
|
end
|
11
12
|
|
12
13
|
def test_close
|
14
|
+
table = @hbase[TABLE]
|
15
|
+
table.exists?
|
16
|
+
assert @hbase.list.is_a?(Array)
|
17
|
+
|
18
|
+
assert !@hbase.closed?
|
13
19
|
@hbase.close
|
20
|
+
assert @hbase.closed?
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
|
22
|
+
assert_raise(RuntimeError) { @hbase.list }
|
23
|
+
assert_raise(RuntimeError) { table.exists? }
|
24
|
+
assert_raise(RuntimeError) { table.drop! }
|
18
25
|
end
|
19
26
|
|
20
27
|
def test_admin
|
data/test/test_scoped.rb
CHANGED
@@ -378,5 +378,40 @@ class TestScoped < TestHBaseJRubyBase
|
|
378
378
|
# Fails on 0.1.3
|
379
379
|
assert_equal 1, @table.range(:prefix => (HBase::ByteArray(50) + HBase::ByteArray(50)).java).count
|
380
380
|
end
|
381
|
+
|
382
|
+
def test_time_range_at
|
383
|
+
t1, t2, t3, t4 =
|
384
|
+
Time.now - 4000,
|
385
|
+
Time.now - 3000,
|
386
|
+
Time.now - 2000,
|
387
|
+
Time.now - 1000
|
388
|
+
@table.put :rowkey1 => { 'cf1:a' => { t1 => 1 } }
|
389
|
+
@table.put :rowkey2 => { 'cf1:a' => { t2 => 2 } }
|
390
|
+
@table.put :rowkey3 => { 'cf1:a' => { t3 => 3 } }
|
391
|
+
@table.put :rowkey4 => { 'cf1:a' => { t4 => 4 } }
|
392
|
+
|
393
|
+
assert_equal 1, @table.time_range(t2, t3).count
|
394
|
+
assert_equal 2, @table.time_range(t2, t3 + 1).count
|
395
|
+
assert_equal 2, @table.time_range(t2, t4).count
|
396
|
+
assert_equal 4, @table.time_range(0, t4 + 1).count
|
397
|
+
|
398
|
+
assert_equal [2, 3], @table.time_range(t2, t4).map { |r| r.fixnum 'cf1:a' }.sort
|
399
|
+
assert_equal %w[rowkey2 rowkey3], @table.time_range(t2, t4).map { |r| r.rowkey :string }.sort
|
400
|
+
|
401
|
+
assert_equal 1, @table.at(t2).count
|
402
|
+
assert_equal 0, @table.at(t2 - 1).count
|
403
|
+
assert_equal 0, @table.at(t2 + 1).count
|
404
|
+
assert_equal [2], @table.at(t2).map { |r| r.fixnum 'cf1:a' }
|
405
|
+
|
406
|
+
@table.put :rowkey5 => { 'cf1:a' => { t1 => 'a', t4 => 'A' }, 'cf1:b' => { t4 => 'B' }}
|
407
|
+
assert_equal 'A', @table.get(:rowkey5).string('cf1:a')
|
408
|
+
assert_equal 'B', @table.get(:rowkey5).string('cf1:b')
|
409
|
+
|
410
|
+
assert_equal 'a', @table.time_range(t1, t3).get(:rowkey5).string('cf1:a')
|
411
|
+
assert_equal nil, @table.time_range(t1, t3).get(:rowkey5).string('cf1:b')
|
412
|
+
|
413
|
+
# according to current hbase impl, later call overrides the previous time ranges. but, why do this?
|
414
|
+
assert_equal 2, @table.time_range(t2, t3).at(t1).count
|
415
|
+
end
|
381
416
|
end
|
382
417
|
|
data/test/test_table.rb
CHANGED
@@ -4,23 +4,33 @@ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
|
4
4
|
require 'helper'
|
5
5
|
require 'bigdecimal'
|
6
6
|
|
7
|
-
class
|
8
|
-
def
|
7
|
+
class TestTable < TestHBaseJRubyBase
|
8
|
+
def test_table_block
|
9
9
|
@hbase.table(TABLE) do |table|
|
10
10
|
assert_equal TABLE, table.name
|
11
11
|
assert table.exists?
|
12
12
|
end
|
13
|
+
end
|
13
14
|
|
15
|
+
def test_table_htable
|
16
|
+
htables = []
|
14
17
|
table = @hbase.table(TABLE)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
table.close
|
18
|
+
4.times do
|
19
|
+
htables << table.htable
|
20
|
+
end
|
21
|
+
assert_equal 1, htables.uniq.length
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
# Multi-threaded
|
24
|
+
htables = []
|
25
|
+
table = @hbase.table(TABLE)
|
26
|
+
4.times do
|
27
|
+
Thread.new {
|
28
|
+
htables << table.htable
|
29
|
+
}.join
|
23
30
|
end
|
31
|
+
assert_equal 4, htables.uniq.length
|
32
|
+
|
33
|
+
assert_equal @hbase.table(TABLE).htable, @hbase[TABLE].htable
|
24
34
|
end
|
25
35
|
|
26
36
|
def test_put_then_get
|
@@ -75,18 +85,18 @@ class TestScoped < TestHBaseJRubyBase
|
|
75
85
|
assert_equal [301, 401], @table.get('row1').int(['cf1:int', 'cf1:int2'])
|
76
86
|
|
77
87
|
# single-get-multi-ver
|
78
|
-
assert_equal [1, 2],
|
79
|
-
assert_equal %w[a b],
|
80
|
-
assert_equal %w[a b],
|
81
|
-
assert_equal [3.14, 6.28],
|
82
|
-
assert_equal [true, false],
|
83
|
-
assert_equal [:sym, :bol],
|
88
|
+
assert_equal [1, 2], @table.get('row1').fixnums('cf1:a').values
|
89
|
+
assert_equal %w[a b], @table.get('row1').strings('cf1:b').values
|
90
|
+
assert_equal %w[a b], @table.get('row1').raws('cf1:b').values.map { |v| String.from_java_bytes v }
|
91
|
+
assert_equal [3.14, 6.28], @table.get('row1').floats('cf1:c').values
|
92
|
+
assert_equal [true, false], @table.get('row1').booleans('cf1:d').values
|
93
|
+
assert_equal [:sym, :bol], @table.get('row1').symbols('cf1:f').values
|
84
94
|
assert_equal [
|
85
95
|
BigDecimal.new("123.456"),
|
86
96
|
BigDecimal.new("456.123")], @table.get('row1').bigdecimals('cf1:g').values
|
87
|
-
assert_equal [101, 100],
|
88
|
-
assert_equal [201, 200],
|
89
|
-
assert_equal [301, 300],
|
97
|
+
assert_equal [101, 100], @table.get('row1').bytes('cf1:byte').values
|
98
|
+
assert_equal [201, 200], @table.get('row1').shorts('cf1:short').values
|
99
|
+
assert_equal [301, 300], @table.get('row1').ints('cf1:int').values
|
90
100
|
|
91
101
|
assert @table.get('row1').fixnums('cf1:a').keys.all? { |k| k.instance_of? Fixnum }
|
92
102
|
|
@@ -102,15 +112,15 @@ class TestScoped < TestHBaseJRubyBase
|
|
102
112
|
assert_equal [nil, nil ], @table.get(['xxx', 'yyy'])
|
103
113
|
|
104
114
|
# Unavailable columns
|
105
|
-
assert_equal nil,
|
106
|
-
assert_equal nil,
|
115
|
+
assert_equal nil, @table.get('row1').symbol('cf1:xxx')
|
116
|
+
assert_equal nil, @table.get('row1').fixnum('cf1:xxx')
|
107
117
|
|
108
118
|
# Unavailable columns (plural form)
|
109
|
-
assert_equal({},
|
110
|
-
assert_equal({},
|
119
|
+
assert_equal({}, @table.get('row1').strings('cf1:xxx'))
|
120
|
+
assert_equal({}, @table.get('row1').strings('cfx:xxx'))
|
111
121
|
|
112
122
|
# Row not found
|
113
|
-
assert_equal nil,
|
123
|
+
assert_equal nil, @table.get('xxx')
|
114
124
|
end
|
115
125
|
|
116
126
|
# Put added after a delete is overshadowed if its timestamp is older than than that of the tombstone
|
@@ -134,7 +144,7 @@ class TestScoped < TestHBaseJRubyBase
|
|
134
144
|
'cf1:a' => {
|
135
145
|
1250000000000 => 'A1',
|
136
146
|
1260000000000 => 'A2',
|
137
|
-
|
147
|
+
Time.at(1270000000) => 'A3', # Ruby Time support
|
138
148
|
},
|
139
149
|
}
|
140
150
|
|
@@ -218,8 +228,8 @@ class TestScoped < TestHBaseJRubyBase
|
|
218
228
|
assert versions[0] > versions[1]
|
219
229
|
assert versions[1] > versions[2]
|
220
230
|
|
221
|
-
# Deletes a version
|
222
|
-
@table.delete('row1', 'cf2:d', versions[0], versions[2])
|
231
|
+
# Deletes a version (Fixnum and Time as timestamps)
|
232
|
+
@table.delete('row1', 'cf2:d', versions[0], Time.at(versions[2] / 1000.0))
|
223
233
|
new_versions = @table.get('row1').to_hash_with_versions['cf2:d'].keys
|
224
234
|
assert_equal new_versions, [versions[1]]
|
225
235
|
|
data/test/test_table_admin.rb
CHANGED
@@ -11,11 +11,25 @@ class TestTableAdmin < TestHBaseJRubyBase
|
|
11
11
|
def test_create_table_symbol_string
|
12
12
|
t = @hbase.table(:test_hbase_jruby_create_table)
|
13
13
|
t.drop! if t.exists?
|
14
|
+
|
15
|
+
assert_raise(ArgumentError) do
|
16
|
+
t.create! :cf, :splits => :xxx
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_raise(ArgumentError) do
|
20
|
+
t.create! :cf => { 1 => 2 }
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_raise(ArgumentError) do
|
24
|
+
t.create! :cf, { 1 => 2 }
|
25
|
+
end
|
26
|
+
|
14
27
|
[ :cf, 'cf', {:cf => {}} ].each do |cf|
|
15
28
|
assert_false t.exists?
|
16
29
|
t.create! cf
|
17
30
|
assert t.exists?
|
18
31
|
t.drop!
|
32
|
+
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
@@ -78,6 +92,10 @@ class TestTableAdmin < TestHBaseJRubyBase
|
|
78
92
|
assert_raise(ArgumentError) do
|
79
93
|
@table.alter! :hello => :world
|
80
94
|
end
|
95
|
+
assert_raise(ArgumentError) do
|
96
|
+
# Splits not allowed
|
97
|
+
@table.alter! :readonly => :true, :splits => [1, 2, 3]
|
98
|
+
end
|
81
99
|
|
82
100
|
max_fs = 512 * 1024 ** 2
|
83
101
|
mem_fs = 64 * 1024 ** 2
|
@@ -138,39 +156,108 @@ class TestTableAdmin < TestHBaseJRubyBase
|
|
138
156
|
@table.drop!
|
139
157
|
end
|
140
158
|
|
141
|
-
def
|
159
|
+
def test_inspection
|
160
|
+
assert @table.inspect.is_a?(String)
|
142
161
|
@table.drop!
|
143
|
-
assert
|
144
|
-
|
145
|
-
@table.create! :cf => {
|
146
|
-
:blockcache => true,
|
147
|
-
:blocksize => 128 * 1024,
|
148
|
-
:bloomfilter => :row,
|
149
|
-
:compression => :gzip,
|
150
|
-
# :data_block_encoding => org.apache.hadoop.hbase.io.encoding.DataBlockEncoding::DIFF,
|
151
|
-
# :encode_on_disk => true,
|
152
|
-
# :keep_deleted_cells => true,
|
153
|
-
:in_memory => true,
|
154
|
-
:min_versions => 5,
|
155
|
-
:replication_scope => 0,
|
156
|
-
:ttl => 100,
|
157
|
-
:versions => 10,
|
158
|
-
}
|
159
|
-
props = eval @table.inspect.gsub(/([A-Z_]+) =>/) { ":#{$1.downcase} =>" }
|
160
|
-
assert_equal TABLE, props[:name]
|
161
|
-
cf = props[:families].first
|
162
|
-
assert_equal 'cf', cf[:name]
|
163
|
-
assert_equal 'ROW', cf[:bloomfilter]
|
164
|
-
assert_equal '0', cf[:replication_scope]
|
165
|
-
assert_equal '10', cf[:versions]
|
166
|
-
assert_equal 'GZIP', cf[:compression]
|
167
|
-
assert_equal '5', cf[:min_versions]
|
168
|
-
assert_equal '100', cf[:ttl]
|
169
|
-
assert_equal '131072', cf[:blocksize]
|
170
|
-
assert_equal 'true', cf[:in_memory]
|
171
|
-
assert_equal 'true', cf[:blockcache]
|
162
|
+
assert @table.inspect.is_a?(String)
|
172
163
|
|
173
|
-
|
164
|
+
[
|
165
|
+
'GZ',
|
166
|
+
:gz,
|
167
|
+
org.apache.hadoop.hbase.io.hfile.Compression::Algorithm::GZ
|
168
|
+
].each do |cmp|
|
169
|
+
@table.create!({
|
170
|
+
:cf => {
|
171
|
+
:blockcache => true,
|
172
|
+
:blocksize => 128 * 1024,
|
173
|
+
:bloomfilter => :row, # as Symbol
|
174
|
+
:compression => cmp, # as String, Symbol, java.lang.Enum
|
175
|
+
:compression_compact => cmp, # as String, Symbol, java.lang.Enum
|
176
|
+
# TODO
|
177
|
+
# :data_block_encoding => :diff,
|
178
|
+
# :encode_on_disk => true,
|
179
|
+
# :keep_deleted_cells => true,
|
180
|
+
:in_memory => true,
|
181
|
+
:min_versions => 5,
|
182
|
+
:replication_scope => 0,
|
183
|
+
:ttl => 100,
|
184
|
+
:versions => 10,
|
185
|
+
}
|
186
|
+
},
|
187
|
+
:max_filesize => 512 * 1024 ** 2,
|
188
|
+
:memstore_flushsize => 64 * 1024 ** 2,
|
189
|
+
:readonly => false,
|
190
|
+
:deferred_log_flush => true,
|
191
|
+
:splits => [10, 20, 30, 40]
|
192
|
+
)
|
193
|
+
|
194
|
+
# Initial region count
|
195
|
+
regions = @table.regions
|
196
|
+
assert_equal 5, regions.count
|
197
|
+
|
198
|
+
# Table properties
|
199
|
+
props = @table.properties
|
200
|
+
assert_equal true, props[:deferred_log_flush]
|
201
|
+
assert_equal false, props[:readonly]
|
202
|
+
assert_equal 64 * 1024 ** 2, props[:memstore_flushsize]
|
203
|
+
assert_equal 512 * 1024 ** 2, props[:max_filesize]
|
204
|
+
|
205
|
+
rprops = @table.raw_properties
|
206
|
+
assert_equal true.to_s, rprops['DEFERRED_LOG_FLUSH']
|
207
|
+
assert_equal false.to_s, rprops['READONLY']
|
208
|
+
assert_equal (64 * 1024 ** 2).to_s, rprops['MEMSTORE_FLUSHSIZE']
|
209
|
+
assert_equal (512 * 1024 ** 2).to_s, rprops['MAX_FILESIZE']
|
210
|
+
|
211
|
+
# Column family properties
|
212
|
+
cf = @table.families['cf']
|
213
|
+
assert_equal 'ROW', cf[:bloomfilter]
|
214
|
+
assert_equal 0, cf[:replication_scope]
|
215
|
+
assert_equal 10, cf[:versions]
|
216
|
+
assert_equal 'GZ', cf[:compression]
|
217
|
+
assert_equal 5, cf[:min_versions]
|
218
|
+
assert_equal 100, cf[:ttl]
|
219
|
+
assert_equal 131072, cf[:blocksize]
|
220
|
+
assert_equal true, cf[:in_memory]
|
221
|
+
assert_equal true, cf[:blockcache]
|
222
|
+
|
223
|
+
rcf = @table.raw_families['cf']
|
224
|
+
assert_equal 'ROW', rcf['BLOOMFILTER']
|
225
|
+
assert_equal 0.to_s, rcf['REPLICATION_SCOPE']
|
226
|
+
assert_equal 10.to_s, rcf['VERSIONS']
|
227
|
+
assert_equal 'GZ', rcf['COMPRESSION']
|
228
|
+
assert_equal 5.to_s, rcf['MIN_VERSIONS']
|
229
|
+
assert_equal 100.to_s, rcf['TTL']
|
230
|
+
assert_equal 131072.to_s, rcf['BLOCKSIZE']
|
231
|
+
assert_equal true.to_s, rcf['IN_MEMORY']
|
232
|
+
assert_equal true.to_s, rcf['BLOCKCACHE']
|
233
|
+
|
234
|
+
@table.put 31, 'cf:a' => 100
|
235
|
+
@table.put 37, 'cf:a' => 100
|
236
|
+
@table.split!(35)
|
237
|
+
|
238
|
+
# FIXME
|
239
|
+
10.times do |i|
|
240
|
+
break if @table.regions.count == 6
|
241
|
+
sleep 1
|
242
|
+
assert false, "Region not split" if i == 9
|
243
|
+
end
|
244
|
+
|
245
|
+
@table.put 39, 'cf:a' => 100
|
246
|
+
@table.split!(38)
|
247
|
+
|
248
|
+
# FIXME
|
249
|
+
10.times do |i|
|
250
|
+
break if @table.regions.count == 7
|
251
|
+
sleep 1
|
252
|
+
assert false, "Region not split" if i == 9
|
253
|
+
end
|
254
|
+
|
255
|
+
regions = @table.regions
|
256
|
+
assert_equal [10, 20, 30, 35, 38, 40], regions.map { |r| HBase::Util.from_bytes :fixnum, r[:start_key] }.compact.sort
|
257
|
+
assert_equal [10, 20, 30, 35, 38, 40], regions.map { |r| HBase::Util.from_bytes :fixnum, r[:end_key] }.compact.sort
|
258
|
+
|
259
|
+
@table.drop!
|
260
|
+
end
|
174
261
|
end
|
175
262
|
end unless ENV['HBASE_JRUBY_TEST_SKIP_ADMIN']
|
176
263
|
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: hbase-jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Junegunn Choi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -73,6 +73,8 @@ files:
|
|
73
73
|
- lib/hbase-jruby/scoped.rb
|
74
74
|
- lib/hbase-jruby/scoped/aggregation.rb
|
75
75
|
- lib/hbase-jruby/table.rb
|
76
|
+
- lib/hbase-jruby/table/admin.rb
|
77
|
+
- lib/hbase-jruby/table/inspection.rb
|
76
78
|
- lib/hbase-jruby/util.rb
|
77
79
|
- lib/hbase-jruby/version.rb
|
78
80
|
- test/helper.rb
|