hbase-jruby 0.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +623 -0
- data/Rakefile +7 -0
- data/hbase-jruby.gemspec +23 -0
- data/lib/hbase-jruby.rb +16 -0
- data/lib/hbase-jruby/admin.rb +29 -0
- data/lib/hbase-jruby/byte_array.rb +39 -0
- data/lib/hbase-jruby/cell.rb +122 -0
- data/lib/hbase-jruby/column_key.rb +63 -0
- data/lib/hbase-jruby/dependency.rb +69 -0
- data/lib/hbase-jruby/hbase.rb +77 -0
- data/lib/hbase-jruby/pom/cdh3u5.xml +40 -0
- data/lib/hbase-jruby/pom/cdh4.1.2.xml +47 -0
- data/lib/hbase-jruby/result.rb +382 -0
- data/lib/hbase-jruby/scoped.rb +489 -0
- data/lib/hbase-jruby/table.rb +486 -0
- data/lib/hbase-jruby/util.rb +171 -0
- data/lib/hbase-jruby/version.rb +5 -0
- data/test/helper.rb +53 -0
- data/test/test_byte_array.rb +40 -0
- data/test/test_cell.rb +51 -0
- data/test/test_column_key.rb +49 -0
- data/test/test_hbase.rb +36 -0
- data/test/test_scoped.rb +318 -0
- data/test/test_table.rb +211 -0
- data/test/test_table_admin.rb +148 -0
- data/test/test_util.rb +80 -0
- metadata +116 -0
data/test/test_table.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
4
|
+
require 'helper'
|
5
|
+
|
6
|
+
class TestScoped < TestHBaseJRubyBase
|
7
|
+
def test_table
|
8
|
+
@hbase.table(TABLE) do |table|
|
9
|
+
assert_equal TABLE, table.name
|
10
|
+
assert table.exists?
|
11
|
+
end
|
12
|
+
|
13
|
+
table = @hbase.table(TABLE)
|
14
|
+
2.times do
|
15
|
+
assert_equal TABLE, table.name
|
16
|
+
assert table.exists?
|
17
|
+
table.close
|
18
|
+
table.close
|
19
|
+
|
20
|
+
# Gets another HTable instance from HTablePool
|
21
|
+
table.put('rowkey' => { 'cf1:a' => 1 })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_put_then_get
|
26
|
+
bignum = 123456789123456789123456789
|
27
|
+
# Single record put
|
28
|
+
assert_equal 1, @table.put('row1',
|
29
|
+
'cf1:a' => 2,
|
30
|
+
'cf1:b' => 'b',
|
31
|
+
'cf1:c' => 6.28,
|
32
|
+
'cf1:d' => false,
|
33
|
+
'cf1:e' => bignum + 1,
|
34
|
+
'cf1:f' => :bol,
|
35
|
+
'cf1:g' => BigDecimal.new("456.123"),
|
36
|
+
'cf1:str1' => "Goodbye", 'cf1:str2' => "Cruel world")
|
37
|
+
assert_equal 1, @table.put('row1',
|
38
|
+
'cf1:a' => 1,
|
39
|
+
'cf1:b' => 'a',
|
40
|
+
'cf1:c' => 3.14,
|
41
|
+
'cf1:d' => true,
|
42
|
+
'cf1:e' => bignum,
|
43
|
+
'cf1:f' => :sym,
|
44
|
+
'cf1:g' => BigDecimal.new("123.456"),
|
45
|
+
'cf1:str1' => "Hello", 'cf1:str2' => "World")
|
46
|
+
# Batch put
|
47
|
+
assert_equal 2, @table.put(
|
48
|
+
'row2' => { 'cf1:a' => 2, 'cf1:b' => 'b', 'cf1:c' => 6.28 },
|
49
|
+
'row3' => { 'cf1:a' => 4, 'cf1:b' => 'c', 'cf1:c' => 6.28 })
|
50
|
+
|
51
|
+
# single-get (latest version)
|
52
|
+
assert_equal 'row1', @table.get('row1').rowkey
|
53
|
+
assert_equal 1, @table.get('row1').fixnum('cf1:a')
|
54
|
+
assert_equal 'a', @table.get('row1').string('cf1:b')
|
55
|
+
assert_equal 'a', String.from_java_bytes(@table.get('row1').raw('cf1:b'))
|
56
|
+
assert_equal 3.14, @table.get('row1').float('cf1:c')
|
57
|
+
assert_equal true, @table.get('row1').boolean('cf1:d')
|
58
|
+
assert_equal bignum, @table.get('row1').bignum('cf1:e')
|
59
|
+
assert_equal :sym, @table.get('row1').symbol('cf1:f')
|
60
|
+
assert_equal BigDecimal.new("123.456"), @table.get('row1').bigdecimal('cf1:g')
|
61
|
+
|
62
|
+
# single-get-multi-col
|
63
|
+
assert_equal %w[Hello World], @table.get('row1').string(['cf1:str1', 'cf1:str2'])
|
64
|
+
|
65
|
+
# single-get-multi-ver
|
66
|
+
assert_equal [1, 2], @table.get('row1').fixnums('cf1:a').values
|
67
|
+
assert_equal %w[a b], @table.get('row1').strings('cf1:b').values
|
68
|
+
assert_equal %w[a b], @table.get('row1').raws('cf1:b').values.map { |v| String.from_java_bytes v }
|
69
|
+
assert_equal [3.14, 6.28], @table.get('row1').floats('cf1:c').values
|
70
|
+
assert_equal [true, false], @table.get('row1').booleans('cf1:d').values
|
71
|
+
assert_equal [bignum, bignum + 1], @table.get('row1').bignums('cf1:e').values
|
72
|
+
assert_equal [:sym, :bol], @table.get('row1').symbols('cf1:f').values
|
73
|
+
assert_equal [
|
74
|
+
BigDecimal.new("123.456"),
|
75
|
+
BigDecimal.new("456.123")], @table.get('row1').bigdecimals('cf1:g').values
|
76
|
+
|
77
|
+
assert @table.get('row1').fixnums('cf1:a').keys.all? { |k| k.instance_of? Fixnum }
|
78
|
+
|
79
|
+
# single-get-multi-col-multi=ver
|
80
|
+
ret = @table.get('row1').strings(['cf1:str1', 'cf1:str2'])
|
81
|
+
assert_equal ['Hello', 'World'], ret.map(&:values).map(&:first)
|
82
|
+
assert_equal ['Goodbye', 'Cruel world'], ret.map(&:values).map(&:last)
|
83
|
+
|
84
|
+
# multi-get
|
85
|
+
assert_equal %w[row1 row2 row3], @table.get(['row1', 'row2', 'row3']).map { |r| r.rowkey }
|
86
|
+
assert_equal [1, 2, 4 ], @table.get(['row1', 'row2', 'row3']).map { |r| r.integer('cf1:a') }
|
87
|
+
assert_equal [3.14, 6.28, 6.28], @table.get(['row1', 'row2', 'row3']).map { |r| r.float('cf1:c') }
|
88
|
+
assert_equal [nil, nil ], @table.get(['xxx', 'yyy'])
|
89
|
+
|
90
|
+
# Unavailable columns
|
91
|
+
assert_equal nil, @table.get('row1').symbol('cf1:xxx')
|
92
|
+
assert_equal nil, @table.get('row1').integer('cf1:xxx')
|
93
|
+
|
94
|
+
# Row not found
|
95
|
+
assert_equal nil, @table.get('xxx')
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_to_hash
|
99
|
+
data = {
|
100
|
+
'cf1:a' => 'Hello',
|
101
|
+
'cf1:b' => 200,
|
102
|
+
'cf1:c' => 3.14,
|
103
|
+
'cf2:d' => :world,
|
104
|
+
'cf2:e' => false,
|
105
|
+
'cf3:f' => 1234567890123456789012345678901234567890,
|
106
|
+
'cf3' => true
|
107
|
+
}
|
108
|
+
schema = {
|
109
|
+
'cf1:a' => :string,
|
110
|
+
'cf1:b' => :integer,
|
111
|
+
'cf1:c' => :float,
|
112
|
+
HBase::ColumnKey(:cf2, :d) => :symbol,
|
113
|
+
HBase::ColumnKey(:cf2, :e) => :boolean,
|
114
|
+
HBase::ColumnKey(:cf3, :f) => :biginteger,
|
115
|
+
'cf3' => :boolean
|
116
|
+
}
|
117
|
+
@table.put('row1', data)
|
118
|
+
@table.put('row2', 'cf1:a' => 'Goodbye')
|
119
|
+
|
120
|
+
assert_equal data, @table.get('row1').to_hash(schema).map { |k, v| { k.to_s => v } }.inject(:merge)
|
121
|
+
assert_equal 1, @table.get('row1').to_hash_with_versions(schema)['cf1:a'].length
|
122
|
+
assert_equal 1, @table.get('row1').to_hash_with_versions(schema)[HBase::ColumnKey(:cf1, :a)].length
|
123
|
+
|
124
|
+
# Better testing for versioned values
|
125
|
+
@table.put('row1', data)
|
126
|
+
assert_equal data, @table.get('row1').to_hash(schema).map { |k, v| { k.to_s => v } }.inject(:merge)
|
127
|
+
|
128
|
+
assert_equal 2, @table.get('row1').to_hash_with_versions(schema)['cf1:a'].length
|
129
|
+
assert_equal 1, @table.get('row1').to_hash_with_versions(schema)['cf3:f'].length
|
130
|
+
|
131
|
+
# get option: :versions
|
132
|
+
assert_equal 1, @table.versions(1).get('row1').to_hash_with_versions(schema)['cf1:a'].length
|
133
|
+
|
134
|
+
# scoped get with filters
|
135
|
+
assert_equal 2, @table.get(['row1', 'row2']).count
|
136
|
+
assert_equal 2, @table.range('row1'...'row2').get(['row1', 'row2']).count
|
137
|
+
assert_equal 2, @table.range('row1'..'row2').get(['row1', 'row2']).compact.count
|
138
|
+
assert_equal 1, @table.range('row1'...'row2').get(['row1', 'row2']).compact.count
|
139
|
+
assert_equal 1, @table.range(:prefix => 'row2').get(['row1', 'row2']).compact.count
|
140
|
+
assert_equal 1, @table.filter('cf1:a' => 'Hello').get(['row1', 'row2']).compact.count
|
141
|
+
|
142
|
+
# scoped get with projection
|
143
|
+
assert_equal %w[cf3 cf3:f], @table.project('cf3').get('row1').to_hash.keys.map(&:to_s)
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_increment
|
147
|
+
@table.put('row1', 'cf1:counter' => 1, 'cf1:counter2' => 100)
|
148
|
+
assert_equal 1, @table.get('row1').fixnum('cf1:counter')
|
149
|
+
|
150
|
+
@table.increment('row1', 'cf1:counter', 1)
|
151
|
+
assert_equal 2, @table.get('row1').int('cf1:counter')
|
152
|
+
|
153
|
+
@table.increment('row1', 'cf1:counter', 2)
|
154
|
+
assert_equal 4, @table.get('row1').integer('cf1:counter')
|
155
|
+
|
156
|
+
# Multi-column increment
|
157
|
+
@table.increment('row1', 'cf1:counter' => 4, 'cf1:counter2' => 100)
|
158
|
+
assert_equal 8, @table.get('row1').integer('cf1:counter')
|
159
|
+
assert_equal 200, @table.get('row1').integer('cf1:counter2')
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_delete
|
163
|
+
@table.put('row1', 'cf1' => 0, 'cf1:a' => 1, 'cf1:b' => 2, 'cf2:c' => 3, 'cf2:d' => 4)
|
164
|
+
sleep 0.1
|
165
|
+
@table.put('row1', 'cf2:d' => 5)
|
166
|
+
sleep 0.1
|
167
|
+
@table.put('row1', 'cf2:d' => 6)
|
168
|
+
versions = @table.get('row1').to_hash_with_versions['cf2:d'].keys
|
169
|
+
assert versions[0] > versions[1]
|
170
|
+
assert versions[1] > versions[2]
|
171
|
+
|
172
|
+
# Deletes a version
|
173
|
+
@table.delete('row1', 'cf2:d', versions[0], versions[2])
|
174
|
+
new_versions = @table.get('row1').to_hash_with_versions['cf2:d'].keys
|
175
|
+
assert_equal new_versions, [versions[1]]
|
176
|
+
|
177
|
+
# Deletes a column
|
178
|
+
assert_equal 3, @table.get('row1').integer('cf2:c')
|
179
|
+
@table.delete('row1', 'cf2:c')
|
180
|
+
assert_nil @table.get('row1').to_hash['cf2:c']
|
181
|
+
|
182
|
+
# Deletes a column with empty qualifier
|
183
|
+
assert_equal 0, @table.get('row1').integer('cf1')
|
184
|
+
@table.delete('row1', 'cf1:')
|
185
|
+
assert_equal 1, @table.get('row1').integer('cf1:a')
|
186
|
+
assert_equal 2, @table.get('row1').integer('cf1:b')
|
187
|
+
assert_nil @table.get('row1').to_hash['cf1']
|
188
|
+
assert_nil @table.get('row1').to_hash['cf1:']
|
189
|
+
|
190
|
+
# Deletes a column family
|
191
|
+
assert_equal 1, @table.get('row1').integer('cf1:a')
|
192
|
+
assert_equal 2, @table.get('row1').integer('cf1:b')
|
193
|
+
@table.delete('row1', 'cf1') # No trailing colon
|
194
|
+
assert_nil @table.get('row1').to_hash['cf1:a']
|
195
|
+
assert_nil @table.get('row1').to_hash['cf1:b']
|
196
|
+
|
197
|
+
# Deletes a row
|
198
|
+
@table.delete('row1')
|
199
|
+
assert_nil @table.get('row1')
|
200
|
+
|
201
|
+
# Batch delete
|
202
|
+
@table.put('row2', 'cf1:a' => 1)
|
203
|
+
@table.put('row3', 'cf1:a' => 1, 'cf1:b' => 2)
|
204
|
+
|
205
|
+
@table.delete ['row2'], ['row3', 'cf1:a']
|
206
|
+
assert_nil @table.get('row2')
|
207
|
+
assert_nil @table.get('row3').to_hash['cf1:a']
|
208
|
+
assert_equal 2, @table.get('row3').integer('cf1:b')
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
4
|
+
require 'helper'
|
5
|
+
|
6
|
+
class TestTableAdmin < TestHBaseJRubyBase
|
7
|
+
def teardown
|
8
|
+
@table.drop! if @table.exists?
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_create_table_symbol_string
|
12
|
+
t = @hbase.table(:test_hbase_jruby_create_table)
|
13
|
+
t.drop! if t.exists?
|
14
|
+
[ :cf, 'cf', :cf => {} ].each do |cf|
|
15
|
+
assert_false t.exists?
|
16
|
+
t.create! cf
|
17
|
+
assert t.exists?
|
18
|
+
t.drop!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_disable_and_drop
|
23
|
+
@table.disable!
|
24
|
+
@table.disable!
|
25
|
+
@table.drop!
|
26
|
+
assert_false @table.exists?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_table_props
|
30
|
+
max_fs = 1024 ** 3
|
31
|
+
@table.drop!
|
32
|
+
@table.create!({ :cf1 => {}, :cf2 => {} }, :max_filesize => max_fs)
|
33
|
+
assert_equal max_fs, @table.descriptor.get_max_file_size
|
34
|
+
|
35
|
+
max_fs = 300 * 1024 ** 2
|
36
|
+
@table.drop!
|
37
|
+
@table.create! :cf1, :max_filesize => max_fs
|
38
|
+
assert_equal max_fs, @table.descriptor.get_max_file_size
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_create_table_invalid_input
|
42
|
+
@table.drop!
|
43
|
+
assert_raise(ArgumentError) do
|
44
|
+
@table.create! 3.14
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_raise(ArgumentError) do
|
48
|
+
@table.create! :cf1 => { :bloom => 'by beach house' }
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_raise(ArgumentError) do
|
52
|
+
@table.create! :cf1 => { :bloomfilter => :xxx }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_enabled_disabled
|
57
|
+
assert @table.enabled?
|
58
|
+
assert !@table.disabled?
|
59
|
+
@table.disable!
|
60
|
+
assert !@table.enabled?
|
61
|
+
assert @table.disabled?
|
62
|
+
@table.enable!
|
63
|
+
assert @table.enabled?
|
64
|
+
assert !@table.disabled?
|
65
|
+
end
|
66
|
+
|
67
|
+
# def test_rename!
|
68
|
+
# new_name = TABLE + '_new'
|
69
|
+
# @table.rename! new_name
|
70
|
+
# assert_equal new_name, @table.name
|
71
|
+
# assert_equal new_name, @table.descriptor.get_name_as_string
|
72
|
+
# @table.drop!
|
73
|
+
# end
|
74
|
+
|
75
|
+
def test_table_properties
|
76
|
+
assert_raise(ArgumentError) do
|
77
|
+
@table.alter! :hello => :world
|
78
|
+
end
|
79
|
+
|
80
|
+
max_fs = 512 * 1024 ** 2
|
81
|
+
mem_fs = 64 * 1024 ** 2
|
82
|
+
|
83
|
+
@table.alter!(
|
84
|
+
:max_filesize => max_fs,
|
85
|
+
:memstore_flushsize => mem_fs,
|
86
|
+
:readonly => false,
|
87
|
+
:deferred_log_flush => true
|
88
|
+
)
|
89
|
+
|
90
|
+
assert_equal max_fs, @table.descriptor.get_max_file_size
|
91
|
+
assert_equal mem_fs, @table.descriptor.get_mem_store_flush_size
|
92
|
+
assert_equal false, @table.descriptor.is_read_only
|
93
|
+
assert_equal true, @table.descriptor.is_deferred_log_flush
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_column_family_alteration!
|
97
|
+
assert @table.descriptor.getFamilies.map(&:getNameAsString).include?('cf2')
|
98
|
+
@table.delete_family! :cf2
|
99
|
+
assert !@table.descriptor.getFamilies.map(&:getNameAsString).include?('cf2')
|
100
|
+
@table.add_family! :cf4, {}
|
101
|
+
assert @table.descriptor.getFamilies.map(&:getNameAsString).include?('cf4')
|
102
|
+
|
103
|
+
# TODO: test more props
|
104
|
+
@table.alter_family! :cf4, :versions => 10
|
105
|
+
assert_equal 10, @table.descriptor.getFamilies.select { |cf| cf.getNameAsString == 'cf4' }.first.getMaxVersions
|
106
|
+
|
107
|
+
assert_raise(ArgumentError) {
|
108
|
+
@table.alter_family! :cf4, :hello => 'world'
|
109
|
+
}
|
110
|
+
assert_raise(ArgumentError) {
|
111
|
+
@table.alter_family! :cf4, :bloomfilter => :xxx
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_inspect
|
116
|
+
@table.drop!
|
117
|
+
assert "{NAME => '#{TABLE}'}", @table.inspect # FIXME
|
118
|
+
|
119
|
+
@table.create! :cf => {
|
120
|
+
:blockcache => true,
|
121
|
+
:blocksize => 128 * 1024,
|
122
|
+
:bloomfilter => :row,
|
123
|
+
:compression => :snappy,
|
124
|
+
# :data_block_encoding => org.apache.hadoop.hbase.io.encoding.DataBlockEncoding::DIFF,
|
125
|
+
# :encode_on_disk => true,
|
126
|
+
# :keep_deleted_cells => true,
|
127
|
+
:in_memory => true,
|
128
|
+
:min_versions => 5,
|
129
|
+
:replication_scope => 0,
|
130
|
+
:ttl => 100,
|
131
|
+
:versions => 10,
|
132
|
+
}
|
133
|
+
props = eval @table.inspect.gsub(/([A-Z_]+) =>/) { ":#{$1.downcase} =>" }
|
134
|
+
assert_equal TABLE, props[:name]
|
135
|
+
cf = props[:families].first
|
136
|
+
assert_equal 'cf', cf[:name]
|
137
|
+
assert_equal 'ROW', cf[:bloomfilter]
|
138
|
+
assert_equal '0', cf[:replication_scope]
|
139
|
+
assert_equal '10', cf[:versions]
|
140
|
+
assert_equal 'SNAPPY', cf[:compression]
|
141
|
+
assert_equal '5', cf[:min_versions]
|
142
|
+
assert_equal '100', cf[:ttl]
|
143
|
+
assert_equal '131072', cf[:blocksize]
|
144
|
+
assert_equal 'true', cf[:in_memory]
|
145
|
+
assert_equal 'true', cf[:blockcache]
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
data/test/test_util.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
4
|
+
require 'helper'
|
5
|
+
require 'bigdecimal'
|
6
|
+
|
7
|
+
class TestUtil < Test::Unit::TestCase
|
8
|
+
Util = HBase::Util
|
9
|
+
|
10
|
+
def test_bytea_conversion
|
11
|
+
Util.import_java_classes!
|
12
|
+
|
13
|
+
[:fixnum, :int, :integer].each do |type|
|
14
|
+
assert_equal 100, Util.from_bytes( type, Util.to_bytes(100) )
|
15
|
+
end
|
16
|
+
[:float, :double].each do |type|
|
17
|
+
assert_equal 3.14, Util.from_bytes( type, Util.to_bytes(3.14) )
|
18
|
+
end
|
19
|
+
[:bignum, :biginteger, :bigint].each do |type|
|
20
|
+
assert_equal 12345678901234567890, Util.from_bytes( type, Util.to_bytes(12345678901234567890) )
|
21
|
+
end
|
22
|
+
[:string, :str].each do |type|
|
23
|
+
assert_equal "Hello", Util.from_bytes( type, Util.to_bytes("Hello") )
|
24
|
+
end
|
25
|
+
[:bool, :boolean].each do |type|
|
26
|
+
assert_equal true, Util.from_bytes( type, Util.to_bytes(true) )
|
27
|
+
assert_equal false, Util.from_bytes( type, Util.to_bytes(false) )
|
28
|
+
end
|
29
|
+
[:symbol, :sym].each do |type|
|
30
|
+
assert_equal :hello, Util.from_bytes( type, Util.to_bytes(:hello) )
|
31
|
+
end
|
32
|
+
|
33
|
+
bd = BigDecimal.new("123456789.123456789")
|
34
|
+
jbd = java.math.BigDecimal.new("9876543210.987654321")
|
35
|
+
[:bigdecimal].each do |type|
|
36
|
+
assert_equal bd, Util.from_bytes( type, Util.to_bytes(bd) )
|
37
|
+
assert_equal jbd, Util.from_bytes( type, Util.to_bytes(jbd) )
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_equal String.from_java_bytes("asdf".to_java_bytes),
|
41
|
+
String.from_java_bytes( Util.from_bytes( :raw, "asdf".to_java_bytes ) )
|
42
|
+
|
43
|
+
assert_equal 0, Util.to_bytes(nil).length
|
44
|
+
|
45
|
+
assert_raise(ArgumentError) { Util.from_bytes(:xxx, [].to_java(Java::byte)) }
|
46
|
+
assert_raise(ArgumentError) { Util.to_bytes({}) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_parse_column_name
|
50
|
+
assert_equal ['abc', 'def'], parse_to_str('abc:def')
|
51
|
+
assert_equal ['abc', 'def:'], parse_to_str('abc:def:')
|
52
|
+
assert_equal ['abc', ''], parse_to_str('abc:')
|
53
|
+
assert_equal ['abc', nil], parse_to_str('abc')
|
54
|
+
assert_equal ['abc', ':::'], parse_to_str('abc::::')
|
55
|
+
|
56
|
+
assert_equal [:abc, :def], parse_to_str([:abc, :def], :symbol)
|
57
|
+
assert_equal [123, 456], parse_to_str([123, 456], :fixnum)
|
58
|
+
assert_equal ['abc', 'def'], parse_to_str(
|
59
|
+
org.apache.hadoop.hbase.KeyValue.new(
|
60
|
+
'rowkey'.to_java_bytes,
|
61
|
+
'abc'.to_java_bytes,
|
62
|
+
'def'.to_java_bytes))
|
63
|
+
|
64
|
+
assert_equal [:abc, :def], parse_to_str(HBase::ColumnKey.new(:abc, :def), :symbol)
|
65
|
+
|
66
|
+
assert_raise(ArgumentError) { Util.parse_column_name(nil) }
|
67
|
+
assert_raise(ArgumentError) { Util.parse_column_name('') }
|
68
|
+
|
69
|
+
assert_equal nil, Util.from_bytes(:string, nil)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_append_0
|
73
|
+
assert_equal [97, 97, 97, 0], Util.append_0("aaa".to_java_bytes).to_a
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def parse_to_str v, type = :string
|
78
|
+
Util.parse_column_name(v).map { |e| Util.from_bytes type, e }
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hbase-jruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Junegunn Choi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: test-unit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: simplecov
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby-esque interface for accessing HBase from JRuby
|
47
|
+
email:
|
48
|
+
- junegunn.c@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- hbase-jruby.gemspec
|
59
|
+
- lib/hbase-jruby.rb
|
60
|
+
- lib/hbase-jruby/admin.rb
|
61
|
+
- lib/hbase-jruby/byte_array.rb
|
62
|
+
- lib/hbase-jruby/cell.rb
|
63
|
+
- lib/hbase-jruby/column_key.rb
|
64
|
+
- lib/hbase-jruby/dependency.rb
|
65
|
+
- lib/hbase-jruby/hbase.rb
|
66
|
+
- lib/hbase-jruby/pom/cdh3u5.xml
|
67
|
+
- lib/hbase-jruby/pom/cdh4.1.2.xml
|
68
|
+
- lib/hbase-jruby/result.rb
|
69
|
+
- lib/hbase-jruby/scoped.rb
|
70
|
+
- lib/hbase-jruby/table.rb
|
71
|
+
- lib/hbase-jruby/util.rb
|
72
|
+
- lib/hbase-jruby/version.rb
|
73
|
+
- test/helper.rb
|
74
|
+
- test/test_byte_array.rb
|
75
|
+
- test/test_cell.rb
|
76
|
+
- test/test_column_key.rb
|
77
|
+
- test/test_hbase.rb
|
78
|
+
- test/test_scoped.rb
|
79
|
+
- test/test_table.rb
|
80
|
+
- test/test_table_admin.rb
|
81
|
+
- test/test_util.rb
|
82
|
+
homepage: https://github.com/junegunn/hbase-jruby
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Ruby-esque interface for accessing HBase from JRuby
|
106
|
+
test_files:
|
107
|
+
- test/helper.rb
|
108
|
+
- test/test_byte_array.rb
|
109
|
+
- test/test_cell.rb
|
110
|
+
- test/test_column_key.rb
|
111
|
+
- test/test_hbase.rb
|
112
|
+
- test/test_scoped.rb
|
113
|
+
- test/test_table.rb
|
114
|
+
- test/test_table_admin.rb
|
115
|
+
- test/test_util.rb
|
116
|
+
has_rdoc:
|