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/hbase-jruby.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.platform = 'java'
|
15
15
|
gem.license = 'MIT'
|
16
16
|
|
17
|
-
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.files = `git ls-files`.split($/).reject { |f| f =~ /^benchmark/ }
|
18
18
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
20
|
gem.require_paths = ["lib"]
|
@@ -2,6 +2,7 @@ class HBase
|
|
2
2
|
class << self
|
3
3
|
# Shortcut method to HBase::ByteArray.new
|
4
4
|
# @param [*Object] values
|
5
|
+
# @return [HBase::ByteArray]
|
5
6
|
def ByteArray *values
|
6
7
|
ByteArray.new(*values)
|
7
8
|
end
|
@@ -16,6 +17,13 @@ class ByteArray
|
|
16
17
|
|
17
18
|
include Enumerable
|
18
19
|
|
20
|
+
# Shortcut method to HBase::ByteArray.new
|
21
|
+
# @param [*Object] values
|
22
|
+
# @return [HBase::ByteArray]
|
23
|
+
def self.[] *values
|
24
|
+
ByteArray.new(*values)
|
25
|
+
end
|
26
|
+
|
19
27
|
# Initializes ByteArray instance with the given objects,
|
20
28
|
# each converted to its byte array representation
|
21
29
|
# @param [*Object] values
|
@@ -30,16 +38,14 @@ class ByteArray
|
|
30
38
|
end
|
31
39
|
|
32
40
|
def each
|
33
|
-
|
34
|
-
|
35
|
-
else
|
36
|
-
self
|
37
|
-
end
|
41
|
+
return enum_for(:each) unless block_given?
|
42
|
+
@java.to_a.each { |byte| yield byte }
|
38
43
|
end
|
39
44
|
|
40
45
|
# Checks if the two byte arrays are the same
|
41
46
|
# @param [HBase::ByteArray] other
|
42
47
|
def eql? other
|
48
|
+
other = other_as_byte_array other
|
43
49
|
Arrays.equals(@java, other.java)
|
44
50
|
end
|
45
51
|
alias == eql?
|
@@ -47,6 +53,7 @@ class ByteArray
|
|
47
53
|
# Compares two ByteArray objects
|
48
54
|
# @param [HBase::ByteArray] other
|
49
55
|
def <=> other
|
56
|
+
other = other_as_byte_array other
|
50
57
|
Bytes.compareTo(@java, other.java)
|
51
58
|
end
|
52
59
|
|
@@ -147,12 +154,25 @@ class ByteArray
|
|
147
154
|
Arrays.java_send(:hashCode, [Util::JAVA_BYTE_ARRAY_CLASS], @java)
|
148
155
|
end
|
149
156
|
|
157
|
+
def inspect
|
158
|
+
"HBase::ByteArray<#{@java.to_a.join ', '}>"
|
159
|
+
end
|
160
|
+
|
150
161
|
private
|
151
162
|
def initialize_ *values
|
152
163
|
@java = values.inject(Util::JAVA_BYTE_ARRAY_EMPTY) { |sum, value|
|
153
164
|
Bytes.add sum, Util.to_bytes(value)
|
154
165
|
}
|
155
166
|
end
|
167
|
+
|
168
|
+
def other_as_byte_array other
|
169
|
+
case other
|
170
|
+
when ByteArray
|
171
|
+
other
|
172
|
+
else
|
173
|
+
ByteArray[other]
|
174
|
+
end
|
175
|
+
end
|
156
176
|
end#ByteArray
|
157
177
|
end#HBase
|
158
178
|
|
data/lib/hbase-jruby/cell.rb
CHANGED
@@ -7,7 +7,8 @@ class Cell
|
|
7
7
|
|
8
8
|
# Creates a boxed object for a KeyValue object
|
9
9
|
# @param [org.apache.hadoop.hbase.KeyValue] key_value
|
10
|
-
def initialize key_value
|
10
|
+
def initialize table, key_value
|
11
|
+
@table = table
|
11
12
|
@java = key_value
|
12
13
|
@ck = nil
|
13
14
|
end
|
@@ -16,16 +17,10 @@ class Cell
|
|
16
17
|
# @param [Symbol] type The type of the rowkey.
|
17
18
|
# Can be one of :string, :symbol, :fixnum, :float, :short, :int, :bigdecimal, :boolean and :raw.
|
18
19
|
# @return [String, byte[]]
|
19
|
-
def rowkey type = :
|
20
|
+
def rowkey type = :raw
|
20
21
|
Util.from_bytes type, @java.getRow
|
21
22
|
end
|
22
23
|
|
23
|
-
# Returns the ColumnKey object for the cell
|
24
|
-
# @return [ColumnKey]
|
25
|
-
def column_key
|
26
|
-
@ck ||= ColumnKey.new @java.getFamily, @java.getQualifier
|
27
|
-
end
|
28
|
-
|
29
24
|
# Returns the name of the column family of the cell
|
30
25
|
# @return [String]
|
31
26
|
def family
|
@@ -49,12 +44,17 @@ class Cell
|
|
49
44
|
end
|
50
45
|
alias ts timestamp
|
51
46
|
|
47
|
+
# Returns the value of the cell. If the column in not defined in the schema, returns Java byte array.
|
48
|
+
def value
|
49
|
+
_, _, type = @table.lookup_schema(cq)
|
50
|
+
Util.from_bytes(type, raw)
|
51
|
+
end
|
52
|
+
|
52
53
|
# Returns the value of the cell as a Java byte array
|
53
54
|
# @return [byte[]]
|
54
|
-
def
|
55
|
+
def raw
|
55
56
|
@java.getValue
|
56
57
|
end
|
57
|
-
alias raw value
|
58
58
|
|
59
59
|
# Returns the column value as a String
|
60
60
|
# @return [String]
|
@@ -122,6 +122,17 @@ class Cell
|
|
122
122
|
KeyValue.COMPARATOR.compare(@java, other.java)
|
123
123
|
end
|
124
124
|
|
125
|
+
# Checks if the cells are the same
|
126
|
+
# @param [HBase::Cell] other
|
127
|
+
def eql? other
|
128
|
+
(self <=> other) == 0
|
129
|
+
end
|
130
|
+
alias == eql?
|
131
|
+
|
132
|
+
def hash
|
133
|
+
@java.hasCode
|
134
|
+
end
|
135
|
+
|
125
136
|
# Returns a printable version of this cell
|
126
137
|
# @return [String]
|
127
138
|
def inspect
|
@@ -16,7 +16,7 @@ class HBase
|
|
16
16
|
'cdh4.1' => 'cdh4.1.4',
|
17
17
|
'cdh3' => 'cdh3u6',
|
18
18
|
'0.95' => '0.95.0',
|
19
|
-
'0.94' => '0.94.
|
19
|
+
'0.94' => '0.94.7',
|
20
20
|
'0.92' => '0.92.2',
|
21
21
|
}
|
22
22
|
|
@@ -154,10 +154,6 @@ class HBase
|
|
154
154
|
HBase::Result => %w[
|
155
155
|
org.apache.hadoop.hbase.util.Bytes
|
156
156
|
],
|
157
|
-
HBase::ColumnKey => %w[
|
158
|
-
java.util.Arrays
|
159
|
-
org.apache.hadoop.hbase.util.Bytes
|
160
|
-
],
|
161
157
|
HBase::Table => %w[
|
162
158
|
org.apache.hadoop.hbase.HColumnDescriptor
|
163
159
|
org.apache.hadoop.hbase.HTableDescriptor
|
data/lib/hbase-jruby/hbase.rb
CHANGED
@@ -4,7 +4,7 @@ require 'java'
|
|
4
4
|
# @!attribute [r] config
|
5
5
|
# @return [org.apache.hadoop.conf.Configuration]
|
6
6
|
class HBase
|
7
|
-
attr_reader :config
|
7
|
+
attr_reader :config, :schema
|
8
8
|
|
9
9
|
include Admin
|
10
10
|
|
@@ -61,6 +61,7 @@ class HBase
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
@htable_pool = HTablePool.new @config, java.lang.Integer::MAX_VALUE
|
64
|
+
@schema = Schema.new
|
64
65
|
@closed = false
|
65
66
|
end
|
66
67
|
|
@@ -138,6 +139,20 @@ class HBase
|
|
138
139
|
}
|
139
140
|
end
|
140
141
|
|
142
|
+
# @param [Hash] hash
|
143
|
+
# @return [HBase::Schema]
|
144
|
+
def schema= hash
|
145
|
+
unless hash.is_a?(Hash)
|
146
|
+
raise ArgumentError, "invalid schema: Hash required"
|
147
|
+
end
|
148
|
+
|
149
|
+
schema = Schema.new
|
150
|
+
hash.each do |table, definition|
|
151
|
+
schema[table] = definition
|
152
|
+
end
|
153
|
+
@schema = schema
|
154
|
+
end
|
155
|
+
|
141
156
|
private
|
142
157
|
def check_closed
|
143
158
|
raise RuntimeError, "Connection already closed" if closed?
|