hbase-jruby 0.2.5-java → 0.2.6-java

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.2.6
5
+ -----
6
+ - Fixed `HBase::Scoped#filter` method to take short integer (byte, short, int) values
7
+ - Fixed `HBase::Scoped#range` method to take short integer (byte, short, int) values
8
+
4
9
  0.2.5
5
10
  -----
6
11
  - Added `HBase::Table#snapshots` method
data/README.md CHANGED
@@ -68,8 +68,8 @@ Call `HBase.resolve_dependency!` helper method passing one of the arguments list
68
68
 
69
69
  | Argument | Dependency | Default version | Required executable |
70
70
  | ---------- | ------------------------ | --------------- | ------------------- |
71
- | cdh4.2[.*] | Cloudera CDH4.2 | cdh4.2.0 | mvn |
72
- | cdh4.1[.*] | Cloudera CDH4.1 | cdh4.1.3 | mvn |
71
+ | cdh4.2[.*] | Cloudera CDH4.2 | cdh4.2.1 | mvn |
72
+ | cdh4.1[.*] | Cloudera CDH4.1 | cdh4.1.4 | mvn |
73
73
  | cdh3[u*] | Cloudera CDH3 | cdh3u6 | mvn |
74
74
  | 0.95[.*] | Apache HBase 0.95 | 0.95.0 | mvn |
75
75
  | 0.94[.*] | Apache HBase 0.94 | 0.94.6.1 | mvn |
@@ -492,10 +492,10 @@ See the following example.
492
492
  table.put idx, 'cf1:a' => idx % 10
493
493
  end
494
494
 
495
- table.filter('cf1:a' => { lte: 1 }).to_a
496
- # 0, 1, 10, 11, 20, 21
497
- table.while('cf1:a' => { lte: 1 }).to_a
498
- # 0, 1
495
+ table.filter('cf1:a' => { lte: 1 }).map { |r| r.rowkey :fixnum }
496
+ # [0, 1, 10, 11, 20, 21]
497
+ table.while('cf1:a' => { lte: 1 }).map { |r| r.rowkey :fixnum }
498
+ # [0, 1]
499
499
  # Scan terminates immediately when condition not met.
