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/lib/hbase-jruby/row.rb
CHANGED
@@ -10,363 +10,250 @@ class Row
|
|
10
10
|
# @param [Symbol] type The type of the rowkey
|
11
11
|
# Can be one of :string, :symbol, :fixnum, :float, :short, :int, :bigdecimal, :boolean and :raw.
|
12
12
|
# @return [String, byte[]]
|
13
|
-
def rowkey type = :
|
13
|
+
def rowkey type = :raw
|
14
14
|
Util.from_bytes type, @result.getRow
|
15
15
|
end
|
16
16
|
|
17
17
|
# Enumerates through cells
|
18
18
|
def each
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
else
|
24
|
-
self
|
19
|
+
return enum_for(:each) unless block_given?
|
20
|
+
@result.raw.each do |kv|
|
21
|
+
yield Cell.new(@table, kv)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
def [] *col
|
26
|
+
col = col.length == 1 ? col[0] : col
|
27
|
+
cf, cq, type = @table.lookup_schema(col)
|
28
|
+
if cf
|
29
|
+
self.send type, [cf, cq]
|
30
|
+
else
|
31
|
+
self.raw col
|
32
|
+
end
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
+
# Only supports string column qualifiers
|
36
|
+
# @return [Hash]
|
37
|
+
def to_h
|
38
|
+
HASH_TEMPLATE.clone.tap do |ret|
|
35
39
|
@result.getNoVersionMap.each do |cf, cqmap|
|
36
40
|
cqmap.each do |cq, val|
|
37
|
-
|
38
|
-
|
39
|
-
ret[name] =
|
41
|
+
f, q, t = @table.lookup_schema(cq.to_s)
|
42
|
+
name = t ? q : [cf.to_s.to_sym, ByteArray[cq]]
|
43
|
+
ret[name] = Util.from_bytes(t, val)
|
40
44
|
end
|
41
45
|
end
|
42
|
-
|
46
|
+
end
|
43
47
|
end
|
48
|
+
alias to_hash to_h
|
44
49
|
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
# @return [Hash<Hash>] Hash representation of the row indexed by ColumnKey
|
49
|
-
def to_hash_with_versions schema = {}
|
50
|
-
schema = parse_schema schema
|
51
|
-
|
52
|
-
HASH_TEMPLATE.clone.tap { |ret|
|
50
|
+
# @return [Hash]
|
51
|
+
def to_H
|
52
|
+
HASH_TEMPLATE.clone.tap do |ret|
|
53
53
|
@result.getMap.each do |cf, cqmap|
|
54
54
|
cqmap.each do |cq, tsmap|
|
55
|
-
|
56
|
-
|
55
|
+
f, q, t = @table.lookup_schema(cq.to_s)
|
56
|
+
name = t ? q : [cf.to_s.to_sym, ByteArray[cq]]
|
57
57
|
|
58
58
|
ret[name] =
|
59
59
|
Hash[
|
60
60
|
tsmap.map { |ts, val|
|
61
|
-
[ ts,
|
61
|
+
[ ts, Util.from_bytes(t, val) ]
|
62
62
|
}
|
63
63
|
]
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
end
|
67
67
|
end
|
68
|
+
alias to_hash_with_versions to_H
|
68
69
|
|
69
70
|
# Returns column values as byte arrays
|
70
71
|
# @overload raw(column)
|
71
72
|
# Returns the latest column value as a byte array
|
72
|
-
# @param [String,
|
73
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
73
74
|
# @return [byte[]] Byte array representation of the latest value
|
74
|
-
|
75
|
-
|
76
|
-
# returns the latest column value as a byte array
|
77
|
-
# @param [<String|HBase::ColumnKey>] column "FAMILY:QUALIFIER" expression or ColumnKey object.
|
78
|
-
# @return [Array<byte[]>] Byte array representations of the latest values
|
79
|
-
def raw cols
|
80
|
-
ret = get_values [*cols]
|
81
|
-
|
82
|
-
case cols
|
83
|
-
when Array
|
84
|
-
ret
|
85
|
-
else
|
86
|
-
ret.first
|
87
|
-
end
|
75
|
+
def raw col
|
76
|
+
get_value col
|
88
77
|
end
|
89
78
|
|
90
79
|
# Returns all versions of column values as byte arrays in a Hash indexed by their timestamps
|
91
80
|
# @overload raws(column)
|
92
81
|
# Returns all versions of column values as byte arrays in a Hash indexed by their timestamps
|
93
|
-
# @param [String,
|
82
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
94
83
|
# @return [Hash<Fixnum, byte[]>]
|
95
|
-
|
96
|
-
|
97
|
-
# returns all versions of column values as byte arrays in a Hash indexed by their timestamps
|
98
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
99
|
-
# @return [Array<Hash<Fixnum, byte[]>>]
|
100
|
-
def raws cols
|
101
|
-
ret = get_values [*cols], true
|
102
|
-
|
103
|
-
case cols
|
104
|
-
when Array
|
105
|
-
ret
|
106
|
-
else
|
107
|
-
ret.first
|
108
|
-
end
|
84
|
+
def raws col
|
85
|
+
get_value col, true
|
109
86
|
end
|
110
87
|
|
111
88
|
# Returns column values as Strings
|
112
89
|
# @overload string(column)
|
113
90
|
# Returns the latest column value as a String
|
114
|
-
# @param [String,
|
91
|
+
# @param [String, Array] col Column name as String or 2-element Array of family and qualifier
|
115
92
|
# @return [String]
|
116
|
-
|
117
|
-
|
118
|
-
# returns the latest column value as a String
|
119
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
120
|
-
# @return [Array<String>]
|
121
|
-
def string cols
|
122
|
-
decode_values :string, cols
|
93
|
+
def string col
|
94
|
+
decode_value :string, col
|
123
95
|
end
|
124
96
|
alias str string
|
125
97
|
|
126
98
|
# Returns all versions of column values as Strings in a Hash indexed by their timestamps
|
127
99
|
# @overload strings(column)
|
128
100
|
# Returns all versions of column values as Strings in a Hash indexed by their timestamps
|
129
|
-
# @param [String,
|
101
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
130
102
|
# @return [Hash<Fixnum, String>]
|
131
|
-
|
132
|
-
|
133
|
-
# returns all versions of column values as Strings in a Hash indexed by their timestamps
|
134
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
135
|
-
# @return [Array<Hash<Fixnum, String>>]
|
136
|
-
def strings cols
|
137
|
-
decode_values :string, cols, true
|
103
|
+
def strings col
|
104
|
+
decode_value :string, col, true
|
138
105
|
end
|
139
106
|
alias strs strings
|
140
107
|
|
141
108
|
# Returns column values as Symbols
|
142
109
|
# @overload symbol(column)
|
143
110
|
# Returns the latest column value as a Symbol
|
144
|
-
# @param [String,
|
111
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
145
112
|
# @return [Symbol]
|
146
|
-
|
147
|
-
|
148
|
-
# returns the latest column values as a Symbol
|
149
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
150
|
-
# @return [Array<Symbol>]
|
151
|
-
def symbol cols
|
152
|
-
decode_values :symbol, cols
|
113
|
+
def symbol col
|
114
|
+
decode_value :symbol, col
|
153
115
|
end
|
154
116
|
alias sym symbol
|
155
117
|
|
156
118
|
# Returns all versions of column values as Symbols in a Hash indexed by their timestamps
|
157
119
|
# @overload symbols(column)
|
158
120
|
# Returns all versions of column values as Symbols in a Hash indexed by their timestamps
|
159
|
-
# @param [String,
|
121
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
160
122
|
# @return [Hash<Fixnum, Symbol>]
|
161
|
-
|
162
|
-
|
163
|
-
# returns all versions of column values as Symbols in a Hash indexed by their timestamps
|
164
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
165
|
-
# @return [Array<Hash<Fixnum, Symbol>>]
|
166
|
-
def symbols cols
|
167
|
-
decode_values :symbol, cols, true
|
123
|
+
def symbols col
|
124
|
+
decode_value :symbol, col, true
|
168
125
|
end
|
169
126
|
alias syms symbols
|
170
127
|
|
171
128
|
# Returns 1-byte column values as Fixnums
|
172
129
|
# @overload byte(column)
|
173
130
|
# Returns the latest column value as a Fixnum
|
174
|
-
# @param [String,
|
131
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
175
132
|
# @return [Fixnum]
|
176
|
-
|
177
|
-
|
178
|
-
# returns the latest 1-byte column values as a Fixnum
|
179
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
180
|
-
# @return [Array<Fixnum>]
|
181
|
-
def byte cols
|
182
|
-
decode_values :byte, cols
|
133
|
+
def byte col
|
134
|
+
decode_value :byte, col
|
183
135
|
end
|
184
136
|
|
185
137
|
# Returns all versions of 1-byte column values as Fixnums in a Hash indexed by their timestamps
|
186
138
|
# @overload bytes(column)
|
187
139
|
# Returns all versions of column values as Fixnums in a Hash indexed by their timestamps
|
188
|
-
# @param [String,
|
140
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
189
141
|
# @return [Hash<Fixnum, Fixnum>]
|
190
|
-
|
191
|
-
|
192
|
-
# returns all versions of 1-byte column values as Fixnums in a Hash indexed by their timestamps
|
193
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
194
|
-
# @return [Array<Hash<Fixnum, Fixnum>>]
|
195
|
-
def bytes cols
|
196
|
-
decode_values :byte, cols, true
|
142
|
+
def bytes col
|
143
|
+
decode_value :byte, col, true
|
197
144
|
end
|
198
145
|
|
199
146
|
# Returns 2-byte column values as Fixnums
|
200
147
|
# @overload short(column)
|
201
148
|
# Returns the latest 2-byte column value as a Fixnum
|
202
|
-
# @param [String,
|
149
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
203
150
|
# @return [Fixnum]
|
204
|
-
|
205
|
-
|
206
|
-
# returns the latest 2-byte column values as a Fixnum
|
207
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
208
|
-
# @return [Array<Fixnum>]
|
209
|
-
def short cols
|
210
|
-
decode_values :short, cols
|
151
|
+
def short col
|
152
|
+
decode_value :short, col
|
211
153
|
end
|
212
154
|
|
213
155
|
# Returns all versions of 2-byte column values as Fixnums in a Hash indexed by their timestamps
|
214
156
|
# @overload shorts(column)
|
215
157
|
# Returns all versions of 2-byte column values as Fixnums in a Hash indexed by their timestamps
|
216
|
-
# @param [String,
|
158
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
217
159
|
# @return [Hash<Fixnum, Fixnum>]
|
218
|
-
|
219
|
-
|
220
|
-
# returns all versions of 2-byte column values as Fixnums in a Hash indexed by their timestamps
|
221
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
222
|
-
# @return [Array<Hash<Fixnum, Fixnum>>]
|
223
|
-
def shorts cols
|
224
|
-
decode_values :short, cols, true
|
160
|
+
def shorts col
|
161
|
+
decode_value :short, col, true
|
225
162
|
end
|
226
163
|
|
227
164
|
# Returns 4-byte column values as Fixnums
|
228
165
|
# @overload int(column)
|
229
166
|
# Returns the latest 4-byte column value as a Fixnum
|
230
|
-
# @param [String,
|
167
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
231
168
|
# @return [Fixnum]
|
232
|
-
|
233
|
-
|
234
|
-
# returns the latest 4-byte column values as a Fixnum
|
235
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
236
|
-
# @return [Array<Fixnum>]
|
237
|
-
def int cols
|
238
|
-
decode_values :int, cols
|
169
|
+
def int col
|
170
|
+
decode_value :int, col
|
239
171
|
end
|
240
172
|
|
241
173
|
# Returns all versions of 4-byte column values as Fixnums in a Hash indexed by their timestamps
|
242
174
|
# @overload ints(column)
|
243
175
|
# Returns all versions of 4-byte column values as Fixnums in a Hash indexed by their timestamps
|
244
|
-
# @param [String,
|
176
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
245
177
|
# @return [Hash<Fixnum, Fixnum>]
|
246
|
-
|
247
|
-
|
248
|
-
# returns all versions of 4-byte column values as Fixnums in a Hash indexed by their timestamps
|
249
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
250
|
-
# @return [Array<Hash<Fixnum, Fixnum>>]
|
251
|
-
def ints cols
|
252
|
-
decode_values :int, cols, true
|
178
|
+
def ints col
|
179
|
+
decode_value :int, col, true
|
253
180
|
end
|
254
181
|
|
255
182
|
# Returns 8-byte column values as Fixnums
|
256
183
|
# @overload fixnum(column)
|
257
184
|
# Returns the latest 8-byte column value as a Fixnum
|
258
|
-
# @param [String,
|
185
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
259
186
|
# @return [Fixnum]
|
260
|
-
|
261
|
-
|
262
|
-
# returns the latest 8-byte column values as a Fixnum
|
263
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
264
|
-
# @return [Array<Fixnum>]
|
265
|
-
def fixnum cols
|
266
|
-
decode_values :fixnum, cols
|
187
|
+
def fixnum col
|
188
|
+
decode_value :fixnum, col
|
267
189
|
end
|
268
190
|
alias long fixnum
|
269
191
|
|
270
192
|
# Returns all versions of 8-byte column values as Fixnums in a Hash indexed by their timestamps
|
271
193
|
# @overload fixnums(column)
|
272
194
|
# Returns all versions of 8-byte column values as Fixnums in a Hash indexed by their timestamps
|
273
|
-
# @param [String,
|
195
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
274
196
|
# @return [Hash<Fixnum, Fixnum>]
|
275
|
-
|
276
|
-
|
277
|
-
# returns all versions of 8-byte column values as Fixnums in a Hash indexed by their timestamps
|
278
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
279
|
-
# @return [Array<Hash<Fixnum, Fixnum>>]
|
280
|
-
def fixnums cols
|
281
|
-
decode_values :fixnum, cols, true
|
197
|
+
def fixnums col
|
198
|
+
decode_value :fixnum, col, true
|
282
199
|
end
|
283
200
|
alias longs fixnums
|
284
201
|
|
285
202
|
# Returns column values as Bigdecimals
|
286
203
|
# @overload bigdecimal(column)
|
287
204
|
# Returns the latest column value as a BigDecimal
|
288
|
-
# @param [String,
|
205
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
289
206
|
# @return [BigDecimal]
|
290
|
-
|
291
|
-
|
292
|
-
# returns the latest column values as a BigDecimal
|
293
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
294
|
-
# @return [Array<BigDecimal>]
|
295
|
-
def bigdecimal cols
|
296
|
-
decode_values :bigdecimal, cols
|
207
|
+
def bigdecimal col
|
208
|
+
decode_value :bigdecimal, col
|
297
209
|
end
|
298
210
|
|
299
211
|
# Returns all versions of column values as BigDecimals in a Hash indexed by their timestamps
|
300
212
|
# @overload bigdecimals(column)
|
301
213
|
# Returns all versions of column values as BigDecimals in a Hash indexed by their timestamps
|
302
|
-
# @param [String,
|
214
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
303
215
|
# @return [Hash<Fixnum, BigDecimal>]
|
304
|
-
|
305
|
-
|
306
|
-
# returns all versions of column values as BigDecimals in a Hash indexed by their timestamps
|
307
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
308
|
-
# @return [Array<Hash<Fixnum, BigDecimal>>]
|
309
|
-
def bigdecimals cols
|
310
|
-
decode_values :bigdecimal, cols, true
|
216
|
+
def bigdecimals col
|
217
|
+
decode_value :bigdecimal, col, true
|
311
218
|
end
|
312
219
|
|
313
220
|
# Returns column values as Floats
|
314
221
|
# @overload float(column)
|
315
222
|
# Returns the latest column value as a Float
|
316
|
-
# @param [String,
|
223
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
317
224
|
# @return [Float]
|
318
|
-
|
319
|
-
|
320
|
-
# returns the latest column values as a Float
|
321
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
322
|
-
# @return [Array<Float>]
|
323
|
-
def float cols
|
324
|
-
decode_values :float, cols
|
225
|
+
def float col
|
226
|
+
decode_value :float, col
|
325
227
|
end
|
326
228
|
alias double float
|
327
229
|
|
328
230
|
# Returns all versions of column values as Floats in a Hash indexed by their timestamps
|
329
231
|
# @overload floats(column)
|
330
232
|
# Returns all versions of column values as Floats in a Hash indexed by their timestamps
|
331
|
-
# @param [String,
|
233
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
332
234
|
# @return [Hash<Fixnum, Float>]
|
333
|
-
|
334
|
-
|
335
|
-
# returns all versions of column values as Floats in a Hash indexed by their timestamps
|
336
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
337
|
-
# @return [Array<Hash<Fixnum, Float>>]
|
338
|
-
def floats cols
|
339
|
-
decode_values :float, cols, true
|
235
|
+
def floats col
|
236
|
+
decode_value :float, col, true
|
340
237
|
end
|
341
238
|
alias doubles floats
|
342
239
|
|
343
240
|
# Returns column values as Booleans
|
344
241
|
# @overload boolean(column)
|
345
242
|
# Returns the latest column value as a boolean value
|
346
|
-
# @param [String,
|
243
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
347
244
|
# @return [true, false]
|
348
|
-
|
349
|
-
|
350
|
-
# returns the latest column values as a boolean value
|
351
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
352
|
-
# @return [Array<true|false>]
|
353
|
-
def boolean cols
|
354
|
-
decode_values :boolean, cols
|
245
|
+
def boolean col
|
246
|
+
decode_value :boolean, col
|
355
247
|
end
|
356
248
|
alias bool boolean
|
357
249
|
|
358
250
|
# Returns all versions of column values as Booleans in a Hash indexed by their timestamps
|
359
251
|
# @overload booleans(column)
|
360
252
|
# Returns all versions of column values as boolean values in a Hash indexed by their timestamps
|
361
|
-
# @param [String,
|
253
|
+
# @param [String, Array] column Column name as String or 2-element Array of family and qualifier
|
362
254
|
# @return [Hash<Fixnum, true|false>]
|
363
|
-
|
364
|
-
|
365
|
-
# returns all versions of column values as boolean values in a Hash indexed by their timestamps
|
366
|
-
# @param [Array<String|HBase::ColumnKey>] columns Array of "FAMILY:QUALIFIER" expressions and ColumnKey objects.
|
367
|
-
# @return [Array<Hash<Fixnum, true|false>>]
|
368
|
-
def booleans cols
|
369
|
-
decode_values :boolean, cols, true
|
255
|
+
def booleans col
|
256
|
+
decode_value :boolean, col, true
|
370
257
|
end
|
371
258
|
alias bools booleans
|
372
259
|
|
@@ -376,57 +263,49 @@ class Row
|
|
376
263
|
end
|
377
264
|
|
378
265
|
private
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
cf, cq = Util.parse_column_name key
|
388
|
-
ColumnKey.new(cf, cq)
|
389
|
-
end
|
390
|
-
super ck
|
391
|
-
end
|
266
|
+
def get_value col, with_versions = false
|
267
|
+
cf, cq = Util.parse_column_name(col)
|
268
|
+
if with_versions
|
269
|
+
# Need to make it a Ruby hash:
|
270
|
+
# Prevents implicit conversion from ruby type to java type when updating the Hash
|
271
|
+
Hash[ allmap.fetch(cf, {}).fetch(cq, {}) ]
|
272
|
+
else
|
273
|
+
@result.getValue cf, cq
|
392
274
|
end
|
393
|
-
|
275
|
+
end
|
394
276
|
|
395
|
-
def
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
# Need to make it a Ruby hash:
|
401
|
-
# Prevents implicit conversion from ruby type to java type when updating the Hash
|
402
|
-
Hash[ allmap.fetch(cf, {}).fetch(cq, {}) ]
|
403
|
-
else
|
404
|
-
@result.getValue cf, cq
|
277
|
+
def decode_value type, col, with_versions = false
|
278
|
+
v = get_value(col, with_versions)
|
279
|
+
if with_versions
|
280
|
+
v.each do |k, raw|
|
281
|
+
v[k] = Util.from_bytes type, raw
|
405
282
|
end
|
406
|
-
|
283
|
+
v
|
284
|
+
else
|
285
|
+
Util.from_bytes type, v
|
286
|
+
end
|
407
287
|
end
|
408
288
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
289
|
+
HASH_TEMPLATE = {}.tap { |h|
|
290
|
+
h.instance_eval do
|
291
|
+
def [] key
|
292
|
+
# %w[cf x]
|
293
|
+
if key.is_a?(Array) && key.length == 2
|
294
|
+
key = [key[0].to_sym, ByteArray[key[1]]]
|
295
|
+
# %[cf:x]
|
296
|
+
elsif key.is_a?(String) && key.index(':')
|
297
|
+
cf, cq = key.split(':', 2)
|
298
|
+
key = [cf.to_sym, ByteArray[cq]]
|
414
299
|
end
|
415
|
-
|
416
|
-
else
|
417
|
-
Util.from_bytes type, v
|
300
|
+
super key
|
418
301
|
end
|
419
|
-
}
|
420
|
-
case cols
|
421
|
-
when Array
|
422
|
-
ret
|
423
|
-
else
|
424
|
-
ret.first
|
425
302
|
end
|
426
|
-
|
303
|
+
}
|
427
304
|
|
305
|
+
# @param [HBase::Table] table
|
428
306
|
# @param [org.apache.hadoop.hbase.client.Result] java_result
|
429
|
-
def initialize java_result
|
307
|
+
def initialize table, java_result
|
308
|
+
@table = table
|
430
309
|
@result = java_result
|
431
310
|
@allmap = nil
|
432
311
|
end
|
@@ -434,22 +313,6 @@ private
|
|
434
313
|
def allmap
|
435
314
|
@allmap ||= @result.getMap
|
436
315
|
end
|
437
|
-
|
438
|
-
def parse_schema schema
|
439
|
-
{}.tap { |ret|
|
440
|
-
schema.each do |name, type|
|
441
|
-
ck =
|
442
|
-
case name
|
443
|
-
when ColumnKey
|
444
|
-
name
|
445
|
-
else
|
446
|
-
cf, cq = Util.parse_column_name(name)
|
447
|
-
ColumnKey.new(cf, cq)
|
448
|
-
end
|
449
|
-
ret[ck] = type
|
450
|
-
end
|
451
|
-
}
|
452
|
-
end
|
453
316
|
end#Row
|
454
317
|
end#HBase
|
455
318
|
|