eurydice 1.0.3-java → 1.1.0.b2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -5
- data/eurydice.gemspec +1 -1
- data/lib/cassandra.rb +8 -6
- data/lib/eurydice/pelops/column_family.rb +36 -5
- data/lib/eurydice/pelops.rb +4 -3
- data/lib/eurydice/version.rb +1 -1
- data/spec/eurydice/pelops/column_family_spec.rb +53 -3
- metadata +7 -7
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
eurydice (1.0.
|
5
|
-
pelops-jars (
|
4
|
+
eurydice (1.1.0.b2-java)
|
5
|
+
pelops-jars (>= 1.2.9)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
bouncy-castle-java (1.5.0146.1)
|
11
|
-
cassandra-jars (0.
|
11
|
+
cassandra-jars (1.0.0-java)
|
12
12
|
diff-lcs (1.1.2)
|
13
13
|
jruby-openssl (0.7.4)
|
14
14
|
bouncy-castle-java
|
15
|
-
pelops-jars (1.
|
16
|
-
cassandra-jars (~> 0.
|
15
|
+
pelops-jars (1.3.0.b3-java)
|
16
|
+
cassandra-jars (~> 1.0.0)
|
17
17
|
rake (0.9.2)
|
18
18
|
rspec (2.6.0)
|
19
19
|
rspec-core (~> 2.6.0)
|
@@ -30,5 +30,6 @@ PLATFORMS
|
|
30
30
|
DEPENDENCIES
|
31
31
|
eurydice!
|
32
32
|
jruby-openssl
|
33
|
+
pelops-jars (= 1.3.0.b3)
|
33
34
|
rake
|
34
35
|
rspec
|
data/eurydice.gemspec
CHANGED
data/lib/cassandra.rb
CHANGED
@@ -24,12 +24,14 @@ module Cassandra
|
|
24
24
|
}.freeze
|
25
25
|
|
26
26
|
MARSHAL_TYPES = {
|
27
|
-
:bytes
|
28
|
-
:ascii
|
29
|
-
:utf8
|
30
|
-
:long
|
31
|
-
:lexical_uuid
|
32
|
-
:time_uuid
|
27
|
+
:bytes => 'org.apache.cassandra.db.marshal.BytesType'.freeze,
|
28
|
+
:ascii => 'org.apache.cassandra.db.marshal.AsciiType'.freeze,
|
29
|
+
:utf8 => 'org.apache.cassandra.db.marshal.UTF8Type'.freeze,
|
30
|
+
:long => 'org.apache.cassandra.db.marshal.LongType'.freeze,
|
31
|
+
:lexical_uuid => 'org.apache.cassandra.db.marshal.LexicalUUIDType'.freeze,
|
32
|
+
:time_uuid => 'org.apache.cassandra.db.marshal.TimeUUIDType'.freeze,
|
33
|
+
:counter => 'org.apache.cassandra.db.marshal.CounterColumnType'.freeze,
|
34
|
+
:counter_column => 'org.apache.cassandra.db.marshal.CounterColumnType'.freeze
|
33
35
|
}.freeze
|
34
36
|
|
35
37
|
INDEX_OPERATORS = {
|
@@ -79,6 +79,17 @@ module Eurydice
|
|
79
79
|
end
|
80
80
|
alias_method :insert, :update
|
81
81
|
|
82
|
+
def increment(row_key, column_key, amount=1, options={})
|
83
|
+
thrift_exception_handler do
|
84
|
+
mutator = @keyspace.create_mutator
|
85
|
+
mutator.write_counter_column(@name, to_pelops_bytes(row_key), to_pelops_bytes(column_key), amount)
|
86
|
+
mutator.execute(get_cl(options))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
alias_method :inc, :increment
|
90
|
+
alias_method :incr, :increment
|
91
|
+
alias_method :increment_column, :increment
|
92
|
+
|
82
93
|
def key?(row_key, options={})
|
83
94
|
thrift_exception_handler do
|
84
95
|
selector = @keyspace.create_selector
|
@@ -101,8 +112,13 @@ module Eurydice
|
|
101
112
|
def get_column(row_key, column_key, options={})
|
102
113
|
thrift_exception_handler do
|
103
114
|
selector = @keyspace.create_selector
|
104
|
-
|
105
|
-
|
115
|
+
if counter_columns?
|
116
|
+
column = selector.get_counter_column_from_row(@name, to_pelops_bytes(row_key), to_pelops_bytes(column_key), get_cl(options))
|
117
|
+
column.get_value
|
118
|
+
else
|
119
|
+
column =selector.get_column_from_row(@name, to_pelops_bytes(row_key), to_pelops_bytes(column_key), get_cl(options))
|
120
|
+
byte_array_to_s(column.get_value)
|
121
|
+
end
|
106
122
|
end
|
107
123
|
rescue NotFoundError => e
|
108
124
|
nil
|
@@ -158,11 +174,19 @@ module Eurydice
|
|
158
174
|
|
159
175
|
EMPTY_STRING = ''.freeze
|
160
176
|
|
177
|
+
def counter_columns?
|
178
|
+
@is_counter_cf ||= definition[:default_validation_class] == Cassandra::MARSHAL_TYPES[:counter]
|
179
|
+
end
|
180
|
+
|
161
181
|
def get_single(row_key, options={})
|
162
182
|
thrift_exception_handler do
|
163
183
|
selector = @keyspace.create_selector
|
164
184
|
column_predicate = create_column_predicate(options)
|
165
|
-
|
185
|
+
if counter_columns?
|
186
|
+
columns = selector.get_counter_columns_from_row(@name, to_pelops_bytes(row_key), column_predicate, get_cl(options))
|
187
|
+
else
|
188
|
+
columns = selector.get_columns_from_row(@name, to_pelops_bytes(row_key), column_predicate, get_cl(options))
|
189
|
+
end
|
166
190
|
columns_to_h(columns, options)
|
167
191
|
end
|
168
192
|
end
|
@@ -172,7 +196,11 @@ module Eurydice
|
|
172
196
|
selector = @keyspace.create_selector
|
173
197
|
column_predicate = create_column_predicate(options)
|
174
198
|
byte_row_keys = row_keys.map { |rk| to_pelops_bytes(rk) }
|
175
|
-
|
199
|
+
if counter_columns?
|
200
|
+
rows = selector.get_counter_columns_from_rows(@name, byte_row_keys, column_predicate, get_cl(options))
|
201
|
+
else
|
202
|
+
rows = selector.get_columns_from_rows(@name, byte_row_keys, column_predicate, get_cl(options))
|
203
|
+
end
|
176
204
|
rows_to_h(rows, options)
|
177
205
|
end
|
178
206
|
end
|
@@ -218,7 +246,10 @@ module Eurydice
|
|
218
246
|
types = options[:validations] || {}
|
219
247
|
key_type = options[:comparator]
|
220
248
|
key = byte_array_to_s(column.get_name, key_type)
|
221
|
-
value =
|
249
|
+
value = if counter_columns?
|
250
|
+
then column.get_value
|
251
|
+
else byte_array_to_s(column.get_value, types[key])
|
252
|
+
end
|
222
253
|
return key, value
|
223
254
|
end
|
224
255
|
|
data/lib/eurydice/pelops.rb
CHANGED
@@ -16,8 +16,8 @@ module Pelops
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module Eurydice
|
19
|
-
def self.connect
|
20
|
-
Pelops.connect
|
19
|
+
def self.connect(*args)
|
20
|
+
Pelops.connect(*args)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.disconnect!
|
@@ -29,7 +29,8 @@ module Eurydice
|
|
29
29
|
host = options.fetch(:host, 'localhost')
|
30
30
|
port = options.fetch(:port, 9160)
|
31
31
|
pool_name = options.fetch(:pool_name, 'eurydice')
|
32
|
-
|
32
|
+
dynamic_node_discovery = options.fetch(:dynamic_node_discovery, false)
|
33
|
+
Cluster.new(::Pelops::Cluster.new(host, port, dynamic_node_discovery))
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.keyspace(keyspace_name, host='localhost', port=9160, pool_name='eurydice')
|
data/lib/eurydice/version.rb
CHANGED
@@ -181,6 +181,12 @@ module Eurydice
|
|
181
181
|
@cf = @keyspace.column_family('test_family')
|
182
182
|
@cf.truncate!
|
183
183
|
end
|
184
|
+
|
185
|
+
before do
|
186
|
+
@counter_cf = @keyspace.column_family('counter_family', :create => false)
|
187
|
+
@counter_cf.create!(:default_validation_class => :counter) unless @counter_cf.exists?
|
188
|
+
@counter_cf.truncate!
|
189
|
+
end
|
184
190
|
|
185
191
|
describe '#update/#insert' do
|
186
192
|
it 'writes a column' do
|
@@ -230,6 +236,26 @@ module Eurydice
|
|
230
236
|
end
|
231
237
|
end
|
232
238
|
end
|
239
|
+
|
240
|
+
describe '#increment' do
|
241
|
+
it 'can increment a counter column' do
|
242
|
+
@cf.increment('ABC', 'count')
|
243
|
+
@cf.get_column('ABC', 'count').should == 1
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'can increment a counter column by the specified amount' do
|
247
|
+
@cf.increment('ABC', 'count', 3)
|
248
|
+
@cf.increment('ABC', 'count', 2)
|
249
|
+
@cf.get_column('ABC', 'count').should == 5
|
250
|
+
end
|
251
|
+
|
252
|
+
[:inc, :incr, :increment_column].each do |name|
|
253
|
+
it "is aliased as #{name}" do
|
254
|
+
@cf.send(name, 'ABC', 'count')
|
255
|
+
@cf.get_column('ABC', 'count').should == 1
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
233
259
|
|
234
260
|
describe '#get' do
|
235
261
|
context 'with a single row key' do
|
@@ -275,6 +301,14 @@ module Eurydice
|
|
275
301
|
it 'returns nil if no row was found' do
|
276
302
|
@cf.get('XYZ').should be_nil
|
277
303
|
end
|
304
|
+
|
305
|
+
it 'loads the value of counter columns' do
|
306
|
+
@counter_cf.increment('ABC', 'a', 1)
|
307
|
+
@counter_cf.increment('ABC', 'b', 2)
|
308
|
+
@counter_cf.increment('ABC', 'c', 4)
|
309
|
+
@counter_cf.increment('ABC', 'd', 8)
|
310
|
+
@counter_cf.get('ABC', :columns => %w(a b c d)).should == {'a' => 1, 'b' => 2, 'c' => 4, 'd' => 8}
|
311
|
+
end
|
278
312
|
end
|
279
313
|
|
280
314
|
context 'with multiple row keys' do
|
@@ -331,6 +365,17 @@ module Eurydice
|
|
331
365
|
it 'returns an empty hash if no rows exist' do
|
332
366
|
@cf.get(%w(ABC GHI)).should == {}
|
333
367
|
end
|
368
|
+
|
369
|
+
it 'loads the value of counter columns' do
|
370
|
+
@counter_cf.increment('ABC', 'a', 1)
|
371
|
+
@counter_cf.increment('ABC', 'b', 2)
|
372
|
+
@counter_cf.increment('DEF', 'c', 4)
|
373
|
+
@counter_cf.increment('DEF', 'd', 8)
|
374
|
+
@counter_cf.get(%w(ABC DEF), :columns => %w(a b c d)).should == {
|
375
|
+
'ABC' => {'a' => 1, 'b' => 2},
|
376
|
+
'DEF' => {'c' => 4, 'd' => 8}
|
377
|
+
}
|
378
|
+
end
|
334
379
|
end
|
335
380
|
|
336
381
|
context 'with options' do
|
@@ -372,11 +417,16 @@ module Eurydice
|
|
372
417
|
@cf.insert('ABC', 'xyz' => 'abc', 'hello' => 'world', 'foo' => 'bar')
|
373
418
|
@cf.get_column('XYZ', 'abc').should be_nil
|
374
419
|
end
|
420
|
+
|
421
|
+
it 'returns the value of a counter column' do
|
422
|
+
@counter_cf.increment('ABC', 'x', 8)
|
423
|
+
@counter_cf.get_column('ABC', 'x').should == 8
|
424
|
+
end
|
375
425
|
end
|
376
426
|
|
377
427
|
describe '#get_column_count' do
|
378
428
|
it 'returns the number of columns in the specified row' do
|
379
|
-
@cf.insert('ABC', Hash[('a'..'z').zip(0..
|
429
|
+
@cf.insert('ABC', Hash[('a'..'z').zip(0..100)])
|
380
430
|
@cf.get_column_count('ABC').should == 26
|
381
431
|
end
|
382
432
|
|
@@ -385,12 +435,12 @@ module Eurydice
|
|
385
435
|
end
|
386
436
|
|
387
437
|
it 'returns the number of columns in the specified range' do
|
388
|
-
@cf.insert('ABC', Hash[('a'..'z').zip(0..
|
438
|
+
@cf.insert('ABC', Hash[('a'..'z').zip(0..100)])
|
389
439
|
@cf.get_column_count('ABC', :columns => 'm'..'q').should == 5
|
390
440
|
end
|
391
441
|
|
392
442
|
it 'returns the number of columns after the specified column' do
|
393
|
-
@cf.insert('ABC', Hash[('a'..'z').zip(0..
|
443
|
+
@cf.insert('ABC', Hash[('a'..'z').zip(0..100)])
|
394
444
|
@cf.get_column_count('ABC', :from_column => 's').should == 8
|
395
445
|
end
|
396
446
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eurydice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 1.0.
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.1.0.b2
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Theo Hultberg
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-11-
|
13
|
+
date: 2011-11-28 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: pelops-jars
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.2.9
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
description: ""
|
@@ -76,9 +76,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
none: false
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 1.3.1
|
82
82
|
requirements: []
|
83
83
|
|
84
84
|
rubyforge_project: eurydice
|