hbase-jruby 0.6.4-java → 0.7.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +68 -72
- data/hbase-jruby.gemspec +1 -1
- data/lib/hbase-jruby/cell.rb +7 -2
- data/lib/hbase-jruby/dependency.rb +77 -194
- data/lib/hbase-jruby/hbase.rb +33 -20
- data/lib/hbase-jruby/row.rb +37 -21
- data/lib/hbase-jruby/schema.rb +6 -4
- data/lib/hbase-jruby/scoped.rb +4 -4
- data/lib/hbase-jruby/table/admin.rb +71 -81
- data/lib/hbase-jruby/table/checked_operation.rb +1 -1
- data/lib/hbase-jruby/table/inspection.rb +1 -0
- data/lib/hbase-jruby/table.rb +20 -4
- data/lib/hbase-jruby/util.rb +14 -17
- data/lib/hbase-jruby/version.rb +1 -1
- data/lib/hbase-jruby.rb +1 -1
- data/test/helper.rb +3 -6
- data/test/test_aggregation.rb +17 -17
- data/test/test_byte_array.rb +9 -9
- data/test/test_cell.rb +3 -2
- data/test/test_hbase.rb +13 -13
- data/test/test_schema.rb +9 -9
- data/test/test_scoped.rb +82 -79
- data/test/test_table.rb +31 -18
- data/test/test_table_admin.rb +140 -130
- data/test/test_util.rb +16 -11
- metadata +12 -11
data/lib/hbase-jruby/hbase.rb
CHANGED
@@ -5,12 +5,16 @@ require 'thread'
|
|
5
5
|
# @author Junegunn Choi <junegunn.c@gmail.com>
|
6
6
|
# @!attribute [r] config
|
7
7
|
# @return [org.apache.hadoop.conf.Configuration]
|
8
|
+
# @!attribute [r] schema
|
9
|
+
# @return [HBase::Schema]
|
8
10
|
class HBase
|
9
11
|
attr_reader :config, :schema
|
10
12
|
|
11
13
|
include Admin
|
12
14
|
include HBase::Util
|
13
15
|
|
16
|
+
DEFAULT_COLUMN_CACHE_SIZE = 200
|
17
|
+
|
14
18
|
# @overload HBase.log4j=(filename)
|
15
19
|
# Configure Log4j logging with the given file
|
16
20
|
# @param [String] filename Path to log4j.properties or log4j.xml file
|
@@ -24,41 +28,43 @@ class HBase
|
|
24
28
|
# @param [java.util.Properties] props Properties object
|
25
29
|
# @return [java.util.Properties]
|
26
30
|
def self.log4j= arg
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
props
|
31
|
-
arg.each do |k, v|
|
32
|
-
props.setProperty k.to_s, v.to_s
|
33
|
-
end
|
34
|
-
org.apache.log4j.PropertyConfigurator.configure props
|
35
|
-
else
|
36
|
-
case File.extname(arg).downcase
|
37
|
-
when '.xml'
|
38
|
-
org.apache.log4j.xml.DOMConfigurator.configure arg
|
39
|
-
else
|
40
|
-
org.apache.log4j.PropertyConfigurator.configure arg
|
41
|
-
end
|
31
|
+
if arg.is_a?(Hash)
|
32
|
+
props = java.util.Properties.new
|
33
|
+
arg.each do |k, v|
|
34
|
+
props.setProperty k.to_s, v.to_s
|
42
35
|
end
|
36
|
+
org.apache.log4j.PropertyConfigurator.configure props
|
43
37
|
else
|
44
|
-
|
38
|
+
case File.extname(arg).downcase
|
39
|
+
when '.xml'
|
40
|
+
org.apache.log4j.xml.DOMConfigurator.configure arg
|
41
|
+
else
|
42
|
+
org.apache.log4j.PropertyConfigurator.configure arg
|
43
|
+
end
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
47
|
# Connects to HBase
|
49
|
-
# @
|
48
|
+
# @overload initialize(zookeeper_quorum)
|
49
|
+
# @param [String] zookeeper_quorum hbase.zookeeper.quorum
|
50
|
+
# @overload initialize(config)
|
51
|
+
# @param [Hash] config A key-value pairs to build HBaseConfiguration from
|
50
52
|
def initialize config = {}
|
51
53
|
begin
|
52
54
|
org.apache.hadoop.conf.Configuration
|
53
55
|
rescue NameError
|
54
56
|
raise NameError.new(
|
55
|
-
"Required Java classes not loaded. Set up CLASSPATH
|
57
|
+
"Required Java classes not loaded. Set up CLASSPATH.`")
|
56
58
|
end
|
57
59
|
|
58
60
|
HBase.import_java_classes!
|
59
61
|
|
60
62
|
@config =
|
61
63
|
case config
|
64
|
+
when String
|
65
|
+
HBaseConfiguration.create.tap do |hbcfg|
|
66
|
+
hbcfg.set 'hbase.zookeeper.quorum', config
|
67
|
+
end
|
62
68
|
when org.apache.hadoop.conf.Configuration
|
63
69
|
config
|
64
70
|
else
|
@@ -146,12 +152,19 @@ class HBase
|
|
146
152
|
# Creates an HBase::Table instance for the specified name
|
147
153
|
# @param [#to_s] table_name The name of the table
|
148
154
|
# @param [Hash] opts Options
|
149
|
-
# @option opts [
|
155
|
+
# @option opts [Fixnum] :column_cache The size of thread-local column-key
|
156
|
+
# interpretation cache (default: 200)
|
150
157
|
# @return [HBase::Table]
|
151
158
|
def table table_name, opts = {}
|
152
159
|
check_closed
|
153
160
|
|
154
|
-
|
161
|
+
# Backward-compatibility (to be removed)
|
162
|
+
if opts.has_key?(:cache)
|
163
|
+
opts = { :column_cache => opts[:cache] ? DEFAULT_COLUMN_CACHE_SIZE : 0 }
|
164
|
+
end
|
165
|
+
|
166
|
+
ht = HBase::Table.send :new, self, @config,
|
167
|
+
table_name, opts.fetch(:column_cache, DEFAULT_COLUMN_CACHE_SIZE)
|
155
168
|
|
156
169
|
if block_given?
|
157
170
|
yield ht
|
data/lib/hbase-jruby/row.rb
CHANGED
@@ -130,7 +130,7 @@ class Row
|
|
130
130
|
alias str string
|
131
131
|
|
132
132
|
# Returns all versions of column values as Strings in a Hash indexed by their timestamps
|
133
|
-
# @param [String, Array]
|
133
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
134
134
|
# @return [Hash<Fixnum, String>]
|
135
135
|
def strings col
|
136
136
|
decode_value :string, col, true
|
@@ -138,7 +138,7 @@ class Row
|
|
138
138
|
alias strs strings
|
139
139
|
|
140
140
|
# Returns the latest column value as a Symbol
|
141
|
-
# @param [String, Array]
|
141
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
142
142
|
# @return [Symbol]
|
143
143
|
def symbol col
|
144
144
|
decode_value :symbol, col
|
@@ -146,7 +146,7 @@ class Row
|
|
146
146
|
alias sym symbol
|
147
147
|
|
148
148
|
# Returns all versions of column values as Symbols in a Hash indexed by their timestamps
|
149
|
-
# @param [String, Array]
|
149
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
150
150
|
# @return [Hash<Fixnum, Symbol>]
|
151
151
|
def symbols col
|
152
152
|
decode_value :symbol, col, true
|
@@ -154,49 +154,49 @@ class Row
|
|
154
154
|
alias syms symbols
|
155
155
|
|
156
156
|
# Returns the latest 1-byte column value as a Fixnum
|
157
|
-
# @param [String, Array]
|
157
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
158
158
|
# @return [Fixnum]
|
159
159
|
def byte col
|
160
160
|
decode_value :byte, col
|
161
161
|
end
|
162
162
|
|
163
163
|
# Returns all versions of 1-byte column values as Fixnums in a Hash indexed by their timestamps
|
164
|
-
# @param [String, Array]
|
164
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
165
165
|
# @return [Hash<Fixnum, Fixnum>]
|
166
166
|
def bytes col
|
167
167
|
decode_value :byte, col, true
|
168
168
|
end
|
169
169
|
|
170
170
|
# Returns the latest 2-byte column value as a Fixnum
|
171
|
-
# @param [String, Array]
|
171
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
172
172
|
# @return [Fixnum]
|
173
173
|
def short col
|
174
174
|
decode_value :short, col
|
175
175
|
end
|
176
176
|
|
177
177
|
# Returns all versions of 2-byte column values as Fixnums in a Hash indexed by their timestamps
|
178
|
-
# @param [String, Array]
|
178
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
179
179
|
# @return [Hash<Fixnum, Fixnum>]
|
180
180
|
def shorts col
|
181
181
|
decode_value :short, col, true
|
182
182
|
end
|
183
183
|
|
184
184
|
# Returns the latest 4-byte column value as a Fixnum
|
185
|
-
# @param [String, Array]
|
185
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
186
186
|
# @return [Fixnum]
|
187
187
|
def int col
|
188
188
|
decode_value :int, col
|
189
189
|
end
|
190
190
|
|
191
191
|
# Returns all versions of 4-byte column values as Fixnums in a Hash indexed by their timestamps
|
192
|
-
# @param [String, Array]
|
192
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
193
193
|
# @return [Hash<Fixnum, Fixnum>]
|
194
194
|
def ints col
|
195
195
|
decode_value :int, col, true
|
196
196
|
end
|
197
197
|
|
198
198
|
# Returns the latest 8-byte column value as a Fixnum
|
199
|
-
# @param [String, Array]
|
199
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
200
200
|
# @return [Fixnum]
|
201
201
|
def fixnum col
|
202
202
|
decode_value :fixnum, col
|
@@ -204,7 +204,7 @@ class Row
|
|
204
204
|
alias long fixnum
|
205
205
|
|
206
206
|
# Returns all versions of 8-byte column values as Fixnums in a Hash indexed by their timestamps
|
207
|
-
# @param [String, Array]
|
207
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
208
208
|
# @return [Hash<Fixnum, Fixnum>]
|
209
209
|
def fixnums col
|
210
210
|
decode_value :fixnum, col, true
|
@@ -212,37 +212,49 @@ class Row
|
|
212
212
|
alias longs fixnums
|
213
213
|
|
214
214
|
# Returns the latest column value as a BigDecimal
|
215
|
-
# @param [String, Array]
|
215
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
216
216
|
# @return [BigDecimal]
|
217
217
|
def bigdecimal col
|
218
218
|
decode_value :bigdecimal, col
|
219
219
|
end
|
220
220
|
|
221
221
|
# Returns all versions of column values as BigDecimals in a Hash indexed by their timestamps
|
222
|
-
# @param [String, Array]
|
222
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
223
223
|
# @return [Hash<Fixnum, BigDecimal>]
|
224
224
|
def bigdecimals col
|
225
225
|
decode_value :bigdecimal, col, true
|
226
226
|
end
|
227
227
|
|
228
|
-
# Returns the latest column value as a Float
|
229
|
-
# @param [String, Array]
|
228
|
+
# Returns the latest 4-byte column value as a Float
|
229
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
230
230
|
# @return [Float]
|
231
231
|
def float col
|
232
232
|
decode_value :float, col
|
233
233
|
end
|
234
|
-
alias double float
|
235
234
|
|
236
|
-
# Returns all versions of column values as Floats in a Hash indexed by their timestamps
|
237
|
-
# @param [String, Array]
|
235
|
+
# Returns all versions of 4-byte column values as Floats in a Hash indexed by their timestamps
|
236
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
238
237
|
# @return [Hash<Fixnum, Float>]
|
239
238
|
def floats col
|
240
239
|
decode_value :float, col, true
|
241
240
|
end
|
242
|
-
|
241
|
+
|
242
|
+
# Returns the latest 8-byte column value as a Float
|
243
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
244
|
+
# @return [Float]
|
245
|
+
def double col
|
246
|
+
decode_value :double, col
|
247
|
+
end
|
248
|
+
|
249
|
+
# Returns all versions of 8-byte column values as Floats in a Hash indexed by their timestamps
|
250
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
251
|
+
# @return [Hash<Fixnum, Float>]
|
252
|
+
def doubles col
|
253
|
+
decode_value :double, col, true
|
254
|
+
end
|
243
255
|
|
244
256
|
# Returns the latest column value as a boolean value
|
245
|
-
# @param [String, Array]
|
257
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
246
258
|
# @return [true, false]
|
247
259
|
def boolean col
|
248
260
|
decode_value :boolean, col
|
@@ -250,7 +262,7 @@ class Row
|
|
250
262
|
alias bool boolean
|
251
263
|
|
252
264
|
# Returns all versions of column values as boolean values in a Hash indexed by their timestamps
|
253
|
-
# @param [String, Array]
|
265
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
254
266
|
# @return [Hash<Fixnum, true|false>]
|
255
267
|
def booleans col
|
256
268
|
decode_value :boolean, col, true
|
@@ -262,6 +274,10 @@ class Row
|
|
262
274
|
Bytes.compareTo(rowkey(:raw), other.rowkey(:raw))
|
263
275
|
end
|
264
276
|
|
277
|
+
def inspect
|
278
|
+
"#<HBase::Row:#{object_id} table=#{@table.name} rowkey=#{Bytes.toStringBinary @result.getRow}>"
|
279
|
+
end
|
280
|
+
|
265
281
|
private
|
266
282
|
def get_value col, with_versions = false
|
267
283
|
cf, cq, _ = @table.lookup_and_parse col, true
|
data/lib/hbase-jruby/schema.rb
CHANGED
@@ -67,8 +67,10 @@ class Schema
|
|
67
67
|
end
|
68
68
|
|
69
69
|
table = table.to_sym
|
70
|
-
@lookup[table] = lookup
|
71
|
-
@schema[table] = definition
|
70
|
+
@lookup = @lookup.dup.tap { |h| h[table] = lookup }
|
71
|
+
@schema = @schema.dup.tap { |h| h[table] = definition }
|
72
|
+
|
73
|
+
definition
|
72
74
|
end
|
73
75
|
|
74
76
|
# @private
|
@@ -103,8 +105,8 @@ class Schema
|
|
103
105
|
# @param [Symbol] table
|
104
106
|
def delete table
|
105
107
|
table = table.to_sym
|
106
|
-
@lookup.
|
107
|
-
@schema.
|
108
|
+
@lookup = @lookup.reject { |k, v| k == table }
|
109
|
+
@schema = @schema.reject { |k, v| k == table }
|
108
110
|
nil
|
109
111
|
end
|
110
112
|
|
data/lib/hbase-jruby/scoped.rb
CHANGED
@@ -27,9 +27,9 @@ class Scoped
|
|
27
27
|
:cache_blocks => true }.merge(options)
|
28
28
|
|
29
29
|
scan = block_given? ? filtered_scan : filtered_scan_minimum
|
30
|
-
scan.
|
30
|
+
scan.setCacheBlocks options[:cache_blocks]
|
31
31
|
if options[:caching] && (@limit.nil? || options[:caching] < @limit)
|
32
|
-
scan.
|
32
|
+
scan.setCaching options[:caching]
|
33
33
|
end
|
34
34
|
|
35
35
|
cnt = 0
|
@@ -524,7 +524,7 @@ private
|
|
524
524
|
end if range
|
525
525
|
|
526
526
|
# Caching
|
527
|
-
scan.
|
527
|
+
scan.setCaching @caching if @caching
|
528
528
|
|
529
529
|
# Filters (with projection)
|
530
530
|
prefix_filter = [*build_prefix_filter].compact
|
@@ -536,7 +536,7 @@ private
|
|
536
536
|
# Limit
|
537
537
|
if @limit
|
538
538
|
if [@caching, @dcaching].compact.all? { |c| @limit < c }
|
539
|
-
scan.
|
539
|
+
scan.setCaching @limit
|
540
540
|
end
|
541
541
|
end
|
542
542
|
|
@@ -99,7 +99,7 @@ class Table
|
|
99
99
|
# :max_filesize => 512 * 1024 ** 2,
|
100
100
|
# :memstore_flushsize => 64 * 1024 ** 2,
|
101
101
|
# :readonly => false,
|
102
|
-
# :
|
102
|
+
# :durability => :async_wal
|
103
103
|
# )
|
104
104
|
def alter! props, &block
|
105
105
|
_alter props, true, &block
|
@@ -313,52 +313,53 @@ private
|
|
313
313
|
|
314
314
|
MAX_SPLIT_WAIT = 30
|
315
315
|
|
316
|
-
def
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
316
|
+
def hcd obj, opts
|
317
|
+
hcd =
|
318
|
+
case obj
|
319
|
+
when HColumnDescriptor
|
320
|
+
obj
|
321
|
+
else
|
322
|
+
HColumnDescriptor.new(obj.to_s)
|
323
|
+
end
|
324
|
+
patch_column_descriptor!(hcd, opts)
|
323
325
|
end
|
324
326
|
|
325
|
-
def hcd
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
hcd.setConfiguration k, v.to_s
|
331
|
-
end
|
332
|
-
elsif method = COLUMN_PROPERTIES[key] && COLUMN_PROPERTIES[key][:set]
|
333
|
-
hcd.send method,
|
334
|
-
({
|
335
|
-
:bloomfilter => proc { |v|
|
336
|
-
enum =
|
337
|
-
if defined?(org.apache.hadoop.hbase.regionserver.StoreFile::BloomType)
|
338
|
-
org.apache.hadoop.hbase.regionserver.StoreFile::BloomType
|
339
|
-
else
|
340
|
-
# 0.95 or later
|
341
|
-
org.apache.hadoop.hbase.regionserver.BloomType
|
342
|
-
end
|
343
|
-
const_shortcut enum, v, "Invalid bloom filter type"
|
344
|
-
},
|
345
|
-
:compression => proc { |v|
|
346
|
-
const_shortcut Compression::Algorithm, v, "Invalid compression algorithm"
|
347
|
-
},
|
348
|
-
:compression_compact => proc { |v|
|
349
|
-
const_shortcut Compression::Algorithm, v, "Invalid compression algorithm"
|
350
|
-
},
|
351
|
-
:data_block_encoding => proc { |v|
|
352
|
-
const_shortcut org.apache.hadoop.hbase.io.encoding.DataBlockEncoding, v, "Invalid data block encoding algorithm"
|
353
|
-
}
|
354
|
-
}[key] || proc { |a| a }).call(val)
|
355
|
-
elsif key.is_a?(String)
|
356
|
-
hcd.setValue key, val.to_s
|
357
|
-
else
|
358
|
-
raise ArgumentError, "Invalid property: #{key}"
|
327
|
+
def patch_column_descriptor! hcd, opts
|
328
|
+
opts.each do |key, val|
|
329
|
+
if key == :config
|
330
|
+
val.each do |k, v|
|
331
|
+
hcd.setConfiguration k, v.to_s
|
359
332
|
end
|
360
|
-
|
361
|
-
|
333
|
+
elsif method = COLUMN_PROPERTIES[key] && COLUMN_PROPERTIES[key][:set]
|
334
|
+
hcd.send method,
|
335
|
+
({
|
336
|
+
:bloomfilter => proc { |v|
|
337
|
+
enum =
|
338
|
+
if defined?(org.apache.hadoop.hbase.regionserver.StoreFile::BloomType)
|
339
|
+
org.apache.hadoop.hbase.regionserver.StoreFile::BloomType
|
340
|
+
else
|
341
|
+
# 0.95 or later
|
342
|
+
org.apache.hadoop.hbase.regionserver.BloomType
|
343
|
+
end
|
344
|
+
const_shortcut enum, v, "Invalid bloom filter type"
|
345
|
+
},
|
346
|
+
:compression => proc { |v|
|
347
|
+
const_shortcut Compression::Algorithm, v, "Invalid compression algorithm"
|
348
|
+
},
|
349
|
+
:compression_compact => proc { |v|
|
350
|
+
const_shortcut Compression::Algorithm, v, "Invalid compression algorithm"
|
351
|
+
},
|
352
|
+
:data_block_encoding => proc { |v|
|
353
|
+
const_shortcut org.apache.hadoop.hbase.io.encoding.DataBlockEncoding, v, "Invalid data block encoding algorithm"
|
354
|
+
}
|
355
|
+
}[key] || proc { |a| a }).call(val)
|
356
|
+
elsif key.is_a?(String)
|
357
|
+
hcd.setValue key, val.to_s
|
358
|
+
else
|
359
|
+
raise ArgumentError, "Invalid property: #{key}"
|
360
|
+
end
|
361
|
+
end#opts
|
362
|
+
hcd
|
362
363
|
end
|
363
364
|
|
364
365
|
def self.const_shortcut base, v, message
|
@@ -406,69 +407,58 @@ private
|
|
406
407
|
with_admin do |admin|
|
407
408
|
htd = admin.get_table_descriptor(@name.to_java_bytes)
|
408
409
|
patch_table_descriptor! htd, props
|
409
|
-
|
410
|
-
|
411
|
-
wait_async_admin(admin, &block) if bang
|
412
|
-
end
|
410
|
+
admin.modifyTable @name.to_java_bytes, htd
|
411
|
+
wait_async_admin(admin, &block) if bang
|
413
412
|
end
|
414
413
|
end
|
415
414
|
|
416
415
|
def _add_family name, opts, bang, &block
|
417
416
|
with_admin do |admin|
|
418
|
-
|
419
|
-
|
420
|
-
wait_async_admin(admin, &block) if bang
|
421
|
-
end
|
417
|
+
admin.addColumn @name, hcd(name.to_s, opts)
|
418
|
+
wait_async_admin(admin, &block) if bang
|
422
419
|
end
|
423
420
|
end
|
424
421
|
|
425
422
|
def _alter_family name, opts, bang, &block
|
426
423
|
with_admin do |admin|
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
424
|
+
htd = admin.get_table_descriptor(@name.to_java_bytes)
|
425
|
+
hcd = htd.getFamily(name.to_s.to_java_bytes)
|
426
|
+
admin.modifyColumn @name, hcd(hcd, opts)
|
427
|
+
wait_async_admin(admin, &block) if bang
|
431
428
|
end
|
432
429
|
end
|
433
430
|
|
434
431
|
def _delete_family name, bang, &block
|
435
432
|
with_admin do |admin|
|
436
|
-
|
437
|
-
|
438
|
-
wait_async_admin(admin, &block) if bang
|
439
|
-
end
|
433
|
+
admin.deleteColumn @name, name.to_s
|
434
|
+
wait_async_admin(admin, &block) if bang
|
440
435
|
end
|
441
436
|
end
|
442
437
|
|
443
438
|
def _add_coprocessor class_name, props, bang, &block
|
444
439
|
with_admin do |admin|
|
445
|
-
|
446
|
-
|
447
|
-
htd
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
org.apache.hadoop.fs.Path.new(path),
|
456
|
-
priority || org.apache.hadoop.hbase.Coprocessor::PRIORITY_USER, params
|
457
|
-
end
|
458
|
-
admin.modifyTable @name.to_java_bytes, htd
|
459
|
-
wait_async_admin(admin, &block) if bang
|
440
|
+
htd = admin.get_table_descriptor(@name.to_java_bytes)
|
441
|
+
if props.empty?
|
442
|
+
htd.addCoprocessor class_name
|
443
|
+
else
|
444
|
+
path, priority, params = props.values_at :path, :priority, :params
|
445
|
+
raise ArgumentError, ":path required" unless path
|
446
|
+
params = params ? Hash[ params.map { |k, v| [k.to_s, v.to_s] } ] : {}
|
447
|
+
htd.addCoprocessor class_name,
|
448
|
+
org.apache.hadoop.fs.Path.new(path),
|
449
|
+
priority || org.apache.hadoop.hbase.Coprocessor::PRIORITY_USER, params
|
460
450
|
end
|
451
|
+
admin.modifyTable @name.to_java_bytes, htd
|
452
|
+
wait_async_admin(admin, &block) if bang
|
461
453
|
end
|
462
454
|
end
|
463
455
|
|
464
456
|
def _remove_coprocessor name, bang, &block
|
465
457
|
with_admin do |admin|
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
wait_async_admin(admin, &block) if bang
|
471
|
-
end
|
458
|
+
htd = admin.get_table_descriptor(@name.to_java_bytes)
|
459
|
+
htd.removeCoprocessor name
|
460
|
+
admin.modifyTable @name.to_java_bytes, htd
|
461
|
+
wait_async_admin(admin, &block) if bang
|
472
462
|
end
|
473
463
|
end
|
474
464
|
|
@@ -16,7 +16,7 @@ class Table
|
|
16
16
|
@rowkey, @cf, @cq, @val, @mutation.put(@rowkey, props))
|
17
17
|
end
|
18
18
|
|
19
|
-
# @param [Object]
|
19
|
+
# @param [Object*] extra Optional delete specification. Column family, qualifier, and timestamps
|
20
20
|
def delete *extra
|
21
21
|
@table.htable.checkAndDelete(
|
22
22
|
@rowkey, @cf, @cq, @val, @mutation.delete(@rowkey, *extra))
|
data/lib/hbase-jruby/table.rb
CHANGED
@@ -308,6 +308,7 @@ class Table
|
|
308
308
|
@hbase.schema.lookup @name_sym, col
|
309
309
|
end
|
310
310
|
|
311
|
+
# Schema lookup without column-key caching
|
311
312
|
# @private
|
312
313
|
def lookup_and_parse col, expect_cq
|
313
314
|
@hbase.schema.lookup_and_parse @name_sym, col, expect_cq
|
@@ -315,21 +316,36 @@ class Table
|
|
315
316
|
|
316
317
|
# @private
|
317
318
|
module ThreadLocalCache
|
319
|
+
# Schema lookup with column-key caching
|
318
320
|
def lookup_and_parse col, expect_cq
|
319
|
-
thread_local(@hbase, @name_sym, :columns)
|
320
|
-
|
321
|
+
cache = thread_local(@hbase, @name_sym, :columns)
|
322
|
+
|
323
|
+
# Column-key cache invalidation
|
324
|
+
schema = @hbase.schema
|
325
|
+
if schema.to_h.object_id != @schema_h.object_id
|
326
|
+
@schema_h = schema.to_h
|
327
|
+
cache.clear
|
328
|
+
end
|
329
|
+
|
330
|
+
unless parsed = cache[col]
|
331
|
+
parsed = schema.lookup_and_parse(@name_sym, col, expect_cq)
|
332
|
+
cache[col] = parsed if cache.length < @cache_size
|
333
|
+
end
|
334
|
+
parsed
|
321
335
|
end
|
322
336
|
end
|
323
337
|
|
324
338
|
private
|
325
|
-
def initialize hbase, config, name,
|
339
|
+
def initialize hbase, config, name, cache_size
|
326
340
|
@hbase = hbase
|
341
|
+
@schema_h = hbase.schema.to_h
|
327
342
|
@config = config
|
328
343
|
@name = name.to_s
|
329
344
|
@name_sym = name.to_sym
|
330
345
|
@mutation = Mutation.new(self)
|
346
|
+
@cache_size = cache_size
|
331
347
|
|
332
|
-
extend ThreadLocalCache if
|
348
|
+
extend ThreadLocalCache if cache_size > 0
|
333
349
|
end
|
334
350
|
|
335
351
|
def check_closed
|
data/lib/hbase-jruby/util.rb
CHANGED
@@ -14,7 +14,7 @@ module Util
|
|
14
14
|
# @param [byte[]] v
|
15
15
|
# @return [byte[]]
|
16
16
|
def to_bytes v
|
17
|
-
import_java_classes!
|
17
|
+
HBase.import_java_classes!
|
18
18
|
|
19
19
|
case v
|
20
20
|
when Array
|
@@ -42,7 +42,7 @@ module Util
|
|
42
42
|
raise ArgumentError, "Unknown value format" unless len == 1
|
43
43
|
|
44
44
|
val = v.values.first
|
45
|
-
raise ArgumentError, "Unknown value format" unless val.is_a?(
|
45
|
+
raise ArgumentError, "Unknown value format" unless val.is_a?(Numeric)
|
46
46
|
|
47
47
|
case v.keys.first
|
48
48
|
when :byte
|
@@ -53,6 +53,10 @@ module Util
|
|
53
53
|
Bytes.java_send :toBytes, [Java::short], val
|
54
54
|
when :long, :fixnum
|
55
55
|
Bytes.java_send :toBytes, [Java::long], val
|
56
|
+
when :float
|
57
|
+
Bytes.java_send :toBytes, [Java::float], val
|
58
|
+
when :double
|
59
|
+
Bytes.java_send :toBytes, [Java::double], val
|
56
60
|
else
|
57
61
|
raise ArgumentError, "Invalid value format"
|
58
62
|
end
|
@@ -69,7 +73,7 @@ module Util
|
|
69
73
|
return nil if val.nil?
|
70
74
|
return Util.to_bytes val if type.nil?
|
71
75
|
|
72
|
-
import_java_classes!
|
76
|
+
HBase.import_java_classes!
|
73
77
|
case type
|
74
78
|
when :string, :str, :symbol, :sym
|
75
79
|
val.to_s.to_java_bytes
|
@@ -83,7 +87,9 @@ module Util
|
|
83
87
|
Bytes.java_send :toBytes, [Java::short], val
|
84
88
|
when :long, :fixnum
|
85
89
|
Bytes.java_send :toBytes, [Java::long], val
|
86
|
-
when :float
|
90
|
+
when :float
|
91
|
+
Bytes.java_send :toBytes, [Java::float], val
|
92
|
+
when :double
|
87
93
|
Bytes.java_send :toBytes, [Java::double], val
|
88
94
|
when :bigdecimal
|
89
95
|
case val
|
@@ -108,7 +114,7 @@ module Util
|
|
108
114
|
def from_bytes type, val
|
109
115
|
return nil if val.nil?
|
110
116
|
|
111
|
-
import_java_classes!
|
117
|
+
HBase.import_java_classes!
|
112
118
|
case type
|
113
119
|
when :string, :str
|
114
120
|
Bytes.to_string val
|
@@ -124,7 +130,9 @@ module Util
|
|
124
130
|
Bytes.to_string(val).to_sym
|
125
131
|
when :bigdecimal
|
126
132
|
BigDecimal.new(Bytes.to_big_decimal(val).to_s)
|
127
|
-
when :float
|
133
|
+
when :float
|
134
|
+
Bytes.to_float val
|
135
|
+
when :double
|
128
136
|
Bytes.to_double val
|
129
137
|
when :boolean, :bool
|
130
138
|
Bytes.to_boolean val
|
@@ -169,17 +177,6 @@ module Util
|
|
169
177
|
return cf, cq
|
170
178
|
end
|
171
179
|
end
|
172
|
-
|
173
|
-
private
|
174
|
-
def import_java_classes!
|
175
|
-
HBase.import_java_classes!
|
176
|
-
if defined?(ByteBuffer) && defined?(KeyValue) && defined?(Bytes)
|
177
|
-
self.instance_eval do
|
178
|
-
def import_java_classes!
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
180
|
end
|
184
181
|
|
185
182
|
private
|