500
500
  ```
501
501
 
@@ -121,25 +121,32 @@ class Scoped
121
121
  # table.range(:prefix => '2012')
122
122
  # table.range(:prefix => ['2010', '2012'])
123
123
  def range *key_range
124
- if key_range.last.is_a?(Hash)
125
- prefixes = arrayfy(key_range.last[:prefix]).compact
126
- raise ArgumentError,
127
- "Invalid range. Unknown option(s) specified." unless (key_range.last.keys - [:prefix]).empty?
128
- key_range = key_range[0...-1]
124
+ if (last = key_range.last).is_a?(Hash)
125
+ prefixes = arrayfy(last[:prefix]).compact
126
+ last = last.reject { |k, v| k == :prefix }
127
+
128
+ key_range = key_range[0...-1] # defensive
129
+ key_range << last unless last.empty?
130
+ else
131
+ prefixes = []
129
132
  end
130
133
 
131
- if prefixes
134
+ if key_range[0].is_a?(Range)
135
+ raise ArgumentError, "Invalid range" unless key_range.length == 1
136
+ elsif !prefixes.empty?
132
137
  raise ArgumentError, "Invalid range" unless [0, 1, 2].include?(key_range.length)
133
138
  else
134
139
  raise ArgumentError, "Invalid range" unless [1, 2].include?(key_range.length)
135
140
  end
136
141
 
142
+ raise ArgumentError, "Invalid range" if !key_range.empty? && key_range.all? { |e| e.nil? }
143
+
137
144
  spawn :@range,
138
145
  key_range[0].is_a?(Range) ?
139
146
  key_range[0] :
140
- (key_range.empty? ? nil : key_range),
147
+ (key_range.empty? ? nil : key_range.map { |e| e.nil? ? nil : Util.to_bytes(e) }),
141
148
  :@prefixes,
142
- prefixes || []
149
+ prefixes
143
150
  end
144
151
 
145
152
  # Returns an HBase::Scoped object with the filters added
@@ -368,12 +375,12 @@ private
368
375
  filters <<
369
376
  RowFilter.new(
370
377
  CompareFilter::CompareOp::GREATER_OR_EQUAL,
371
- BinaryComparator.new(Util.to_bytes range[0])) if range[0]
378
+ BinaryComparator.new(range[0])) if range[0]
372
379
 
373
380
  filters <<
374
381
  RowFilter.new(
375
382
  CompareFilter::CompareOp::LESS,
376
- BinaryComparator.new(Util.to_bytes range[1])) if range[1]
383
+ BinaryComparator.new(range[1])) if range[1]
377
384
  else
378
385
  raise ArgumentError, "Invalid range"
379
386
  end if range
@@ -432,7 +439,11 @@ private
432
439
  when :ne # , :!= # Ruby 1.8 compatibility
433
440
  CompareFilter::CompareOp::NOT_EQUAL
434
441
  else
435
- raise ArgumentError, "Unknown operator: #{op}"
442
+ if val.length == 1
443
+ return filter_for(cf, cq, Util.to_bytes(val))
444
+ else
445
+ raise ArgumentError, "Unknown operator: #{op}"
446
+ end
436
447
  end
437
448
  case v
438
449
  when Array
@@ -448,8 +459,6 @@ private
448
459
  SingleColumnValueFilter.new(cf, cq, operator, Util.to_bytes(vv))
449
460
  }
450
461
  )
451
- when Hash
452
- raise ArgumentError, "Hash predicate not supported"
453
462
  else
454
463
  SingleColumnValueFilter.new(cf, cq, operator, Util.to_bytes(v))
455
464
  end
@@ -483,8 +492,8 @@ private
483
492
  scan.setStopRow Util.append_0(Util.to_bytes range.end)
484
493
  end
485
494
  when Array
486
- scan.setStartRow Util.to_bytes range[0] if range[0]
487
- scan.setStopRow Util.to_bytes range[1] if range[1]
495
+ scan.setStartRow range[0] if range[0]
496
+ scan.setStopRow range[1] if range[1]
488
497
  else
489
498
  # This shouldn't happen though.
490
499
  raise ArgumentError, "Invalid range"
@@ -1,5 +1,5 @@
1
1
  class HBase
2
2
  module JRuby
3
- VERSION = "0.2.5"
3
+ VERSION = '0.2.6'
4
4
  end
5
5
  end
data/test/test_scoped.rb CHANGED
@@ -25,7 +25,10 @@ class TestScoped < TestHBaseJRubyBase
25
25
  def test_invalid_range
26
26
  assert_raise(ArgumentError) { @table.range }
27
27
  assert_raise(ArgumentError) { @table.range(:xxx => 'row1') }
28
+ assert_raise(ArgumentError) { @table.range({}) }
28
29
  assert_raise(ArgumentError) { @table.range(1, 2, 3) }
30
+ assert_raise(ArgumentError) { @table.range(nil, nil) }
31
+ assert_raise(ArgumentError) { @table.range(1..3, 4..5) }
29
32
  end
30
33
 
31
34
  def test_invalid_project
@@ -96,6 +99,46 @@ class TestScoped < TestHBaseJRubyBase
96
99
  assert_equal 50, @table.range(111..150).filter('cf1:a' => 131...140, 'cf2:b' => 132..133).unscope.count
97
100
  end
98
101
 
102
+ def test_range_on_short_int
103
+ (1..10).each do |i|
104
+ @table.put({ :short => i }, 'cf1:a' => 'dummy')
105
+ end
106
+
107
+ assert_equal 5, @table.range({ :short => 6 }).count
108
+ assert_equal 2, @table.range({ :short => 6 }, { :short => 8 }).count
109
+ assert_equal 2, @table.range({ :short => 6 }, { :short => 8, :prefix => []}).count
110
+ assert_equal 2, @table.range({ :short => 6 }, { :short => 8 }, :prefix => []).count
111
+ assert_equal 3, @table.range(nil, { :short => 4 }).count
112
+ assert_equal 3, @table.range(nil, { :short => 4, :prefix => [] }).count
113
+ assert_equal 3, @table.range(nil, { :short => 4 }, :prefix => []).count
114
+ end
115
+
116
+ def test_filter_on_short_int
117
+ @table.put(1, 'cf1:a' => { :long => 100 })
118
+ @table.put(2, 'cf1:a' => { :int => 100 })
119
+ @table.put(3, 'cf1:a' => { :short => 100 })
120
+ @table.put(4, 'cf1:a' => { :byte => 100 })
121
+ @table.put(5, 'cf1:a' => { :byte => 110 })
122
+
123
+ assert_equal 1, @table.filter('cf1:a' => { :long => 100 }).count
124
+ assert_equal 1, @table.filter('cf1:a' => { :int => 100 }).count
125
+ assert_equal 1, @table.filter('cf1:a' => { :short => 100 }).count
126
+ assert_equal 1, @table.filter('cf1:a' => { :byte => 100 }).count
127
+
128
+ assert_equal 1, @table.filter('cf1:a' => { :long => 100 }).first.rowkey(:fixnum)
129
+ assert_equal 2, @table.filter('cf1:a' => { :int => 100 }).first.rowkey(:fixnum)
130
+ assert_equal 3, @table.filter('cf1:a' => { :short => 100 }).first.rowkey(:fixnum)
131
+ assert_equal 4, @table.filter('cf1:a' => { :byte => 100 }).first.rowkey(:fixnum)
132
+
133
+ assert_equal 5, @table.filter('cf1:a' => { :gt => { :byte => 100 } }).first.rowkey(:fixnum)
134
+ end
135
+
136
+ def test_filter_operator_and_short_int
137
+ assert_raise(ArgumentError) {
138
+ @table.filter('cf1:a' => { :long => 100, :gt => 10 })
139
+ }
140
+ end
141
+
99
142
  def test_scan
100
143
  insert = lambda do
101
144
  (40..70).each do |i|
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: hbase-jruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.2.6
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-05-02 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit