hyperion-riak 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,12 +54,16 @@ module Hyperion
54
54
  end
55
55
 
56
56
  def pack_key(kind, key)
57
- kind, riak_key = Hyperion::Key.decompose_key(key)
58
- riak_key
57
+ if key
58
+ kind, riak_key = Hyperion::Key.decompose_key(key)
59
+ riak_key
60
+ end
59
61
  end
60
62
 
61
63
  def unpack_key(kind, riak_key)
62
- Hyperion::Key.compose_key(kind, riak_key)
64
+ if riak_key
65
+ Hyperion::Key.compose_key(kind, riak_key)
66
+ end
63
67
  end
64
68
 
65
69
  private
@@ -1,29 +1,50 @@
1
1
  function(riak_record) {
2
- var data = Riak.mapValuesJson(riak_record)[0];
2
+ var value, fieldValue, data, isNull;
3
+
4
+ isNull = function(value) {
5
+ return (typeof value === "undefined" || value === null);
6
+ }
7
+
8
+ any = function(value, coll) {
9
+ for (var i = 0; i < coll.length; i++) {
10
+ if (value === coll[i]) {
11
+ return true;
12
+ }
13
+ }
14
+ return false;
15
+ }
16
+
17
+ data = Riak.mapValuesJson(riak_record)[0];
3
18
  <% filters.each do |filter| %>
4
- var value = <%= filter.value.to_json %>
5
- var fieldValue = data[<%= filter.field.to_json %>];
19
+ value = <%= filter.value.to_json %>
20
+ fieldValue = data[<%= filter.field.to_json %>];
6
21
  <% operator = filter.operator %>
7
- <% if operator == "contains?" %>
8
- var found = false;
9
- <% filter.value.each do |item| %>
10
- if (fieldValue == <%= item.to_json %>) {
11
- found = true;
12
- }
13
- <% end %>
14
- if (!found) {
15
- return [];
16
- }
17
- <% elsif operator == "=" %>
18
- if (fieldValue !== value) {
19
- return [];
20
- }
21
- <% elsif operator == "!=" %>
22
- if (fieldValue == value) {
22
+ <% if operator == 'contains?' %>
23
+ if (!any(fieldValue, <%= filter.value.to_json %>)) {
23
24
  return [];
24
25
  }
26
+ <% elsif operator == '=' %>
27
+ <% if filter.value.nil? %>
28
+ if (!isNull(fieldValue)) {
29
+ return [];
30
+ }
31
+ <% else %>
32
+ if (fieldValue !== value) {
33
+ return [];
34
+ }
35
+ <% end %>
36
+ <% elsif operator == '!=' %>
37
+ <% if filter.value.nil? %>
38
+ if (isNull(fieldValue)) {
39
+ return [];
40
+ }
41
+ <% else %>
42
+ if (fieldValue === value) {
43
+ return [];
44
+ }
45
+ <% end %>
25
46
  <% else %>
26
- if (!(fieldValue <%= operator %> value)) {
47
+ if (isNull(fieldValue) || !(fieldValue <%= operator %> value)) {
27
48
  return [];
28
49
  }
29
50
  <% end %>
@@ -38,7 +38,7 @@ module Hyperion
38
38
  end
39
39
 
40
40
  def can_optimize?
41
- !first_equals_filter.nil?
41
+ !first_equals_filter.nil? && !first_equals_filter.value.nil?
42
42
  end
43
43
 
44
44
  def optimal_index_field
@@ -2,7 +2,7 @@ def test_app_name
2
2
  '_HTEST_'
3
3
  end
4
4
 
5
- BUCKETS = ['testing', 'other_testing']
5
+ BUCKETS = ['testing', 'other_testing', 'account', 'shirt']
6
6
 
7
7
  def empty_buckets(ds)
8
8
  client = ds.instance_variable_get(:@client)
@@ -40,7 +40,14 @@ describe Hyperion::Riak::OptimizedFilterOrder do
40
40
  o.optimal_index_field.should == :int
41
41
  end
42
42
 
43
- it 'returns bucket name for optimal_index_value' do
43
+ it 'does not optimize when value is nil' do
44
+ filters = [filter(:int, '=', nil)]
45
+ o = described_class.new(filters, '')
46
+ o.optimal_index_field.should == '$bucket'
47
+ o.filters.should == filters
48
+ end
49
+
50
+ it 'returns optimal_index_value' do
44
51
  filters = [filter(:int, '=', 1)]
45
52
  bucket_name = "hamburgers"
46
53
 
@@ -5,6 +5,7 @@ describe Hyperion::Riak::OptimizedRangeFilters do
5
5
  let(:test_less_than_filter) { filter(:test, '<', 1) }
6
6
  let(:test_greater_than_filter) { filter(:test, '>', 1) }
7
7
  let(:test_equals_filter) { filter(:test, '=', 1) }
8
+ let(:nil_test_equals_filter) { filter(:test, '=', nil) }
8
9
  let(:other_test_less_than_filter) { filter(:other_test, '<', 1) }
9
10
  let(:other_test_greater_than_filter) { filter(:other_test, '>', 1) }
10
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperion-riak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2012-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - '='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.1.3
37
+ version: 0.2.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
- version: 0.1.3
45
+ version: 0.2.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: riak-client
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 1.0.5
53
+ version: 1.1.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.5
61
+ version: 1.1.0
62
62
  description: Riak datastore for Hyperion
63
63
  email:
64
64
  - myles@8thlight.com