datastax_rails 1.0.14.2 → 1.0.14.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/datastax_rails/attribute_methods/definition.rb +1 -1
- data/lib/datastax_rails/persistence.rb +4 -4
- data/lib/datastax_rails/relation/search_methods.rb +3 -3
- data/lib/datastax_rails/relation/spawn_methods.rb +2 -3
- data/lib/datastax_rails/serializers/xml_serializer.rb +3 -0
- data/lib/datastax_rails/tasks/column_family.rb +3 -3
- data/lib/datastax_rails/types/date_type.rb +2 -1
- data/lib/datastax_rails/types/float_type.rb +6 -6
- data/lib/datastax_rails/types/integer_type.rb +6 -6
- data/lib/datastax_rails/types/string_type.rb +1 -0
- data/lib/datastax_rails/types/time_type.rb +1 -0
- data/lib/datastax_rails/version.rb +1 -1
- data/spec/datastax_rails/types/integer_type_spec.rb +35 -0
- data/spec/dummy/log/development.log +64 -0
- data/spec/dummy/log/test.log +1478 -0
- metadata +6 -4
@@ -100,9 +100,9 @@ module DatastaxRails
|
|
100
100
|
def encode_attributes(attributes, schema_version)
|
101
101
|
encoded = {"schema_version" => schema_version.to_s}
|
102
102
|
attributes.each do |column_name, value|
|
103
|
-
if value.nil?
|
104
|
-
encoded[column_name.to_s] = ""
|
105
|
-
else
|
103
|
+
# if value.nil?
|
104
|
+
# encoded[column_name.to_s] = ""
|
105
|
+
# else
|
106
106
|
encoded_value = attribute_definitions[column_name.to_sym].coder.encode(value)
|
107
107
|
if(encoded_value.is_a?(Array))
|
108
108
|
encoded_value.each_with_index do |chunk,i|
|
@@ -111,7 +111,7 @@ module DatastaxRails
|
|
111
111
|
else
|
112
112
|
encoded[column_name.to_s] = encoded_value
|
113
113
|
end
|
114
|
-
end
|
114
|
+
# end
|
115
115
|
end
|
116
116
|
encoded
|
117
117
|
end
|
@@ -71,7 +71,7 @@ module DatastaxRails
|
|
71
71
|
# end
|
72
72
|
def limit(value)
|
73
73
|
clone.tap do |r|
|
74
|
-
r.per_page_value = value
|
74
|
+
r.per_page_value = value.to_i
|
75
75
|
end
|
76
76
|
end
|
77
77
|
alias :per_page :limit
|
@@ -81,7 +81,7 @@ module DatastaxRails
|
|
81
81
|
# Model.page(2)
|
82
82
|
def page(value)
|
83
83
|
clone.tap do |r|
|
84
|
-
r.page_value = value
|
84
|
+
r.page_value = value.to_i
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -104,7 +104,7 @@ module DatastaxRails
|
|
104
104
|
return self if attrs.blank?
|
105
105
|
|
106
106
|
clone.tap do |r|
|
107
|
-
r.group_values +=
|
107
|
+
r.group_values += attrs.flatten
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -86,7 +86,7 @@ module DatastaxRails
|
|
86
86
|
result
|
87
87
|
end
|
88
88
|
|
89
|
-
VALID_FIND_OPTIONS = [:conditions, :limit, :offset, :order, :group, :page, :per_page]
|
89
|
+
VALID_FIND_OPTIONS = [:conditions, :limit, :select, :offset, :order, :group, :page, :per_page]
|
90
90
|
def apply_finder_options(options) #:nodoc:
|
91
91
|
relation = clone
|
92
92
|
return relation unless options
|
@@ -95,12 +95,11 @@ module DatastaxRails
|
|
95
95
|
finders = options.dup
|
96
96
|
finders.delete_if { |key, value| value.nil? }
|
97
97
|
|
98
|
-
([:group, :order, :limit, :offset, :page, :per_page] & finders.keys).each do |finder|
|
98
|
+
([:group, :order, :limit, :offset, :page, :per_page, :select] & finders.keys).each do |finder|
|
99
99
|
relation = relation.send(finder, finders[finder])
|
100
100
|
end
|
101
101
|
|
102
102
|
relation = relation.where(finders[:conditions]) if options.has_key?(:conditions)
|
103
|
-
|
104
103
|
relation
|
105
104
|
end
|
106
105
|
end
|
@@ -110,19 +110,19 @@ module DatastaxRails
|
|
110
110
|
uri = URI.parse(solr_url)
|
111
111
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
112
112
|
if force || solrconfig_digest != sm_digests['solrconfig']
|
113
|
-
puts "Posting Solr Config file to '#{
|
113
|
+
puts "Posting Solr Config file to '#{solr_url}/solrconfig.xml'"
|
114
114
|
http.post(uri.path+"/solrconfig.xml", solrconfig)
|
115
115
|
sleep(5) if Rails.env.production?
|
116
116
|
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:solrconfig => solrconfig_digest).execute
|
117
117
|
end
|
118
118
|
if force || stopwords_digest != sm_digests['stopwords']
|
119
|
-
puts "Posting Solr Stopwords file to '#{
|
119
|
+
puts "Posting Solr Stopwords file to '#{solr_url}/stopwords.txt'"
|
120
120
|
http.post(uri.path+"/stopwords.txt", stopwords)
|
121
121
|
sleep(5) if Rails.env.production?
|
122
122
|
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:stopwords => stopwords_digest).execute
|
123
123
|
end
|
124
124
|
if force || schema_digest != sm_digests['digest']
|
125
|
-
puts "Posting Solr Schema file to '#{
|
125
|
+
puts "Posting Solr Schema file to '#{solr_url}/schema.xml'"
|
126
126
|
http.post(uri.path+"/schema.xml", schema)
|
127
127
|
sleep(5) if Rails.env.production?
|
128
128
|
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:digest => schema_digest).execute
|
@@ -5,11 +5,12 @@ module DatastaxRails
|
|
5
5
|
FORMAT = '%Y-%m-%dT%H:%M:%SZ'
|
6
6
|
|
7
7
|
def encode(value)
|
8
|
-
raise ArgumentError.new("#{self} requires a Date") unless value.
|
8
|
+
raise ArgumentError.new("#{self} requires a Date") unless value.kind_of?(Date) || value.kind_of?(Time)
|
9
9
|
value.to_date.strftime(FORMAT)
|
10
10
|
end
|
11
11
|
|
12
12
|
def decode(str)
|
13
|
+
return str if str.kind_of?(Date)
|
13
14
|
Date.parse(str) rescue nil
|
14
15
|
end
|
15
16
|
end
|
@@ -4,14 +4,14 @@ module DatastaxRails
|
|
4
4
|
DEFAULTS = {:solr_type => 'float', :indexed => true, :stored => true, :multi_valued => false, :sortable => true, :tokenized => false, :fulltext => false}
|
5
5
|
REGEX = /\A[-+]?(\d+(\.\d+)?|\.\d+)\Z/
|
6
6
|
def encode(float)
|
7
|
-
|
8
|
-
float.to_s
|
7
|
+
return -10191980.0 if float.blank?
|
8
|
+
raise ArgumentError.new("#{self} requires a Float. You passed #{float.to_s}") unless float.kind_of?(Float) || (float.kind_of?(String) && float.match(REGEX))
|
9
|
+
float.to_f
|
9
10
|
end
|
10
11
|
|
11
|
-
def decode(
|
12
|
-
return nil if
|
13
|
-
|
14
|
-
str.to_f
|
12
|
+
def decode(float)
|
13
|
+
return nil if float.blank? || float == -10191980.0
|
14
|
+
float.to_f
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -4,14 +4,14 @@ module DatastaxRails
|
|
4
4
|
DEFAULTS = {:solr_type => 'int', :indexed => true, :stored => true, :multi_valued => false, :sortable => true, :tokenized => false, :fulltext => false}
|
5
5
|
REGEX = /\A[-+]?\d+\Z/
|
6
6
|
def encode(int)
|
7
|
-
|
8
|
-
int.to_s
|
7
|
+
return -10191980 if int.blank?
|
8
|
+
raise ArgumentError.new("#{self} requires an Integer. You passed #{int.to_s}") unless int.kind_of?(Integer) || (int.kind_of?(String) && int.match(REGEX))
|
9
|
+
int.to_i
|
9
10
|
end
|
10
11
|
|
11
|
-
def decode(
|
12
|
-
return nil if
|
13
|
-
|
14
|
-
str.to_i
|
12
|
+
def decode(int)
|
13
|
+
return nil if int.blank? || int.to_i == -10191980
|
14
|
+
int.to_i
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -3,6 +3,7 @@ module DatastaxRails
|
|
3
3
|
class StringType < BaseType
|
4
4
|
DEFAULTS = {:solr_type => 'string', :indexed => true, :stored => true, :multi_valued => false, :sortable => true, :tokenized => false, :fulltext => true}
|
5
5
|
def encode(str)
|
6
|
+
str = "" unless str
|
6
7
|
raise ArgumentError.new("#{self} requires a String") unless str.kind_of?(String)
|
7
8
|
str.dup
|
8
9
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DatastaxRails::Types::IntegerType do
|
4
|
+
before(:each) do
|
5
|
+
@coder = DatastaxRails::Types::IntegerType.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#encode" do
|
9
|
+
it "should store integers as Fixnums" do
|
10
|
+
@coder.encode(12).should be_a_kind_of(Fixnum)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should convert properly formatted strings to Fixnums" do
|
14
|
+
@coder.encode("12").should be_a_kind_of(Fixnum)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an exception on improperly formatted strings" do
|
18
|
+
lambda { @coder.encode("foo") }.should raise_exception(ArgumentError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should store a sentinel value for nils" do
|
22
|
+
@coder.encode(nil).should == -10191980
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#decode" do
|
27
|
+
it "should return integers" do
|
28
|
+
@coder.decode(12).should == 12
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return nil if the sentinel value is found" do
|
32
|
+
@coder.decode(-10191980).should be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,2 +1,66 @@
|
|
1
1
|
update people using consistency QUORUM SET birthdate = '2012-09-10T00:00:00Z', updated_at = '2012-09-12T19:59:57Z', schema_version = '0' WHERE KEY IN ('ea5d4cec-d679-11e1-90fc-d988657988ea')
|
2
2
|
people insert (4.1ms) ea5d4cec-d679-11e1-90fc-d988657988ea {"birthdate"=>"2012-09-10T00:00:00Z", "updated_at"=>"2012-09-12T19:59:57Z", "schema_version"=>"0"}
|
3
|
+
update jobs using consistency QUORUM SET created_at = '2012-09-25T18:49:10Z', title = 'Engineer', updated_at = '2012-09-25T18:49:10Z', schema_version = '0', position_number = 12345 WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
4
|
+
jobs insert (44.0ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"created_at"=>"2012-09-25T18:49:10Z", "title"=>"Engineer", "updated_at"=>"2012-09-25T18:49:10Z", "schema_version"=>"0", "position_number"=>12345}
|
5
|
+
DELETE FROM jobs USING CONSISTENCY QUORUM WHERE KEY IN ('85c6e32c-9f8a-11e1-8316-f893c43ba585')
|
6
|
+
jobs remove (22.7ms) #<DatastaxRails::Identity::UUIDKeyFactory:0x7b115f0>
|
7
|
+
update jobs using consistency QUORUM SET created_at = '2012-09-25T18:49:10Z', title = 'Engineer', updated_at = '2012-09-25T18:51:39Z', schema_version = '0', position_number = 12345 WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
8
|
+
jobs insert (2.8ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"created_at"=>"2012-09-25T18:49:10Z", "title"=>"Engineer", "updated_at"=>"2012-09-25T18:51:39Z", "schema_version"=>"0", "position_number"=>12345}
|
9
|
+
update jobs using consistency QUORUM SET created_at = '2012-09-25T18:49:10Z', title = 'Engineer', updated_at = '2012-09-25T18:51:57Z', schema_version = '0', position_number = 123456 WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
10
|
+
jobs insert (2.3ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"created_at"=>"2012-09-25T18:49:10Z", "title"=>"Engineer", "updated_at"=>"2012-09-25T18:51:57Z", "schema_version"=>"0", "position_number"=>123456}
|
11
|
+
update jobs using consistency QUORUM SET created_at = '2012-09-25T18:49:10Z', title = 'Engineer', updated_at = '2012-09-25T18:52:15Z', schema_version = '0', position_number = '' WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
12
|
+
jobs insert (10002.2ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"created_at"=>"2012-09-25T18:49:10Z", "title"=>"Engineer", "updated_at"=>"2012-09-25T18:52:15Z", "schema_version"=>"0", "position_number"=>""}
|
13
|
+
update jobs using consistency QUORUM SET created_at = '2012-09-25T18:49:10Z', title = 'Engineer', updated_at = '2012-09-25T18:53:20Z', schema_version = '0', position_number = '' WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
14
|
+
jobs insert (10001.9ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"created_at"=>"2012-09-25T18:49:10Z", "title"=>"Engineer", "updated_at"=>"2012-09-25T18:53:20Z", "schema_version"=>"0", "position_number"=>""}
|
15
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'people'
|
16
|
+
update schema_migrations using consistency QUORUM SET digest = 'ad9a586c6685ac554d946069b03380beb4262237' WHERE KEY IN ('people')
|
17
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'cars'
|
18
|
+
update schema_migrations using consistency QUORUM SET digest = '464a9743d7eb329077b695664663d5f37807e3c8' WHERE KEY IN ('cars')
|
19
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'jobs'
|
20
|
+
update schema_migrations using consistency QUORUM SET digest = '888a6c5c997a428d9090ae9485e0414ab90be548' WHERE KEY IN ('jobs')
|
21
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'boats'
|
22
|
+
update schema_migrations using consistency QUORUM SET digest = 'a62063d2c216babfe5b0a961e6f45cd020277aac' WHERE KEY IN ('boats')
|
23
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'hobbies'
|
24
|
+
update schema_migrations using consistency QUORUM SET digest = 'a2d743c761b9bcdbc787d433452edea0e41867cd' WHERE KEY IN ('hobbies')
|
25
|
+
update jobs using consistency QUORUM SET updated_at = '2012-09-25T20:00:56Z', schema_version = '0', position_number = '' WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
26
|
+
jobs insert (10003.0ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"updated_at"=>"2012-09-25T20:00:56Z", "schema_version"=>"0", "position_number"=>""}
|
27
|
+
update jobs using consistency QUORUM SET updated_at = '2012-09-25T20:03:54Z', schema_version = '0', position_number = '' WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
28
|
+
jobs insert (10002.5ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"updated_at"=>"2012-09-25T20:03:54Z", "schema_version"=>"0", "position_number"=>""}
|
29
|
+
update jobs using consistency QUORUM SET updated_at = '2012-09-25T20:05:55Z', schema_version = '0', position_number = -10191980 WHERE KEY IN ('b157168c-0741-11e2-9e4f-87f5d0ef990d')
|
30
|
+
jobs insert (3.3ms) b157168c-0741-11e2-9e4f-87f5d0ef990d {"updated_at"=>"2012-09-25T20:05:55Z", "schema_version"=>"0", "position_number"=>-10191980}
|
31
|
+
update hobbies using consistency QUORUM SET schema_version = '0' WHERE KEY IN ('6b422e7c-074e-11e2-8d4b-79683c20ffdf')
|
32
|
+
hobbies insert (7.9ms) 6b422e7c-074e-11e2-8d4b-79683c20ffdf {"schema_version"=>"0"}
|
33
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'people'
|
34
|
+
update schema_migrations using consistency QUORUM SET digest = 'a2b198b8a7d1be5ea56eac476d1245f695701d4c' WHERE KEY IN ('people')
|
35
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'cars'
|
36
|
+
update schema_migrations using consistency QUORUM SET digest = 'a76b07633e6f52ec64d62d50d2e73dd4686399aa' WHERE KEY IN ('cars')
|
37
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'jobs'
|
38
|
+
update schema_migrations using consistency QUORUM SET digest = '5badd69eee9539738d7caf3dae1368ae5fd4d578' WHERE KEY IN ('jobs')
|
39
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'boats'
|
40
|
+
update schema_migrations using consistency QUORUM SET digest = 'bcb94bb0c4fbe41b65bada3896cf4fda3a644d0b' WHERE KEY IN ('boats')
|
41
|
+
SELECT * FROM schema_migrations USING CONSISTENCY QUORUM WHERE key = 'hobbies'
|
42
|
+
update schema_migrations using consistency QUORUM SET digest = '6e83a0877c2b2b879a31ce1d0bfd251faafccfb0' WHERE KEY IN ('hobbies')
|
43
|
+
update hobbies using consistency QUORUM SET schema_version = '0' WHERE KEY IN ('d6bf8848-074e-11e2-900c-dcfeb4b35235')
|
44
|
+
hobbies insert (2.1ms) d6bf8848-074e-11e2-900c-dcfeb4b35235 {"schema_version"=>"0"}
|
45
|
+
update hobbies using consistency QUORUM SET schema_version = '0' WHERE KEY IN ('d9c2a322-074e-11e2-83e8-f51257df591f')
|
46
|
+
hobbies insert (1.4ms) d9c2a322-074e-11e2-83e8-f51257df591f {"schema_version"=>"0"}
|
47
|
+
update hobbies using consistency QUORUM SET schema_version = '0', complexity = 1.0 WHERE KEY IN ('025e0c04-074f-11e2-8e5b-8ba0a9f7edb5')
|
48
|
+
hobbies insert (3.1ms) 025e0c04-074f-11e2-8e5b-8ba0a9f7edb5 {"schema_version"=>"0", "complexity"=>1.0}
|
49
|
+
update hobbies using consistency QUORUM SET name = 'Hiking', schema_version = '0', complexity = 1.0 WHERE KEY IN ('3c13ae54-074f-11e2-8292-0d7011b9bb3a')
|
50
|
+
hobbies insert (2.3ms) 3c13ae54-074f-11e2-8292-0d7011b9bb3a {"name"=>"Hiking", "schema_version"=>"0", "complexity"=>1.0}
|
51
|
+
update hobbies using consistency QUORUM SET schema_version = '0' WHERE KEY IN ('de14043e-0753-11e2-9f2f-f86b6fc194a2')
|
52
|
+
hobbies insert (2.3ms) de14043e-0753-11e2-9f2f-f86b6fc194a2 {"schema_version"=>"0"}
|
53
|
+
update hobbies using consistency QUORUM SET name = 'Hi', schema_version = '0' WHERE KEY IN ('8d84af80-0755-11e2-82a8-736d24b9f368')
|
54
|
+
hobbies insert (2.5ms) 8d84af80-0755-11e2-82a8-736d24b9f368 {"name"=>"Hi", "schema_version"=>"0"}
|
55
|
+
update hobbies using consistency QUORUM SET name = 'hi', schema_version = '0' WHERE KEY IN ('a140d51c-0755-11e2-8c41-235ffd303c4a')
|
56
|
+
hobbies insert (9.2ms) a140d51c-0755-11e2-8c41-235ffd303c4a {"name"=>"hi", "schema_version"=>"0"}
|
57
|
+
update hobbies using consistency QUORUM SET name = 'hi', schema_version = '0' WHERE KEY IN ('19030868-0756-11e2-9874-c880dfb7c32d')
|
58
|
+
hobbies insert (2.4ms) 19030868-0756-11e2-9874-c880dfb7c32d {"name"=>"hi", "schema_version"=>"0"}
|
59
|
+
update hobbies using consistency QUORUM SET name = 'hi', schema_version = '0' WHERE KEY IN ('3a4e9d8e-0756-11e2-836e-eb52de18324b')
|
60
|
+
hobbies insert (8.8ms) 3a4e9d8e-0756-11e2-836e-eb52de18324b {"name"=>"hi", "schema_version"=>"0"}
|
61
|
+
update hobbies using consistency QUORUM SET name = 'hi', schema_version = '0' WHERE KEY IN ('98170424-0756-11e2-9100-5d9655af83d2')
|
62
|
+
hobbies insert (8.4ms) 98170424-0756-11e2-9100-5d9655af83d2 {"name"=>"hi", "schema_version"=>"0"}
|
63
|
+
update hobbies using consistency QUORUM SET name = 'j', schema_version = '0' WHERE KEY IN ('7332d7f8-0758-11e2-93a6-c8fd85e4fc7d')
|
64
|
+
hobbies insert (8.7ms) 7332d7f8-0758-11e2-93a6-c8fd85e4fc7d {"name"=>"j", "schema_version"=>"0"}
|
65
|
+
update hobbies using consistency QUORUM SET created_at = '2012-09-25T21:35:31Z', updated_at = '2012-09-25T21:35:31Z', schema_version = '0' WHERE KEY IN ('ee85bbfa-0758-11e2-9b96-52afb52cd9cd')
|
66
|
+
hobbies insert (8.2ms) ee85bbfa-0758-11e2-9b96-52afb52cd9cd {"created_at"=>"2012-09-25T21:35:31Z", "updated_at"=>"2012-09-25T21:35:31Z", "schema_version"=>"0"}
|