gotime-cassandra_object 4.0.2 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -4
- data/gotime-cassandra_object.gemspec +1 -2
- data/lib/cassandra_object/base.rb +0 -1
- data/lib/cassandra_object/batches.rb +16 -12
- data/lib/cassandra_object/connection.rb +1 -5
- data/lib/gotime-cassandra_object.rb +0 -1
- data/test/unit/connection_test.rb +11 -12
- metadata +1 -19
- data/lib/cassandra_object/consistency.rb +0 -31
- data/test/unit/consistency_test.rb +0 -20
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'gotime-cassandra_object'
|
5
|
-
s.version = '4.0
|
5
|
+
s.version = '4.1.0'
|
6
6
|
s.description = 'Cassandra ActiveModel'
|
7
7
|
s.summary = 'Cassandra ActiveModel'
|
8
8
|
s.authors = ["Michael Koziarski", "gotime"]
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.require_paths = ['lib']
|
19
19
|
|
20
20
|
s.add_runtime_dependency('activemodel', '>= 3.0')
|
21
|
-
s.add_runtime_dependency('cassandra', '>= 0.14.0')
|
22
21
|
s.add_runtime_dependency('cassandra-cql')
|
23
22
|
s.add_runtime_dependency('thrift_client', '~> 0.8.0')
|
24
23
|
|
@@ -3,27 +3,31 @@ module CassandraObject
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
def find_each
|
7
|
-
|
8
|
-
yield
|
6
|
+
def find_each(options = {})
|
7
|
+
find_in_batches(options) do |records|
|
8
|
+
records.each { |record| yield record }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_in_batches(options = {})
|
13
13
|
batch_size = options.delete(:batch_size) || 1000
|
14
|
+
start_key = nil
|
14
15
|
|
15
|
-
|
16
|
+
statement = "select * from #{column_family} limit #{batch_size + 1}"
|
17
|
+
records = instantiate_from_cql statement
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
while records.any?
|
20
|
+
if records.size > batch_size
|
21
|
+
next_record = records.pop
|
22
|
+
else
|
23
|
+
next_record = nil
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
yield records
|
27
|
+
break if next_record.nil?
|
28
|
+
|
29
|
+
statement = "SELECT * FROM #{column_family} WHERE KEY >= ? LIMIT #{batch_size + 1}"
|
30
|
+
records = instantiate_from_cql statement, next_record.id
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -33,12 +33,8 @@ module CassandraObject
|
|
33
33
|
self.connection_config = spec.reverse_merge(DEFAULT_OPTIONS)
|
34
34
|
end
|
35
35
|
|
36
|
-
def connection
|
37
|
-
@@connection ||= Cassandra.new(connection_config[:keyspace], connection_config[:servers], connection_config[:thrift].symbolize_keys)
|
38
|
-
end
|
39
|
-
|
40
36
|
def cql
|
41
|
-
@@cql ||= CassandraCQL::Database.new(connection_config[:servers], keyspace: connection_config[:keyspace], connection_config[:thrift].symbolize_keys)
|
37
|
+
@@cql ||= CassandraCQL::Database.new(connection_config[:servers], {keyspace: connection_config[:keyspace]}, connection_config[:thrift].symbolize_keys)
|
42
38
|
end
|
43
39
|
|
44
40
|
def execute_cql(cql_string, *bind_vars)
|
@@ -9,23 +9,22 @@ class CassandraObject::ConnectionTest < CassandraObject::TestCase
|
|
9
9
|
end
|
10
10
|
|
11
11
|
test 'establish_connection' do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
TestObject.establish_connection(
|
13
|
+
keyspace: 'place_directory_development',
|
14
|
+
servers: '192.168.0.100:9160',
|
15
|
+
thrift: {'timeout' => 10}
|
16
|
+
)
|
17
17
|
#
|
18
|
-
|
19
|
-
|
20
|
-
# assert_equal 10, TestObject.connection.thrift_client_options[:timeout]
|
18
|
+
assert_equal 'place_directory_development', TestObject.connection_config[:keyspace]
|
19
|
+
assert_equal 10, TestObject.connection_config[:thrift]['timeout']
|
21
20
|
end
|
22
21
|
|
23
22
|
test 'establish_connection defaults' do
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
TestObject.establish_connection(
|
24
|
+
keyspace: 'place_directory_development'
|
25
|
+
)
|
27
26
|
#
|
28
27
|
# assert_equal 'place_directory_development', TestObject.connection.keyspace
|
29
|
-
|
28
|
+
assert_equal "127.0.0.1:9160", TestObject.connection_config[:servers]
|
30
29
|
end
|
31
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -28,22 +28,6 @@ dependencies:
|
|
28
28
|
- - ! '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '3.0'
|
31
|
-
- !ruby/object:Gem::Dependency
|
32
|
-
name: cassandra
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
|
-
requirements:
|
36
|
-
- - ! '>='
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: 0.14.0
|
39
|
-
type: :runtime
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ! '>='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.14.0
|
47
31
|
- !ruby/object:Gem::Dependency
|
48
32
|
name: cassandra-cql
|
49
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +105,6 @@ files:
|
|
121
105
|
- lib/cassandra_object/belongs_to/reflection.rb
|
122
106
|
- lib/cassandra_object/callbacks.rb
|
123
107
|
- lib/cassandra_object/connection.rb
|
124
|
-
- lib/cassandra_object/consistency.rb
|
125
108
|
- lib/cassandra_object/errors.rb
|
126
109
|
- lib/cassandra_object/finder_methods.rb
|
127
110
|
- lib/cassandra_object/identity.rb
|
@@ -163,7 +146,6 @@ files:
|
|
163
146
|
- test/unit/belongs_to_test.rb
|
164
147
|
- test/unit/callbacks_test.rb
|
165
148
|
- test/unit/connection_test.rb
|
166
|
-
- test/unit/consistency_test.rb
|
167
149
|
- test/unit/finder_methods_test.rb
|
168
150
|
- test/unit/identity_test.rb
|
169
151
|
- test/unit/inspect_test.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module CassandraObject
|
2
|
-
module Consistency
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
cattr_accessor :consistency_levels
|
7
|
-
self.consistency_levels = [:one, :quorum, :all]
|
8
|
-
|
9
|
-
class_attribute :write_consistency
|
10
|
-
class_attribute :read_consistency
|
11
|
-
self.write_consistency = :quorum
|
12
|
-
self.read_consistency = :quorum
|
13
|
-
end
|
14
|
-
|
15
|
-
module ClassMethods
|
16
|
-
THRIFT_LEVELS = {
|
17
|
-
one: Cassandra::Consistency::ONE,
|
18
|
-
quorum: Cassandra::Consistency::QUORUM,
|
19
|
-
all: Cassandra::Consistency::ALL
|
20
|
-
}
|
21
|
-
|
22
|
-
def thrift_read_consistency
|
23
|
-
THRIFT_LEVELS[read_consistency] || (raise "Invalid consistency level #{read_consistency}")
|
24
|
-
end
|
25
|
-
|
26
|
-
def thrift_write_consistency
|
27
|
-
THRIFT_LEVELS[write_consistency] || (raise "Invalid consistency level #{write_consistency}")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CassandraObject::ConsistencyTest < CassandraObject::TestCase
|
4
|
-
class TestModel < CassandraObject::Base
|
5
|
-
end
|
6
|
-
|
7
|
-
test 'consistency_levels' do
|
8
|
-
assert_equal [:one, :quorum, :all].to_set, TestModel.consistency_levels.to_set
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'thrift_write_consistency' do
|
12
|
-
TestModel.write_consistency = :all
|
13
|
-
assert_equal Cassandra::Consistency::ALL, TestModel.thrift_write_consistency
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'thrift_read_consistency' do
|
17
|
-
TestModel.read_consistency = :all
|
18
|
-
assert_equal Cassandra::Consistency::ALL, TestModel.thrift_read_consistency
|
19
|
-
end
|
20
|
-
end
|