cassandra-cql 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -7
- data/lib/cassandra-cql.rb +2 -0
- data/lib/cassandra-cql/statement.rb +3 -1
- data/lib/cassandra-cql/types/date_type.rb +9 -0
- data/lib/cassandra-cql/version.rb +1 -1
- data/spec/comparator_spec.rb +27 -7
- data/spec/statement_spec.rb +12 -10
- data/spec/validation_spec.rb +15 -3
- metadata +17 -16
data/README.rdoc
CHANGED
@@ -69,10 +69,3 @@ So adding a feature like counters just requires teaching the CQL parser to under
|
|
69
69
|
|
70
70
|
# Delete the swarthy bastard Kevin
|
71
71
|
db.execute("DELETE FROM users WHERE id=?", 'kway')
|
72
|
-
|
73
|
-
=TODO
|
74
|
-
|
75
|
-
1. Make bind_var usage friendlier
|
76
|
-
2. Determine if returning Time objects for TimeUUID is appropriate in all cases and if not, add an option
|
77
|
-
3. Add yardoc
|
78
|
-
4. Add spec for database
|
data/lib/cassandra-cql.rb
CHANGED
@@ -18,11 +18,13 @@ here = File.dirname(__FILE__)
|
|
18
18
|
require "#{here}/../vendor/gen-rb/cassandra"
|
19
19
|
|
20
20
|
require 'bigdecimal'
|
21
|
+
require 'date'
|
21
22
|
require 'thrift_client'
|
22
23
|
require 'cassandra-cql/types/abstract_type'
|
23
24
|
require 'cassandra-cql/types/ascii_type'
|
24
25
|
require 'cassandra-cql/types/boolean_type'
|
25
26
|
require 'cassandra-cql/types/bytes_type'
|
27
|
+
require 'cassandra-cql/types/date_type'
|
26
28
|
require 'cassandra-cql/types/decimal_type'
|
27
29
|
require 'cassandra-cql/types/double_type'
|
28
30
|
require 'cassandra-cql/types/float_type'
|
@@ -83,8 +83,10 @@ module CassandraCQL
|
|
83
83
|
obj.map { |member| cast_to_cql(member) }
|
84
84
|
elsif obj.kind_of?(Fixnum) or obj.kind_of?(Float)
|
85
85
|
obj
|
86
|
+
elsif obj.kind_of?(Date)
|
87
|
+
obj.strftime('%Y-%m-%d')
|
86
88
|
elsif obj.kind_of?(Time)
|
87
|
-
|
89
|
+
(obj.to_f * 1000).to_i
|
88
90
|
elsif obj.kind_of?(UUID)
|
89
91
|
obj.to_guid
|
90
92
|
# There are corner cases where this is an invalid assumption but they are extremely rare.
|
data/spec/comparator_spec.rb
CHANGED
@@ -78,6 +78,27 @@ describe "Comparator Roundtrip tests" do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
context "with date comparator" do
|
82
|
+
let(:cf_name) { "comparator_cf_date" }
|
83
|
+
before(:each) { create_column_family(cf_name, 'DateType') }
|
84
|
+
|
85
|
+
it "should return a Time object" do
|
86
|
+
ts = Time.new
|
87
|
+
res = create_and_fetch_column(cf_name, ts)
|
88
|
+
res.to_f.should be_within(0.001).of(ts.to_f)
|
89
|
+
res.should be_kind_of(Time)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return a timestamp given a date" do
|
93
|
+
date = Date.today
|
94
|
+
res = create_and_fetch_column(cf_name, date)
|
95
|
+
[:year, :month, :day].each do |sym|
|
96
|
+
res.send(sym).should eq(date.send(sym))
|
97
|
+
end
|
98
|
+
res.class.should eq(Time)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
81
102
|
|
82
103
|
context "with decimal comparator" do
|
83
104
|
let(:cf_name) { "comparator_cf_decimal" }
|
@@ -88,13 +109,12 @@ describe "Comparator Roundtrip tests" do
|
|
88
109
|
create_and_fetch_column(cf_name, value*-1).should eq(value*-1)
|
89
110
|
end
|
90
111
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
# end
|
112
|
+
it "should return a small decimal" do
|
113
|
+
test_for_value(15.333)
|
114
|
+
end
|
115
|
+
it "should return a huge decimal" do
|
116
|
+
test_for_value(BigDecimal.new('129182739481237481341234123411.1029348102934810293481039'))
|
117
|
+
end
|
98
118
|
end
|
99
119
|
|
100
120
|
context "with double comparator" do
|
data/spec/statement_spec.rb
CHANGED
@@ -100,17 +100,19 @@ end
|
|
100
100
|
|
101
101
|
describe "cast_to_cql" do
|
102
102
|
context "with a Time object" do
|
103
|
-
it "should return a
|
103
|
+
it "should return a Time object with the number of microseconds since epoch" do
|
104
104
|
ts = Time.new - 86400 # set it to yesterday just to be sure no defaulting to today misses an error
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
105
|
+
long = Statement.cast_to_cql(ts)
|
106
|
+
long.should be_kind_of(Integer)
|
107
|
+
Time.at(long / 1000.0).to_f.should be_within(0.001).of(ts.to_f)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with a Date object" do
|
112
|
+
it "should return a corresponding Time object" do
|
113
|
+
date = Date.today << 1
|
114
|
+
str = Statement.cast_to_cql(date)
|
115
|
+
str.should eq(date.strftime('%Y-%m-%d'))
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
data/spec/validation_spec.rb
CHANGED
@@ -9,7 +9,8 @@ describe "Validation Roundtrip tests" do
|
|
9
9
|
|
10
10
|
def create_and_fetch_column(column_family, value)
|
11
11
|
@connection.execute("insert into #{column_family} (id, test_column) values (?, ?)", 'test', value)
|
12
|
-
|
12
|
+
res = @connection.execute("select test_column from #{column_family} where id = ?", 'test')
|
13
|
+
return res.fetch[0]
|
13
14
|
end
|
14
15
|
|
15
16
|
def create_column_family(name, test_column_type, opts="")
|
@@ -197,8 +198,19 @@ describe "Validation Roundtrip tests" do
|
|
197
198
|
before(:each) { create_column_family(cf_name, 'timestamp') }
|
198
199
|
|
199
200
|
it "should return a timestamp" do
|
200
|
-
|
201
|
-
|
201
|
+
ts = Time.new
|
202
|
+
res = create_and_fetch_column(cf_name, ts)
|
203
|
+
res.to_f.should be_within(0.001).of(ts.to_f)
|
204
|
+
res.class.should eq(Time)
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return a timestamp given a date" do
|
208
|
+
date = Date.today
|
209
|
+
res = create_and_fetch_column(cf_name, date)
|
210
|
+
[:year, :month, :day].each do |sym|
|
211
|
+
res.send(sym).should eq(date.send(sym))
|
212
|
+
end
|
213
|
+
res.class.should eq(Time)
|
202
214
|
end
|
203
215
|
end
|
204
216
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassandra-cql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-16 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70205356087480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70205356087480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rcov
|
27
|
-
requirement: &
|
27
|
+
requirement: &70205356087020 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.9
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70205356087020
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70205356086560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.6.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70205356086560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70205356086100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70205356086100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70205356085640 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.7.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70205356085640
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simple_uuid
|
71
|
-
requirement: &
|
71
|
+
requirement: &70205356085180 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 0.2.0
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70205356085180
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: thrift_client
|
82
|
-
requirement: &
|
82
|
+
requirement: &70205356084720 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: 0.7.1
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70205356084720
|
91
91
|
description: CQL Interface to Cassandra
|
92
92
|
email:
|
93
93
|
- kelley@insidesystems.net
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/cassandra-cql/types/ascii_type.rb
|
112
112
|
- lib/cassandra-cql/types/boolean_type.rb
|
113
113
|
- lib/cassandra-cql/types/bytes_type.rb
|
114
|
+
- lib/cassandra-cql/types/date_type.rb
|
114
115
|
- lib/cassandra-cql/types/decimal_type.rb
|
115
116
|
- lib/cassandra-cql/types/double_type.rb
|
116
117
|
- lib/cassandra-cql/types/float_type.rb
|