hbase-jruby 0.3.5-java → 0.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +13 -0
- data/README.md +135 -30
- data/lib/hbase-jruby/batch_exception.rb +12 -0
- data/lib/hbase-jruby/byte_array.rb +6 -0
- data/lib/hbase-jruby/dependency.rb +6 -4
- data/lib/hbase-jruby/row.rb +8 -2
- data/lib/hbase-jruby/schema.rb +2 -1
- data/lib/hbase-jruby/scoped.rb +7 -4
- data/lib/hbase-jruby/table/batch_action.rb +69 -0
- data/lib/hbase-jruby/table/checked_operation.rb +11 -8
- data/lib/hbase-jruby/table/mutation.rb +130 -0
- data/lib/hbase-jruby/table.rb +130 -82
- data/lib/hbase-jruby/version.rb +1 -1
- data/lib/hbase-jruby.rb +3 -0
- data/test/helper.rb +8 -1
- data/test/test_byte_array.rb +4 -0
- data/test/test_schema.rb +123 -67
- data/test/test_table.rb +266 -120
- metadata +5 -2
data/test/test_table.rb
CHANGED
@@ -34,8 +34,11 @@ class TestTable < TestHBaseJRubyBase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_put_then_get
|
37
|
+
row1 = next_rowkey.to_s
|
38
|
+
row2 = next_rowkey.to_s
|
39
|
+
row3 = next_rowkey.to_s
|
37
40
|
# Single record put
|
38
|
-
assert_equal 1, @table.put(
|
41
|
+
assert_equal 1, @table.put(row1,
|
39
42
|
'cf1:a' => 2,
|
40
43
|
'cf1:b' => 'b',
|
41
44
|
'cf1:c' => 6.28,
|
@@ -46,7 +49,7 @@ class TestTable < TestHBaseJRubyBase
|
|
46
49
|
'cf1:short' => { :short => 200 },
|
47
50
|
'cf1:int' => { :int => 300 },
|
48
51
|
'cf1:str1' => "Goodbye", 'cf1:str2' => "Cruel world")
|
49
|
-
assert_equal 1, @table.put(
|
52
|
+
assert_equal 1, @table.put(row1,
|
50
53
|
'cf1:a' => 1,
|
51
54
|
'cf1:b' => 'a',
|
52
55
|
'cf1:c' => 3.14,
|
@@ -60,66 +63,66 @@ class TestTable < TestHBaseJRubyBase
|
|
60
63
|
'cf1:str1' => "Hello", 'cf1:str2' => "World")
|
61
64
|
# Batch put
|
62
65
|
assert_equal 2, @table.put(
|
63
|
-
|
64
|
-
|
66
|
+
row2 => { 'cf1:a' => 2, 'cf1:b' => 'b', 'cf1:c' => 6.28 },
|
67
|
+
row3 => { 'cf1:a' => 4, 'cf1:b' => 'c', 'cf1:c' => 6.28 })
|
65
68
|
|
66
69
|
# single-get (latest version)
|
67
|
-
result = @table.get(
|
70
|
+
result = @table.get(row1)
|
68
71
|
# Test enumerator
|
69
72
|
assert_equal result.to_a, result.each.each.to_a
|
70
73
|
assert_equal result.to_a, result.each.take_while { true }.to_a
|
71
74
|
|
72
|
-
assert_equal
|
73
|
-
assert_equal
|
74
|
-
assert_equal 1, @table.get(
|
75
|
-
assert_equal 'a', @table.get(
|
76
|
-
assert_equal 'a', String.from_java_bytes(@table.get(
|
77
|
-
assert_equal 3.14, @table.get(
|
78
|
-
assert_equal true, @table.get(
|
79
|
-
assert_equal :sym, @table.get(
|
80
|
-
assert_equal BigDecimal.new("123.456"), @table.get(
|
81
|
-
assert_equal 101, @table.get(
|
82
|
-
assert_equal 201, @table.get(
|
83
|
-
assert_equal 301, @table.get(
|
75
|
+
assert_equal row1, @table.get(row1).rowkey(:string)
|
76
|
+
assert_equal row1, @table.get(row1).rowkey(:string)
|
77
|
+
assert_equal 1, @table.get(row1).fixnum('cf1:a')
|
78
|
+
assert_equal 'a', @table.get(row1).string('cf1:b')
|
79
|
+
assert_equal 'a', String.from_java_bytes(@table.get(row1).raw('cf1:b'))
|
80
|
+
assert_equal 3.14, @table.get(row1).float('cf1:c')
|
81
|
+
assert_equal true, @table.get(row1).boolean('cf1:d')
|
82
|
+
assert_equal :sym, @table.get(row1).symbol('cf1:f')
|
83
|
+
assert_equal BigDecimal.new("123.456"), @table.get(row1).bigdecimal('cf1:g')
|
84
|
+
assert_equal 101, @table.get(row1).byte('cf1:byte')
|
85
|
+
assert_equal 201, @table.get(row1).short('cf1:short')
|
86
|
+
assert_equal 301, @table.get(row1).int('cf1:int')
|
84
87
|
|
85
88
|
# single-get-multi-col (deprecated since 0.3)
|
86
|
-
# assert_equal %w[Hello World], @table.get(
|
87
|
-
# assert_equal [301, 401], @table.get(
|
89
|
+
# assert_equal %w[Hello World], @table.get(row1).string(['cf1:str1', 'cf1:str2'])
|
90
|
+
# assert_equal [301, 401], @table.get(row1).int(['cf1:int', 'cf1:int2'])
|
88
91
|
|
89
92
|
# single-get-multi-ver
|
90
|
-
assert_equal [1, 2], @table.get(
|
91
|
-
assert_equal %w[a b], @table.get(
|
92
|
-
assert_equal %w[a b], @table.get(
|
93
|
-
assert_equal [3.14, 6.28], @table.get(
|
94
|
-
assert_equal [true, false], @table.get(
|
95
|
-
assert_equal [:sym, :bol], @table.get(
|
93
|
+
assert_equal [1, 2], @table.get(row1).fixnums('cf1:a').values
|
94
|
+
assert_equal %w[a b], @table.get(row1).strings('cf1:b').values
|
95
|
+
assert_equal %w[a b], @table.get(row1).raws('cf1:b').values.map { |v| String.from_java_bytes v }
|
96
|
+
assert_equal [3.14, 6.28], @table.get(row1).floats('cf1:c').values
|
97
|
+
assert_equal [true, false], @table.get(row1).booleans('cf1:d').values
|
98
|
+
assert_equal [:sym, :bol], @table.get(row1).symbols('cf1:f').values
|
96
99
|
assert_equal [
|
97
100
|
BigDecimal.new("123.456"),
|
98
|
-
BigDecimal.new("456.123")], @table.get(
|
99
|
-
assert_equal [101, 100], @table.get(
|
100
|
-
assert_equal [201, 200], @table.get(
|
101
|
-
assert_equal [301, 300], @table.get(
|
101
|
+
BigDecimal.new("456.123")], @table.get(row1).bigdecimals('cf1:g').values
|
102
|
+
assert_equal [101, 100], @table.get(row1).bytes('cf1:byte').values
|
103
|
+
assert_equal [201, 200], @table.get(row1).shorts('cf1:short').values
|
104
|
+
assert_equal [301, 300], @table.get(row1).ints('cf1:int').values
|
102
105
|
|
103
|
-
assert @table.get(
|
106
|
+
assert @table.get(row1).fixnums('cf1:a').keys.all? { |k| k.instance_of? Fixnum }
|
104
107
|
|
105
108
|
# single-get-multi-col-multi=ver (deprecated since 0.3)
|
106
|
-
# rets = @table.get(
|
109
|
+
# rets = @table.get(row1).strings(['cf1:str1', 'cf1:str2'])
|
107
110
|
# assert_equal ['Hello', 'World'], rets.map(&:values).map(&:first)
|
108
111
|
# assert_equal ['Goodbye', 'Cruel world'], rets.map(&:values).map(&:last)
|
109
112
|
|
110
113
|
# multi-get
|
111
|
-
assert_equal
|
112
|
-
assert_equal [1, 2, 4 ], @table.get([
|
113
|
-
assert_equal [3.14, 6.28, 6.28], @table.get([
|
114
|
+
assert_equal [row1, row2, row3], @table.get([row1, row2, row3]).map { |r| r.rowkey :string }
|
115
|
+
assert_equal [1, 2, 4 ], @table.get([row1, row2, row3]).map { |r| r.fixnum('cf1:a') }
|
116
|
+
assert_equal [3.14, 6.28, 6.28], @table.get([row1, row2, row3]).map { |r| r.float('cf1:c') }
|
114
117
|
assert_equal [nil, nil ], @table.get(['xxx', 'yyy'])
|
115
118
|
|
116
119
|
# Unavailable columns
|
117
|
-
assert_equal nil, @table.get(
|
118
|
-
assert_equal nil, @table.get(
|
120
|
+
assert_equal nil, @table.get(row1).symbol('cf1:xxx')
|
121
|
+
assert_equal nil, @table.get(row1).fixnum('cf1:xxx')
|
119
122
|
|
120
123
|
# Unavailable columns (plural form)
|
121
|
-
assert_equal({}, @table.get(
|
122
|
-
assert_equal({}, @table.get(
|
124
|
+
assert_equal({}, @table.get(row1).strings('cf1:xxx'))
|
125
|
+
assert_equal({}, @table.get(row1).strings('cfx:xxx'))
|
123
126
|
|
124
127
|
# Row not found
|
125
128
|
assert_equal nil, @table.get('xxx')
|
@@ -128,19 +131,20 @@ class TestTable < TestHBaseJRubyBase
|
|
128
131
|
# Put added after a delete is overshadowed if its timestamp is older than than that of the tombstone
|
129
132
|
# https://issues.apache.org/jira/browse/HBASE-2847
|
130
133
|
def test_put_delete_put
|
134
|
+
rowkey = next_rowkey
|
131
135
|
pend("https://issues.apache.org/jira/browse/HBASE-2847") do
|
132
136
|
data = { 'cf1:pdp' => { 1250000000000 => 'A1' } }
|
133
|
-
@table.put
|
134
|
-
assert_equal 'A1', @table.get(
|
135
|
-
@table.delete
|
136
|
-
assert_nil @table.get(
|
137
|
-
@table.put
|
138
|
-
assert_equal 'A1', @table.get(
|
137
|
+
@table.put rowkey => data
|
138
|
+
assert_equal 'A1', @table.get(rowkey).string('cf1:pdp')
|
139
|
+
@table.delete rowkey
|
140
|
+
assert_nil @table.get(rowkey)
|
141
|
+
@table.put rowkey => data
|
142
|
+
assert_equal 'A1', @table.get(rowkey).string('cf1:pdp')
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
142
146
|
def test_put_timestamp
|
143
|
-
rowkey =
|
147
|
+
rowkey = next_rowkey
|
144
148
|
@table.put rowkey => {
|
145
149
|
'cf1:b' => 'B1',
|
146
150
|
'cf1:a' => {
|
@@ -157,103 +161,125 @@ class TestTable < TestHBaseJRubyBase
|
|
157
161
|
end
|
158
162
|
|
159
163
|
def test_increment
|
160
|
-
|
161
|
-
|
164
|
+
row1 = next_rowkey.to_s
|
165
|
+
row2 = next_rowkey.to_s
|
162
166
|
|
163
|
-
@table.
|
164
|
-
assert_equal
|
167
|
+
@table.put(row1, 'cf1:counter' => 1, 'cf1:counter2' => 100)
|
168
|
+
assert_equal 1, @table.get(row1).fixnum('cf1:counter')
|
165
169
|
|
166
|
-
@table.increment(
|
167
|
-
assert_equal
|
170
|
+
ret = @table.increment(row1, 'cf1:counter', 1)
|
171
|
+
assert_equal 2, ret['cf1:counter']
|
172
|
+
assert_equal 2, @table.get(row1).fixnum('cf1:counter')
|
173
|
+
|
174
|
+
ret = @table.increment(row1, 'cf1:counter', 2)
|
175
|
+
assert_equal 4, ret['cf1:counter']
|
176
|
+
assert_equal 4, @table.get(row1).fixnum('cf1:counter')
|
168
177
|
|
169
178
|
# Multi-column increment
|
170
|
-
@table.increment(
|
171
|
-
assert_equal 8,
|
172
|
-
assert_equal
|
179
|
+
ret = @table.increment(row1, 'cf1:counter' => 4, 'cf1:counter2' => 100)
|
180
|
+
assert_equal 8, ret['cf1:counter']
|
181
|
+
assert_equal 8, @table.get(row1).fixnum('cf1:counter')
|
182
|
+
assert_equal 200, ret['cf1:counter2']
|
183
|
+
assert_equal 200, ret[%w[cf1 counter2]]
|
184
|
+
assert_equal 200, @table.get(row1).fixnum('cf1:counter2')
|
173
185
|
|
174
186
|
# Multi-row multi-column increment
|
175
|
-
@table.put(
|
176
|
-
@table.increment
|
177
|
-
|
178
|
-
assert_equal 12,
|
179
|
-
assert_equal 300,
|
180
|
-
assert_equal 2,
|
181
|
-
assert_equal 200,
|
187
|
+
@table.put(row2, 'cf1:counter' => 1, 'cf1:counter2' => 100)
|
188
|
+
ret = @table.increment row1 => { 'cf1:counter' => 4, 'cf1:counter2' => 100 },
|
189
|
+
row2 => { 'cf1:counter' => 1, 'cf1:counter2' => 100 }
|
190
|
+
assert_equal 12, ret[row1]['cf1:counter']
|
191
|
+
assert_equal 300, ret[row1]['cf1:counter2']
|
192
|
+
assert_equal 2, ret[row2]['cf1:counter']
|
193
|
+
assert_equal 200, ret[row2]['cf1:counter2']
|
194
|
+
assert_equal 200, ret[row2][%w[cf1 counter2]]
|
195
|
+
assert_equal 12, @table.get(row1).fixnum('cf1:counter')
|
196
|
+
assert_equal 300, @table.get(row1).fixnum('cf1:counter2')
|
197
|
+
assert_equal 2, @table.get(row2).fixnum('cf1:counter')
|
198
|
+
assert_equal 200, @table.get(row2).fixnum('cf1:counter2')
|
182
199
|
end
|
183
200
|
|
184
201
|
def test_delete
|
185
|
-
|
202
|
+
row1 = next_rowkey.to_s
|
203
|
+
row2 = next_rowkey.to_s
|
204
|
+
row3 = next_rowkey.to_s
|
205
|
+
|
206
|
+
@table.put(row1, 'cf1:' => 0, 'cf1:a' => 1, 'cf1:b' => 2, 'cf2:c' => 3, 'cf2:d' => 4)
|
186
207
|
sleep 0.1
|
187
|
-
@table.put(
|
208
|
+
@table.put(row1, 'cf2:d' => 5)
|
188
209
|
sleep 0.1
|
189
|
-
@table.put(
|
190
|
-
versions = @table.get(
|
210
|
+
@table.put(row1, 'cf2:d' => 6)
|
211
|
+
versions = @table.get(row1).to_H[%w[cf2 d]].keys
|
191
212
|
assert versions[0] > versions[1]
|
192
213
|
assert versions[1] > versions[2]
|
193
214
|
|
194
215
|
# Deletes a version (Fixnum and Time as timestamps)
|
195
|
-
@table.delete(
|
196
|
-
new_versions = @table.get(
|
216
|
+
@table.delete(row1, 'cf2:d', versions[0], Time.at(versions[2] / 1000.0))
|
217
|
+
new_versions = @table.get(row1).to_H[%w[cf2 d]].keys
|
197
218
|
assert_equal new_versions, [versions[1]]
|
198
219
|
|
199
220
|
# Deletes a column
|
200
|
-
assert_equal 3, @table.get(
|
201
|
-
@table.delete(
|
202
|
-
assert_nil @table.get(
|
221
|
+
assert_equal 3, @table.get(row1).fixnum('cf2:c')
|
222
|
+
@table.delete(row1, 'cf2:c')
|
223
|
+
assert_nil @table.get(row1).to_h['cf2:c']
|
203
224
|
|
204
225
|
# Deletes a column with empty qualifier
|
205
|
-
assert_equal 0, @table.get(
|
206
|
-
@table.delete(
|
207
|
-
assert_equal 1, @table.get(
|
208
|
-
assert_equal 2, @table.get(
|
209
|
-
assert_nil @table.get(
|
210
|
-
assert_nil @table.get('row1').to_h['cf1:']
|
226
|
+
assert_equal 0, @table.get(row1).fixnum('cf1:')
|
227
|
+
@table.delete(row1, 'cf1:')
|
228
|
+
assert_equal 1, @table.get(row1).fixnum('cf1:a')
|
229
|
+
assert_equal 2, @table.get(row1).fixnum('cf1:b')
|
230
|
+
assert_nil @table.get(row1).to_h['cf1:']
|
211
231
|
|
212
232
|
# Deletes a column family
|
213
|
-
assert_equal 1, @table.get(
|
214
|
-
assert_equal 2, @table.get(
|
215
|
-
@table.delete(
|
216
|
-
assert_nil @table.get(
|
217
|
-
assert_nil @table.get(
|
233
|
+
assert_equal 1, @table.get(row1).fixnum('cf1:a')
|
234
|
+
assert_equal 2, @table.get(row1).fixnum('cf1:b')
|
235
|
+
@table.delete(row1, 'cf1') # No trailing colon
|
236
|
+
assert_nil @table.get(row1).to_h['cf1:a']
|
237
|
+
assert_nil @table.get(row1).to_h['cf1:b']
|
218
238
|
|
219
239
|
# Deletes a row
|
220
|
-
@table.delete(
|
221
|
-
assert_nil @table.get(
|
240
|
+
@table.delete(row1)
|
241
|
+
assert_nil @table.get(row1)
|
222
242
|
|
223
243
|
# Batch delete
|
224
|
-
@table.put(
|
225
|
-
@table.put(
|
244
|
+
@table.put(row2, 'cf1:a' => 1)
|
245
|
+
@table.put(row3, 'cf1:a' => 1, 'cf1:b' => 2)
|
226
246
|
|
227
|
-
@table.delete [
|
228
|
-
assert_nil @table.get(
|
229
|
-
assert_nil @table.get(
|
230
|
-
assert_equal 2, @table.get(
|
247
|
+
@table.delete [row2], [row3, 'cf1:a']
|
248
|
+
assert_nil @table.get(row2)
|
249
|
+
assert_nil @table.get(row3).to_h['cf1:a']
|
250
|
+
assert_equal 2, @table.get(row3).fixnum('cf1:b')
|
231
251
|
end
|
232
252
|
|
233
253
|
def test_delete_advanced
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
254
|
+
row1 = next_rowkey.to_s
|
255
|
+
drow = next_rowkey.to_s
|
256
|
+
|
257
|
+
@table.put(row1, 'cf1:' => 0, 'cf1:a' => 1, 'cf1:b' => 2, 'cf2:c' => 3, 'cf2:d' => 4)
|
258
|
+
@table.delete(row1, 'cf1:', 'cf1:b', 'cf2')
|
259
|
+
assert_equal 1, @table.get(row1).to_h.keys.length
|
260
|
+
assert_equal 1, @table.get(row1).fixnum('cf1:a')
|
238
261
|
|
239
262
|
ts = Time.now
|
240
|
-
@table.put(
|
263
|
+
@table.put(drow, 'cf1:a' => { 1000 => 1, 2000 => 2, 3000 => 3 },
|
241
264
|
'cf1:b' => { 4000 => 4, 5000 => 5, 6000 => 6 },
|
242
265
|
'cf2:c' => 3, 'cf2:d' => 4, 'cf3:e' => 5)
|
243
|
-
@table.delete(
|
266
|
+
@table.delete(drow, 'cf1:a', 1000, Time.at(2),
|
244
267
|
'cf2:c',
|
245
268
|
'cf1:b', 5000,
|
246
269
|
'cf3')
|
247
270
|
|
248
|
-
assert_equal 3, @table.get(
|
271
|
+
assert_equal 3, @table.get(drow).to_h.keys.length
|
249
272
|
|
250
|
-
assert_equal 1, @table.get(
|
251
|
-
assert_equal 2, @table.get(
|
252
|
-
assert_equal 3000, @table.get(
|
253
|
-
assert_equal [6000, 4000], @table.get(
|
273
|
+
assert_equal 1, @table.get(drow).to_H['cf1:a'].length
|
274
|
+
assert_equal 2, @table.get(drow).to_H['cf1:b'].length
|
275
|
+
assert_equal 3000, @table.get(drow).to_H['cf1:a'].keys.first
|
276
|
+
assert_equal [6000, 4000], @table.get(drow).to_H['cf1:b'].keys
|
254
277
|
end
|
255
278
|
|
256
279
|
def test_delete_advanced_with_schema
|
280
|
+
row1 = next_rowkey.to_s
|
281
|
+
drow = next_rowkey.to_s
|
282
|
+
|
257
283
|
@hbase.schema[@table.name] = {
|
258
284
|
:cf1 => {
|
259
285
|
:a => :int,
|
@@ -267,29 +293,29 @@ class TestTable < TestHBaseJRubyBase
|
|
267
293
|
:e => :fixnum
|
268
294
|
}
|
269
295
|
}
|
270
|
-
@table.put(
|
271
|
-
@table.delete(
|
272
|
-
assert_equal 1, @table.get(
|
273
|
-
assert_equal 1, @table.get(
|
274
|
-
assert_equal 1, @table.get(
|
296
|
+
@table.put(row1, 'cf1:' => 0, :a => 1, :b => 2, :c => 3, :d => 4)
|
297
|
+
@table.delete(row1, 'cf1:', :b, 'cf2')
|
298
|
+
assert_equal 1, @table.get(row1).to_h.keys.length
|
299
|
+
assert_equal 1, @table.get(row1).to_h[:a]
|
300
|
+
assert_equal 1, @table.get(row1).int(:a)
|
275
301
|
|
276
302
|
ts = Time.now
|
277
|
-
@table.put(
|
303
|
+
@table.put(drow, :a => { 1000 => 1, 2000 => 2, 3000 => 3 },
|
278
304
|
:b => { 4000 => 4, 5000 => 5, 6000 => 6 },
|
279
305
|
:c => 3,
|
280
306
|
:d => 4,
|
281
307
|
:e => 5)
|
282
|
-
@table.delete(
|
308
|
+
@table.delete(drow, :a, 1000, Time.at(2),
|
283
309
|
:c,
|
284
310
|
[:cf1, :b], 5000,
|
285
311
|
'cf3')
|
286
312
|
|
287
|
-
assert_equal 3, @table.get(
|
313
|
+
assert_equal 3, @table.get(drow).to_h.keys.length
|
288
314
|
|
289
|
-
assert_equal 1, @table.get(
|
290
|
-
assert_equal 2, @table.get(
|
291
|
-
assert_equal 3000, @table.get(
|
292
|
-
assert_equal [6000, 4000], @table.get(
|
315
|
+
assert_equal 1, @table.get(drow).to_H[:a].length
|
316
|
+
assert_equal 2, @table.get(drow).to_H[:b].length
|
317
|
+
assert_equal 3000, @table.get(drow).to_H[:a].keys.first
|
318
|
+
assert_equal [6000, 4000], @table.get(drow).to_H[:b].keys
|
293
319
|
end
|
294
320
|
|
295
321
|
def test_delete_row
|
@@ -324,17 +350,16 @@ class TestTable < TestHBaseJRubyBase
|
|
324
350
|
|
325
351
|
[
|
326
352
|
# Without schema
|
327
|
-
[
|
328
|
-
|
353
|
+
[next_rowkey, 'cf1:a', 'cf1:b', 'cf1:c'],
|
354
|
+
[next_rowkey, 'cf1:a', 'cf1:b', 'cf1:c'],
|
329
355
|
# With schema
|
330
|
-
[
|
331
|
-
|
356
|
+
[next_rowkey, :a, :b, :c],
|
357
|
+
[next_rowkey, :a, :b, :c],
|
332
358
|
].each do |args|
|
333
|
-
@table.delete_row 1
|
334
|
-
@table.put 1, 'cf1:a' => 100
|
335
|
-
|
336
359
|
rk, a, b, c = args
|
337
360
|
|
361
|
+
@table.put rk, 'cf1:a' => 100
|
362
|
+
|
338
363
|
# not nil
|
339
364
|
assert_equal false, @table.check(rk, a => 200).put(b => 300)
|
340
365
|
assert_equal nil, @table.get(rk).short(b)
|
@@ -366,7 +391,7 @@ class TestTable < TestHBaseJRubyBase
|
|
366
391
|
].each do |abcd|
|
367
392
|
a, b, c, d = abcd
|
368
393
|
|
369
|
-
rk =
|
394
|
+
rk = next_rowkey
|
370
395
|
ts = Time.now
|
371
396
|
@table.put rk, a => 100, b => 200,
|
372
397
|
c => { ts => 300, (ts - 1000) => 400, (ts - 2000).to_i => 500 },
|
@@ -395,5 +420,126 @@ class TestTable < TestHBaseJRubyBase
|
|
395
420
|
}
|
396
421
|
end
|
397
422
|
end
|
423
|
+
|
424
|
+
def test_append
|
425
|
+
rk = next_rowkey
|
426
|
+
@table.put rk, 'cf1:a' => 'hello', 'cf2:b' => 'foo'
|
427
|
+
result = @table.append rk, 'cf1:a' => ' world', 'cf2:b' => 'bar'
|
428
|
+
assert_equal 'hello world', result['cf1:a'].to_s
|
429
|
+
assert_equal 'foobar', result[%w[cf2 b]].to_s
|
430
|
+
assert_equal 'hello world', @table.get(rk).string('cf1:a')
|
431
|
+
assert_equal 'foobar', @table.get(rk).string('cf2:b')
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_mutate
|
435
|
+
rk = next_rowkey
|
436
|
+
@table.put rk,
|
437
|
+
'cf1:a' => 100, 'cf1:b' => 'hello', 'cf1:c' => 'hola',
|
438
|
+
'cf2:d' => 3.14
|
439
|
+
ret = @table.mutate(rk) { |m|
|
440
|
+
m.put 'cf1:a' => 200
|
441
|
+
m.delete 'cf1:c', 'cf2'
|
442
|
+
m.put 'cf1:z' => true
|
443
|
+
}
|
444
|
+
assert_equal nil, ret
|
445
|
+
|
446
|
+
row = @table.get(rk)
|
447
|
+
assert_equal 200, row.long('cf1:a')
|
448
|
+
assert_equal 'hello', row.string('cf1:b')
|
449
|
+
assert_equal nil, row.string('cf1:c')
|
450
|
+
assert_equal nil, row['cf1:c']
|
451
|
+
assert_equal true, row.boolean('cf1:z')
|
452
|
+
assert_equal nil, row.float('cf2:d')
|
453
|
+
assert_equal nil, row['cf2:d']
|
454
|
+
|
455
|
+
@table.mutate(rk) { |m| } # Nothing
|
456
|
+
@table.mutate(rk) { |m| m.delete }
|
457
|
+
assert_equal nil, @table.get(rk)
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_invalid_column_key
|
461
|
+
assert_raise(ArgumentError) {
|
462
|
+
@table.put next_rowkey, :some_column => 1
|
463
|
+
}
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_batch
|
467
|
+
rk1, rk2, rk3 = next_rowkey, next_rowkey, next_rowkey
|
468
|
+
|
469
|
+
ret = @table.batch { |b|
|
470
|
+
b.put rk1, 'cf1:a' => 1, 'cf1:b' => 2, 'cf2:c' => 'hello'
|
471
|
+
b.put rk2, 'cf1:a' => 2, 'cf1:b' => 3, 'cf2:c' => 'hello'
|
472
|
+
b.put rk3, 'cf1:a' => 3, 'cf1:b' => 4, 'cf2:c' => 'hello'
|
473
|
+
}
|
474
|
+
assert_equal 3, ret.length
|
475
|
+
assert_equal :put, ret[0][:type]
|
476
|
+
assert_equal :put, ret[1][:type]
|
477
|
+
assert_equal :put, ret[2][:type]
|
478
|
+
assert_equal true, ret[0][:result]
|
479
|
+
assert_equal true, ret[1][:result]
|
480
|
+
assert_equal true, ret[2][:result]
|
481
|
+
|
482
|
+
ret = @table.batch { |b|
|
483
|
+
b.put rk3, 'cf1:c' => 5
|
484
|
+
b.delete rk1, 'cf1:a'
|
485
|
+
b.increment rk2, 'cf1:a' => 10, 'cf1:b' => 20
|
486
|
+
b.append rk2, 'cf2:c' => ' world'
|
487
|
+
b.mutate(rk3) do |m|
|
488
|
+
m.put 'cf2:d' => 'hola'
|
489
|
+
m.put 'cf2:e' => 'mundo'
|
490
|
+
m.delete 'cf1:b'
|
491
|
+
end
|
492
|
+
b.get(rk1)
|
493
|
+
b.filter('cf1:a' => 0).get(rk1)
|
494
|
+
b.versions(1).project('cf2').get(rk1)
|
495
|
+
}
|
496
|
+
assert_equal 8, ret.length
|
497
|
+
assert_equal [:put, :delete, :increment, :append, :mutate, :get, :get, :get],
|
498
|
+
ret.map { |r| r[:type] }
|
499
|
+
assert_equal [true, true, true],
|
500
|
+
ret.values_at(0, 1, 4).map { |r| r[:result] }
|
501
|
+
assert_equal 12, ret[2][:result]['cf1:a']
|
502
|
+
assert_equal 23, ret[2][:result]['cf1:b']
|
503
|
+
assert_equal 'hello world', ret[3][:result]['cf2:c'].to_s
|
504
|
+
# assert_equal nil, ret[5][:result].long('cf1:a') # No guarantee
|
505
|
+
assert_equal 2, ret[5][:result].long('cf1:b')
|
506
|
+
assert_equal nil, ret[6][:result]
|
507
|
+
assert_equal nil, ret[7][:result].fixnum('cf1:b')
|
508
|
+
assert_equal 'hello', ret[7][:result].string('cf2:c')
|
509
|
+
|
510
|
+
assert_equal nil, @table.get(rk1)['cf1:a']
|
511
|
+
assert_equal 12, @table.get(rk2).long('cf1:a')
|
512
|
+
assert_equal 23, @table.get(rk2).long('cf1:b')
|
513
|
+
assert_equal 5, @table.get(rk3).long('cf1:c')
|
514
|
+
assert_equal 'hello world', @table.get(rk2).string('cf2:c')
|
515
|
+
assert_equal 'hola', @table.get(rk3).string('cf2:d')
|
516
|
+
assert_equal 'mundo', @table.get(rk3).string('cf2:e')
|
517
|
+
assert_equal nil, @table.get(rk3).string('cf2:b')
|
518
|
+
end
|
519
|
+
|
520
|
+
def test_batch_exception
|
521
|
+
rk = next_rowkey
|
522
|
+
@table.put rk, 'cf1:a' => 1
|
523
|
+
|
524
|
+
begin
|
525
|
+
@table.batch do |b|
|
526
|
+
b.put next_rowkey, 'cf1:a' => 1
|
527
|
+
b.put next_rowkey, 'cf100:a' => 1
|
528
|
+
b.get rk
|
529
|
+
b.put next_rowkey, 'cf200:a' => 1
|
530
|
+
end
|
531
|
+
assert false
|
532
|
+
rescue HBase::BatchException => e
|
533
|
+
assert_equal 4, e.results.length
|
534
|
+
assert_equal true, e.results[0][:result]
|
535
|
+
assert_equal false, e.results[1][:result]
|
536
|
+
assert_equal 1, e.results[2][:result].fixnum('cf1:a')
|
537
|
+
assert_equal false, e.results[3][:result]
|
538
|
+
|
539
|
+
assert e.results[1][:exception].is_a?(java.lang.Exception)
|
540
|
+
assert e.results[3][:exception].is_a?(java.lang.Exception)
|
541
|
+
assert e.java_exception.is_a?(java.lang.Exception)
|
542
|
+
end
|
543
|
+
end
|
398
544
|
end
|
399
545
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hbase-jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.5
|
5
4
|
prerelease:
|
5
|
+
version: 0.4.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-07-
|
12
|
+
date: 2013-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- hbase-jruby.gemspec
|
60
60
|
- lib/hbase-jruby.rb
|
61
61
|
- lib/hbase-jruby/admin.rb
|
62
|
+
- lib/hbase-jruby/batch_exception.rb
|
62
63
|
- lib/hbase-jruby/byte_array.rb
|
63
64
|
- lib/hbase-jruby/cell.rb
|
64
65
|
- lib/hbase-jruby/dependency.rb
|
@@ -70,8 +71,10 @@ files:
|
|
70
71
|
- lib/hbase-jruby/scoped/aggregation.rb
|
71
72
|
- lib/hbase-jruby/table.rb
|
72
73
|
- lib/hbase-jruby/table/admin.rb
|
74
|
+
- lib/hbase-jruby/table/batch_action.rb
|
73
75
|
- lib/hbase-jruby/table/checked_operation.rb
|
74
76
|
- lib/hbase-jruby/table/inspection.rb
|
77
|
+
- lib/hbase-jruby/table/mutation.rb
|
75
78
|
- lib/hbase-jruby/util.rb
|
76
79
|
- lib/hbase-jruby/version.rb
|
77
80
|
- test/helper.rb
|