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.
@@ -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
@@ -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
- UUID.new(obj).to_guid
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.
@@ -0,0 +1,9 @@
1
+ module CassandraCQL
2
+ module Types
3
+ class DateType < AbstractType
4
+ def self.cast(value)
5
+ Time.at(bytes_to_long(value) / 1000.0)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -15,5 +15,5 @@ limitations under the License.
15
15
  =end
16
16
 
17
17
  module CassandraCQL
18
- VERSION = "1.0.1"
18
+ VERSION = "1.0.2"
19
19
  end
@@ -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
- # These tests currently crash the node
92
- it "should return a small decimal" #do
93
- # test_for_value(15.333)
94
- # end
95
- it "should return a huge decimal" #do
96
- # test_for_value(BigDecimal.new('129182739481237481341234123411.1029348102934810293481039'))
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
@@ -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 guid of a UUID" do
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
- guid = Statement.cast_to_cql(ts)
106
- guid.should be_kind_of(String)
107
- expect {
108
- ret = UUID.new(guid)
109
- uuid_ts = Time.at(ret.seconds)
110
- [:year, :month, :day, :hour, :min, :sec].each do |sym|
111
- uuid_ts.send(sym).should eq(ts.send(sym))
112
- end
113
- }.to_not raise_error
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
 
@@ -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
- return @connection.execute("select test_column from #{column_family} where id = ?", 'test').fetch[0]
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
- uuid = UUID.new
201
- #create_and_fetch_column(cf_name, uuid).should eq(uuid)
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.1
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-03 00:00:00.000000000Z
12
+ date: 2011-11-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70106920848140 !ruby/object:Gem::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: *70106920848140
24
+ version_requirements: *70205356087480
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rcov
27
- requirement: &70106920847680 !ruby/object:Gem::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: *70106920847680
35
+ version_requirements: *70205356087020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70106920847220 !ruby/object:Gem::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: *70106920847220
46
+ version_requirements: *70205356086560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70106920846760 !ruby/object:Gem::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: *70106920846760
57
+ version_requirements: *70205356086100
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &70106920846300 !ruby/object:Gem::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: *70106920846300
68
+ version_requirements: *70205356085640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simple_uuid
71
- requirement: &70106920845840 !ruby/object:Gem::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: *70106920845840
79
+ version_requirements: *70205356085180
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: thrift_client
82
- requirement: &70106920845380 !ruby/object:Gem::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: *70106920845380
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