hbase-jruby 0.3.0-java → 0.3.1-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.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 0.3.1
5
+ -----
6
+ - Fixed a bug in `'cf:cq' => :type` shortcut schema definition
7
+ - Added schema data type validation
8
+ - Fixed reference to ambiguous column names
9
+
4
10
  0.3.0
5
11
  -----
6
12
  - Easier data access with table schema
@@ -37,9 +37,12 @@ class Row
37
37
  def to_h
38
38
  HASH_TEMPLATE.clone.tap do |ret|
39
39
  @result.getNoVersionMap.each do |cf, cqmap|
40
+ cf = cf.to_s
40
41
  cqmap.each do |cq, val|
41
42
  f, q, t = @table.lookup_schema(cq.to_s)
42
- name = t ? q : [cf.to_s.to_sym, ByteArray[cq]]
43
+ t = nil if f != cf
44
+ name = t ? q : [cf.to_sym, ByteArray[cq]]
45
+
43
46
  ret[name] = Util.from_bytes(t, val)
44
47
  end
45
48
  end
@@ -51,9 +54,11 @@ class Row
51
54
  def to_H
52
55
  HASH_TEMPLATE.clone.tap do |ret|
53
56
  @result.getMap.each do |cf, cqmap|
57
+ cf = cf.to_s
54
58
  cqmap.each do |cq, tsmap|
55
59
  f, q, t = @table.lookup_schema(cq.to_s)
56
- name = t ? q : [cf.to_s.to_sym, ByteArray[cq]]
60
+ t = nil if f != cf
61
+ name = t ? q : [cf.to_sym, ByteArray[cq]]
57
62
 
58
63
  ret[name] =
59
64
  Hash[
@@ -1,4 +1,5 @@
1
1
  require 'forwardable'
2
+ require 'set'
2
3
 
3
4
  class HBase
4
5
  class Schema
@@ -35,7 +36,7 @@ class Schema
35
36
  # CF:CQ => Type shortcut
36
37
  cf = cf.to_s
37
38
  if cf.index(':')
38
- cf, q = key.to_s.split ':', 2
39
+ cf, q = cf.to_s.split ':', 2
39
40
  cols = { q => cols }
40
41
  else
41
42
  raise ArgumentError, "invalid schema: expected Hash" unless cols.is_a?(Hash)
@@ -43,7 +44,10 @@ class Schema
43
44
 
44
45
  # Family => { Column => Type }
45
46
  cols.each do |cq, type|
46
- raise ArgumentError, "invalid schema" unless type.is_a?(Symbol)
47
+ type = type.to_sym
48
+ unless KNOWN_TYPES.include? type
49
+ raise ArgumentError, "invalid schema: unknown type: #{type}"
50
+ end
47
51
 
48
52
  # Pattern
49
53
  case cq
@@ -110,6 +114,17 @@ private
110
114
  }
111
115
  end
112
116
 
117
+ KNOWN_TYPES = Set[
118
+ :string, :str, :symbol, :sym,
119
+ :byte,
120
+ :boolean, :bool,
121
+ :int,
122
+ :short,
123
+ :long, :fixnum,
124
+ :float, :double,
125
+ :bigdecimal,
126
+ :raw
127
+ ]
113
128
  end
114
129
  end
115
130
 
@@ -1,5 +1,5 @@
1
1
  class HBase
2
2
  module JRuby
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
data/test/test_schema.rb CHANGED
@@ -12,6 +12,14 @@ class TestSchema < TestHBaseJRubyBase
12
12
  @hbase.schema.delete @table.name
13
13
  end
14
14
 
15
+ def test_invalid_schema_type
16
+ @hbase.schema = { @table.name => { :cf1 => { :a => 'string' } } }
17
+
18
+ assert_raise(ArgumentError) do
19
+ @hbase.schema = { @table.name => { :cf1 => { :a => :xxx } } }
20
+ end
21
+ end
22
+
15
23
  def test_schema
16
24
  @hbase.schema = {
17
25
  @table.name => {
@@ -27,6 +35,7 @@ class TestSchema < TestHBaseJRubyBase
27
35
 
28
36
  # cf3:f is a 8-byte integer
29
37
  :cf3 => { :f => :fixnum },
38
+ 'cf3:g' => :float
30
39
  }
31
40
  }
32
41
 
@@ -98,6 +107,19 @@ class TestSchema < TestHBaseJRubyBase
98
107
  assert_equal 2, @table.filter( 'a' => 50..110).count
99
108
  assert_equal 2, @table.filter( :a => 50..110).count
100
109
  assert_equal 1, @table.filter(:a => { :gt => 150 }).count
110
+
111
+ # cf:g (automatic type conversion)
112
+ @table.put 3, :g => 3.14
113
+ assert_equal 3.14, @table.get(3)[:g]
114
+ @table.put 3, :g => 314
115
+ assert_equal 314, @table.get(3)[:g]
116
+
117
+ # cf3:g vs. cf2:g
118
+ @table.put 4, :g => 3.14, 'cf2:g' => 'String'
119
+ assert_equal 3.14, @table.get(4)[:g]
120
+ assert_equal 'String', @table.get(4)['cf2:g'].to_s
121
+ assert_equal 3.14, @table.get(4).to_h[:g]
122
+ assert_equal 'String', @table.get(4).to_h['cf2:g'].to_s
101
123
  end
102
124
 
103
125
  def test_schema_readme
metadata CHANGED
@@ -2,30 +2,28 @@
2
2
  name: hbase-jruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
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-20 00:00:00.000000000 Z
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-unit
16
16
  version_requirements: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - '>='
19
19
  - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
20
+ version: '0'
22
21
  none: false
23
22
  requirement: !ruby/object:Gem::Requirement
24
23
  requirements:
25
- - - ">="
24
+ - - '>='
26
25
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
26
+ version: '0'
29
27
  none: false
30
28
  prerelease: false
31
29
  type: :development
@@ -33,17 +31,15 @@ dependencies:
33
31
  name: simplecov
34
32
  version_requirements: !ruby/object:Gem::Requirement
35
33
  requirements:
36
- - - ">="
34
+ - - '>='
37
35
  - !ruby/object:Gem::Version
38
- version: !binary |-
39
- MA==
36
+ version: '0'
40
37
  none: false
41
38
  requirement: !ruby/object:Gem::Requirement
42
39
  requirements:
43
- - - ">="
40
+ - - '>='
44
41
  - !ruby/object:Gem::Version
45
- version: !binary |-
46
- MA==
42
+ version: '0'
47
43
  none: false
48
44
  prerelease: false
49
45
  type: :development
@@ -54,7 +50,7 @@ executables: []
54
50
  extensions: []
55
51
  extra_rdoc_files: []
56
52
  files:
57
- - ".gitignore"
53
+ - .gitignore
58
54
  - CHANGELOG.md
59
55
  - Gemfile
60
56
  - LICENSE.txt
@@ -96,17 +92,15 @@ require_paths:
96
92
  - lib
97
93
  required_ruby_version: !ruby/object:Gem::Requirement
98
94
  requirements:
99
- - - ">="
95
+ - - '>='
100
96
  - !ruby/object:Gem::Version
101
- version: !binary |-
102
- MA==
97
+ version: '0'
103
98
  none: false
104
99
  required_rubygems_version: !ruby/object:Gem::Requirement
105
100
  requirements:
106
- - - ">="
101
+ - - '>='
107
102
  - !ruby/object:Gem::Version
108
- version: !binary |-
109
- MA==
103
+ version: '0'
110
104
  none: false
111
105
  requirements: []
112
106
  rubyforge_project: