cassandra 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.12.2
2
+ - Respect the start_key in get_range. Resolves Issue #127.
3
+ - Fix issue with differences in gemspec and what is required. Resolves Issue #125.
4
+ - Update to Cassandra 0.8.7 and 1.0.2.
5
+
1
6
  v0.12.1
2
7
  - Fix issue with simple_uuid dependency.
3
8
  - Fix issue with get_range & get_range_batch keeping all results when a block is given. Resolves Issue# 112.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # cassandra
2
2
  A Ruby client for the Cassandra distributed database.
3
3
 
4
- Supports 1.8.7, 1.9.2, and rubinius on Cassandra 0.6.13, 0.7.8, 0.8.4.
4
+ Supports 1.8.7, 1.9.2, and rubinius on Cassandra 0.6.13, 0.7.9, 0.8.6, 1.0.0-rc2.
5
5
 
6
6
  ## Getting Started
7
7
 
@@ -31,10 +31,10 @@ To use the default version simply use a normal require:
31
31
 
32
32
  require 'cassandra'
33
33
 
34
- To use a specific version (0.7 in this example) you would use a
34
+ To use a specific version (1.0 in this example) you would use a
35
35
  slightly differently formatted require:
36
36
 
37
- require 'cassandra/0.7'
37
+ require 'cassandra/1.0'
38
38
 
39
39
  #### Environment Variable Method
40
40
  These mechanisms work well when you are using the cassandra gem in your
@@ -349,4 +349,4 @@ Example:
349
349
 
350
350
  ## Reporting Problems
351
351
 
352
- The Github issue tracker is [here](http://github.com/fauna/cassandra/issues). If you have problems with this library or Cassandra itself, please use the [cassandra-user mailing list](http://mail-archives.apache.org/mod_mbox/incubator-cassandra-user/).
352
+ The Github issue tracker is [here](http://github.com/twitter/cassandra/issues). If you have problems with this library or Cassandra itself, please use the [cassandra-user mailing list](http://mail-archives.apache.org/mod_mbox/incubator-cassandra-user/).
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ unless ENV['FROM_BIN_CASSANDRA_HELPER']
9
9
  p.project = "fauna"
10
10
  p.summary = "A Ruby client for the Cassandra distributed database."
11
11
  p.rubygems_version = ">= 0.8"
12
- p.dependencies = ['thrift_client >=0.7.0', 'json', 'rake', 'simple_uuid >=0.2.0']
12
+ p.dependencies = ['thrift_client >=0.7.0 <0.9', 'json', 'rake', 'simple_uuid ~>0.2.0']
13
13
  p.ignore_pattern = /^(data|vendor\/cassandra|cassandra|vendor\/thrift|.*\.rbc)/
14
14
  p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
15
15
  p.retain_gemspec = true
@@ -18,8 +18,9 @@ end
18
18
 
19
19
  CassandraBinaries = {
20
20
  '0.6' => 'http://archive.apache.org/dist/cassandra/0.6.13/apache-cassandra-0.6.13-bin.tar.gz',
21
- '0.7' => 'http://archive.apache.org/dist/cassandra/0.7.8/apache-cassandra-0.7.8-bin.tar.gz',
22
- '0.8' => 'http://archive.apache.org/dist/cassandra/0.8.4/apache-cassandra-0.8.4-bin.tar.gz'
21
+ '0.7' => 'http://archive.apache.org/dist/cassandra/0.7.9/apache-cassandra-0.7.9-bin.tar.gz',
22
+ '0.8' => 'http://archive.apache.org/dist/cassandra/0.8.7/apache-cassandra-0.8.7-bin.tar.gz',
23
+ '1.0' => 'http://archive.apache.org/dist/cassandra/1.0.6/apache-cassandra-1.0.6-bin.tar.gz'
23
24
  }
24
25
 
25
26
  CASSANDRA_HOME = ENV['CASSANDRA_HOME'] || "#{ENV['HOME']}/cassandra"
@@ -153,10 +154,12 @@ task :test => 'data:load'
153
154
  # desc "Regenerate thrift bindings for Cassandra" # Dev only
154
155
  task :thrift do
155
156
  puts "Generating Thrift bindings"
157
+ FileUtils.mkdir_p "vendor/#{CASSANDRA_VERSION}"
158
+
156
159
  system(
157
- "cd vendor &&
160
+ "cd vendor/#{CASSANDRA_VERSION} &&
158
161
  rm -rf gen-rb &&
159
- thrift -gen rb #{CASSANDRA_HOME}/interface/cassandra.thrift")
162
+ thrift -gen rb #{File.join(CASSANDRA_HOME, "cassandra-#{CASSANDRA_VERSION}")}/interface/cassandra.thrift")
160
163
  end
161
164
 
162
165
  task :fix_perms do
@@ -1,43 +1,43 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{cassandra}
5
- s.version = "0.12.1"
4
+ s.name = "cassandra"
5
+ s.version = "0.13.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Evan Weaver, Ryan King}]
9
- s.date = %q{2011-08-22}
10
- s.description = %q{A Ruby client for the Cassandra distributed database.}
11
- s.email = %q{}
12
- s.executables = [%q{cassandra_helper}]
13
- s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.md}, %q{bin/cassandra_helper}, %q{lib/cassandra.rb}, %q{lib/cassandra/0.6.rb}, %q{lib/cassandra/0.6/cassandra.rb}, %q{lib/cassandra/0.6/columns.rb}, %q{lib/cassandra/0.6/protocol.rb}, %q{lib/cassandra/0.7.rb}, %q{lib/cassandra/0.7/cassandra.rb}, %q{lib/cassandra/0.7/columns.rb}, %q{lib/cassandra/0.7/protocol.rb}, %q{lib/cassandra/0.8.rb}, %q{lib/cassandra/0.8/cassandra.rb}, %q{lib/cassandra/0.8/columns.rb}, %q{lib/cassandra/0.8/protocol.rb}, %q{lib/cassandra/array.rb}, %q{lib/cassandra/cassandra.rb}, %q{lib/cassandra/column_family.rb}, %q{lib/cassandra/columns.rb}, %q{lib/cassandra/comparable.rb}, %q{lib/cassandra/constants.rb}, %q{lib/cassandra/debug.rb}, %q{lib/cassandra/helpers.rb}, %q{lib/cassandra/keyspace.rb}, %q{lib/cassandra/long.rb}, %q{lib/cassandra/mock.rb}, %q{lib/cassandra/ordered_hash.rb}, %q{lib/cassandra/protocol.rb}, %q{lib/cassandra/time.rb}]
14
- s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.md}, %q{Rakefile}, %q{bin/cassandra_helper}, %q{conf/0.6/cassandra.in.sh}, %q{conf/0.6/log4j.properties}, %q{conf/0.6/schema.json}, %q{conf/0.6/storage-conf.xml}, %q{conf/0.7/cassandra.in.sh}, %q{conf/0.7/cassandra.yaml}, %q{conf/0.7/log4j-server.properties}, %q{conf/0.7/schema.json}, %q{conf/0.7/schema.txt}, %q{conf/0.8/cassandra.in.sh}, %q{conf/0.8/cassandra.yaml}, %q{conf/0.8/log4j-server.properties}, %q{conf/0.8/schema.json}, %q{conf/0.8/schema.txt}, %q{lib/cassandra.rb}, %q{lib/cassandra/0.6.rb}, %q{lib/cassandra/0.6/cassandra.rb}, %q{lib/cassandra/0.6/columns.rb}, %q{lib/cassandra/0.6/protocol.rb}, %q{lib/cassandra/0.7.rb}, %q{lib/cassandra/0.7/cassandra.rb}, %q{lib/cassandra/0.7/columns.rb}, %q{lib/cassandra/0.7/protocol.rb}, %q{lib/cassandra/0.8.rb}, %q{lib/cassandra/0.8/cassandra.rb}, %q{lib/cassandra/0.8/columns.rb}, %q{lib/cassandra/0.8/protocol.rb}, %q{lib/cassandra/array.rb}, %q{lib/cassandra/cassandra.rb}, %q{lib/cassandra/column_family.rb}, %q{lib/cassandra/columns.rb}, %q{lib/cassandra/comparable.rb}, %q{lib/cassandra/constants.rb}, %q{lib/cassandra/debug.rb}, %q{lib/cassandra/helpers.rb}, %q{lib/cassandra/keyspace.rb}, %q{lib/cassandra/long.rb}, %q{lib/cassandra/mock.rb}, %q{lib/cassandra/ordered_hash.rb}, %q{lib/cassandra/protocol.rb}, %q{lib/cassandra/time.rb}, %q{test/cassandra_client_test.rb}, %q{test/cassandra_mock_test.rb}, %q{test/cassandra_test.rb}, %q{test/comparable_types_test.rb}, %q{test/eventmachine_test.rb}, %q{test/ordered_hash_test.rb}, %q{test/test_helper.rb}, %q{vendor/0.6/gen-rb/cassandra.rb}, %q{vendor/0.6/gen-rb/cassandra_constants.rb}, %q{vendor/0.6/gen-rb/cassandra_types.rb}, %q{vendor/0.7/gen-rb/cassandra.rb}, %q{vendor/0.7/gen-rb/cassandra_constants.rb}, %q{vendor/0.7/gen-rb/cassandra_types.rb}, %q{vendor/0.8/gen-rb/cassandra.rb}, %q{vendor/0.8/gen-rb/cassandra_constants.rb}, %q{vendor/0.8/gen-rb/cassandra_types.rb}, %q{cassandra.gemspec}]
15
- s.homepage = %q{http://fauna.github.com/fauna/cassandra/}
16
- s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Cassandra}, %q{--main}, %q{README.md}]
17
- s.require_paths = [%q{lib}]
18
- s.rubyforge_project = %q{fauna}
19
- s.rubygems_version = %q{1.8.5}
20
- s.summary = %q{A Ruby client for the Cassandra distributed database.}
21
- s.test_files = [%q{test/cassandra_client_test.rb}, %q{test/cassandra_mock_test.rb}, %q{test/cassandra_test.rb}, %q{test/comparable_types_test.rb}, %q{test/eventmachine_test.rb}, %q{test/ordered_hash_test.rb}, %q{test/test_helper.rb}]
8
+ s.authors = ["Evan Weaver, Ryan King"]
9
+ s.date = "2012-07-19"
10
+ s.description = "A Ruby client for the Cassandra distributed database."
11
+ s.email = ""
12
+ s.executables = ["cassandra_helper"]
13
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.md", "bin/cassandra_helper", "lib/cassandra.rb", "lib/cassandra/0.6.rb", "lib/cassandra/0.6/cassandra.rb", "lib/cassandra/0.6/columns.rb", "lib/cassandra/0.6/protocol.rb", "lib/cassandra/0.7.rb", "lib/cassandra/0.7/cassandra.rb", "lib/cassandra/0.7/columns.rb", "lib/cassandra/0.7/protocol.rb", "lib/cassandra/0.8.rb", "lib/cassandra/0.8/cassandra.rb", "lib/cassandra/0.8/columns.rb", "lib/cassandra/0.8/protocol.rb", "lib/cassandra/1.0/cassandra.rb", "lib/cassandra/1.0/columns.rb", "lib/cassandra/1.0/protocol.rb", "lib/cassandra/1.0.rb", "lib/cassandra/array.rb", "lib/cassandra/cassandra.rb", "lib/cassandra/column_family.rb", "lib/cassandra/columns.rb", "lib/cassandra/comparable.rb", "lib/cassandra/composite.rb", "lib/cassandra/constants.rb", "lib/cassandra/debug.rb", "lib/cassandra/helpers.rb", "lib/cassandra/keyspace.rb", "lib/cassandra/long.rb", "lib/cassandra/mock.rb", "lib/cassandra/ordered_hash.rb", "lib/cassandra/protocol.rb", "lib/cassandra/time.rb"]
14
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.md", "Rakefile", "bin/cassandra_helper", "conf/0.6/cassandra.in.sh", "conf/0.6/log4j.properties", "conf/0.6/schema.json", "conf/0.6/storage-conf.xml", "conf/0.7/cassandra.in.sh", "conf/0.7/cassandra.yaml", "conf/0.7/log4j-server.properties", "conf/0.7/schema.json", "conf/0.7/schema.txt", "conf/0.8/cassandra.in.sh", "conf/0.8/cassandra.yaml", "conf/0.8/log4j-server.properties", "conf/0.8/schema.json", "conf/0.8/schema.txt", "lib/cassandra.rb", "lib/cassandra/0.6.rb", "lib/cassandra/0.6/cassandra.rb", "lib/cassandra/0.6/columns.rb", "lib/cassandra/0.6/protocol.rb", "lib/cassandra/0.7.rb", "lib/cassandra/0.7/cassandra.rb", "lib/cassandra/0.7/columns.rb", "lib/cassandra/0.7/protocol.rb", "lib/cassandra/0.8.rb", "lib/cassandra/0.8/cassandra.rb", "lib/cassandra/0.8/columns.rb", "lib/cassandra/0.8/protocol.rb", "lib/cassandra/1.0/cassandra.rb", "lib/cassandra/1.0/columns.rb", "lib/cassandra/1.0/protocol.rb", "lib/cassandra/1.0.rb", "lib/cassandra/array.rb", "lib/cassandra/cassandra.rb", "lib/cassandra/column_family.rb", "lib/cassandra/columns.rb", "lib/cassandra/comparable.rb", "lib/cassandra/composite.rb", "lib/cassandra/constants.rb", "lib/cassandra/debug.rb", "lib/cassandra/helpers.rb", "lib/cassandra/keyspace.rb", "lib/cassandra/long.rb", "lib/cassandra/mock.rb", "lib/cassandra/ordered_hash.rb", "lib/cassandra/protocol.rb", "lib/cassandra/time.rb", "test/cassandra_client_test.rb", "test/cassandra_mock_test.rb", "test/cassandra_test.rb", "test/comparable_types_test.rb", "test/composite_type_test.rb", "test/eventmachine_test.rb", "test/ordered_hash_test.rb", "test/test_helper.rb", "vendor/0.6/gen-rb/cassandra.rb", "vendor/0.6/gen-rb/cassandra_constants.rb", "vendor/0.6/gen-rb/cassandra_types.rb", "vendor/0.7/gen-rb/cassandra.rb", "vendor/0.7/gen-rb/cassandra_constants.rb", "vendor/0.7/gen-rb/cassandra_types.rb", "vendor/0.8/gen-rb/cassandra.rb", "vendor/0.8/gen-rb/cassandra_constants.rb", "vendor/0.8/gen-rb/cassandra_types.rb", "vendor/1.0/gen-rb/cassandra.rb", "vendor/1.0/gen-rb/cassandra_constants.rb", "vendor/1.0/gen-rb/cassandra_types.rb", "cassandra.gemspec"]
15
+ s.homepage = "http://github.com/twitter/cassandra/"
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cassandra", "--main", "README.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = "fauna"
19
+ s.rubygems_version = "1.8.10"
20
+ s.summary = "A Ruby client for the Cassandra distributed database."
21
+ s.test_files = ["test/cassandra_mock_test.rb", "test/ordered_hash_test.rb", "test/cassandra_client_test.rb", "test/cassandra_test.rb", "test/comparable_types_test.rb", "test/test_helper.rb", "test/eventmachine_test.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  s.specification_version = 3
25
25
 
26
26
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_runtime_dependency(%q<thrift_client>, [">= 0.7.0"])
27
+ s.add_runtime_dependency(%q<thrift_client>, ["< 0.9", ">= 0.7.0"])
28
28
  s.add_runtime_dependency(%q<json>, [">= 0"])
29
29
  s.add_runtime_dependency(%q<rake>, [">= 0"])
30
- s.add_runtime_dependency(%q<simple_uuid>, [">= 0.2.0"])
30
+ s.add_runtime_dependency(%q<simple_uuid>, ["~> 0.2.0"])
31
31
  else
32
- s.add_dependency(%q<thrift_client>, [">= 0.7.0"])
32
+ s.add_dependency(%q<thrift_client>, ["< 0.9", ">= 0.7.0"])
33
33
  s.add_dependency(%q<json>, [">= 0"])
34
34
  s.add_dependency(%q<rake>, [">= 0"])
35
- s.add_dependency(%q<simple_uuid>, [">= 0.2.0"])
35
+ s.add_dependency(%q<simple_uuid>, ["~> 0.2.0"])
36
36
  end
37
37
  else
38
- s.add_dependency(%q<thrift_client>, [">= 0.7.0"])
38
+ s.add_dependency(%q<thrift_client>, ["< 0.9", ">= 0.7.0"])
39
39
  s.add_dependency(%q<json>, [">= 0"])
40
40
  s.add_dependency(%q<rake>, [">= 0"])
41
- s.add_dependency(%q<simple_uuid>, [">= 0.2.0"])
41
+ s.add_dependency(%q<simple_uuid>, ["~> 0.2.0"])
42
42
  end
43
43
  end
@@ -18,7 +18,7 @@
18
18
  # (%l is slower.)
19
19
 
20
20
  # output messages into a rolling log file as well as stdout
21
- log4j.rootLogger=DEBUG,stdout,R
21
+ log4j.rootLogger=INFO,stdout,R
22
22
 
23
23
  # stdout
24
24
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
@@ -61,6 +61,9 @@
61
61
  "SuperUUID":{
62
62
  "subcomparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
63
63
  "comparator_type":"org.apache.cassandra.db.marshal.TimeUUIDType",
64
- "column_type":"Super"}
64
+ "column_type":"Super"},
65
+ "CompositeColumnConversion":{
66
+ "comparator_type":"org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.IntegerType,org.apache.cassandra.db.marshal.UTF8Type)",
67
+ "column_type":"Standard"}
65
68
  }
66
69
  }
@@ -1,5 +1,5 @@
1
1
  create keyspace Twitter with
2
- placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
2
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
3
3
  strategy_options = [{replication_factor:1}];
4
4
  use Twitter;
5
5
  create column family Users with comparator = 'UTF8Type';
@@ -17,7 +17,7 @@ create column family UserRelationships with
17
17
  create column family Usernames with comparator = 'UTF8Type';
18
18
  create column family Statuses with comparator = 'UTF8Type';
19
19
  create column family StatusAudits with comparator = 'UTF8Type';
20
- create column family StatusRelationships with
20
+ create column family StatusRelationships with
21
21
  comparator = 'UTF8Type' and
22
22
  column_type = 'Super' and
23
23
  subcomparator = 'TimeUUIDType';
@@ -28,7 +28,7 @@ create column family TimelinishThings with
28
28
  comparator = 'BytesType';
29
29
 
30
30
  create keyspace Multiblog with
31
- placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
31
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
32
32
  strategy_options = [{replication_factor:1}];
33
33
  use Multiblog;
34
34
  create column family Blogs with comparator = 'TimeUUIDType';
@@ -36,16 +36,16 @@ create column family Comments with comparator = 'TimeUUIDType';
36
36
 
37
37
 
38
38
  create keyspace MultiblogLong with
39
- placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
39
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
40
40
  strategy_options = [{replication_factor:1}];
41
41
  use MultiblogLong;
42
42
  create column family Blogs with comparator = 'LongType';
43
43
  create column family Comments with comparator = 'LongType';
44
44
 
45
45
  create keyspace TypeConversions with
46
- placement_strategy = 'org.apache.cassandra.locator.LocalStrategy' AND
46
+ placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' AND
47
47
  strategy_options = [{replication_factor:1}];
48
48
  use TypeConversions;
49
49
  create column family UUIDColumnConversion with comparator = TimeUUIDType;
50
50
  create column family SuperUUID with comparator = TimeUUIDType and column_type = Super;
51
-
51
+ create column family CompositeColumnConversion with comparator = 'CompositeType(IntegerType, UTF8Type)';
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- gem 'thrift_client', '~> 0.7.0'
2
+ gem 'thrift_client', '>= 0.7.0', '< 0.9'
3
3
  require 'thrift_client'
4
4
  gem 'simple_uuid' , '~> 0.2.0'
5
5
  require 'simple_uuid'
@@ -23,6 +23,7 @@ require 'cassandra/array'
23
23
  require 'cassandra/time'
24
24
  require 'cassandra/comparable'
25
25
  require 'cassandra/long'
26
+ require 'cassandra/composite'
26
27
  require 'cassandra/ordered_hash'
27
28
  require 'cassandra/columns'
28
29
  require 'cassandra/protocol'
@@ -5,6 +5,21 @@ class Cassandra
5
5
  # Add a value to the counter in cf:key:super column:column
6
6
  def add(column_family, key, value, *columns_and_options)
7
7
  column_family, column, sub_column, options = extract_and_validate_params(column_family, key, columns_and_options, WRITE_DEFAULTS)
8
- _add(column_family, key, column, sub_column, value, options[:consistency])
8
+
9
+ mutation_map = if is_super(column_family)
10
+ {
11
+ key => {
12
+ column_family => [_super_counter_mutation(column_family, column, sub_column, value)]
13
+ }
14
+ }
15
+ else
16
+ {
17
+ key => {
18
+ column_family => [_standard_counter_mutation(column_family, column, value)]
19
+ }
20
+ }
21
+ end
22
+
23
+ @batch ? @batch << [mutation_map, options[:consistency]] : _mutate(mutation_map, options[:consistency])
9
24
  end
10
25
  end
@@ -1,4 +1,28 @@
1
1
  class Cassandra
2
2
  module Columns #:nodoc:
3
+ def _standard_counter_mutation(column_family, column_name, value)
4
+ CassandraThrift::Mutation.new(
5
+ :column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
6
+ :counter_column => CassandraThrift::CounterColumn.new(
7
+ :name => column_name_class(column_family).new(column_name).to_s,
8
+ :value => value,
9
+ )
10
+ )
11
+ )
12
+ end
13
+
14
+ def _super_counter_mutation(column_family, super_column_name, sub_column, value)
15
+ CassandraThrift::Mutation.new(:column_or_supercolumn =>
16
+ CassandraThrift::ColumnOrSuperColumn.new(
17
+ :counter_super_column => CassandraThrift::SuperColumn.new(
18
+ :name => column_name_class(column_family).new(super_column_name).to_s,
19
+ :columns => [CassandraThrift::CounterColumn.new(
20
+ :name => sub_column_name_class(column_family).new(sub_column).to_s,
21
+ :value => value
22
+ )]
23
+ )
24
+ )
25
+ )
26
+ end
3
27
  end
4
28
  end
@@ -1,5 +1,3 @@
1
- require "#{File.expand_path(File.dirname(__FILE__))}/../0.7/protocol"
2
-
3
1
  class Cassandra
4
2
  # Inner methods for actually doing the Thrift calls
5
3
  module Protocol #:nodoc:
@@ -8,16 +6,5 @@ class Cassandra
8
6
  def _remove_counter(key, column_path, consistency_level)
9
7
  client.remove_counter(key, column_path, consistency_level)
10
8
  end
11
-
12
- def _add(column_family, key, column, sub_column, value, consistency)
13
- if is_super(column_family)
14
- column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family, :super_column => column)
15
- counter_column = CassandraThrift::CounterColumn.new(:name => sub_column, :value => value)
16
- else
17
- column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
18
- counter_column = CassandraThrift::CounterColumn.new(:name => column, :value => value)
19
- end
20
- client.add(key, column_parent, counter_column, consistency)
21
- end
22
9
  end
23
10
  end
@@ -0,0 +1,7 @@
1
+ class Cassandra
2
+ def self.VERSION
3
+ "1.0"
4
+ end
5
+ end
6
+
7
+ require "#{File.expand_path(File.dirname(__FILE__))}/../cassandra"
@@ -0,0 +1,25 @@
1
+ class Cassandra
2
+
3
+ ## Counters
4
+
5
+ # Add a value to the counter in cf:key:super column:column
6
+ def add(column_family, key, value, *columns_and_options)
7
+ column_family, column, sub_column, options = extract_and_validate_params(column_family, key, columns_and_options, WRITE_DEFAULTS)
8
+
9
+ mutation_map = if is_super(column_family)
10
+ {
11
+ key => {
12
+ column_family => [_super_counter_mutation(column_family, column, sub_column, value)]
13
+ }
14
+ }
15
+ else
16
+ {
17
+ key => {
18
+ column_family => [_standard_counter_mutation(column_family, column, value)]
19
+ }
20
+ }
21
+ end
22
+
23
+ @batch ? @batch << [mutation_map, options[:consistency]] : _mutate(mutation_map, options[:consistency])
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ class Cassandra
2
+ module Columns #:nodoc:
3
+ def _standard_counter_mutation(column_family, column_name, value)
4
+ CassandraThrift::Mutation.new(
5
+ :column_or_supercolumn => CassandraThrift::ColumnOrSuperColumn.new(
6
+ :counter_column => CassandraThrift::CounterColumn.new(
7
+ :name => column_name_class(column_family).new(column_name).to_s,
8
+ :value => value,
9
+ )
10
+ )
11
+ )
12
+ end
13
+
14
+ def _super_counter_mutation(column_family, super_column_name, sub_column, value)
15
+ CassandraThrift::Mutation.new(:column_or_supercolumn =>
16
+ CassandraThrift::ColumnOrSuperColumn.new(
17
+ :counter_super_column => CassandraThrift::SuperColumn.new(
18
+ :name => column_name_class(column_family).new(super_column_name).to_s,
19
+ :columns => [CassandraThrift::CounterColumn.new(
20
+ :name => sub_column_name_class(column_family).new(sub_column).to_s,
21
+ :value => value
22
+ )]
23
+ )
24
+ )
25
+ )
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/../0.7/protocol"
2
+
3
+ class Cassandra
4
+ # Inner methods for actually doing the Thrift calls
5
+ module Protocol #:nodoc:
6
+ private
7
+
8
+ def _remove_counter(key, column_path, consistency_level)
9
+ client.remove_counter(key, column_path, consistency_level)
10
+ end
11
+ end
12
+ end
@@ -741,27 +741,29 @@ class Cassandra
741
741
  # range of keys in the column_family you request.
742
742
  #
743
743
  # If a block is passed in we will yield the row key and columns for
744
- # each record returned.
744
+ # each record returned and return a nil value instead of a Cassandra::OrderedHash.
745
745
  #
746
746
  # See Cassandra#get_range for more details.
747
747
  #
748
748
  def get_range_batch(column_family, options = {})
749
749
  batch_size = options.delete(:batch_size) || 100
750
750
  count = options.delete(:key_count)
751
- result = {}
751
+ result = (!block_given? && {}) || nil
752
+ num_results = 0
752
753
 
753
754
  options[:start_key] ||= ''
754
755
  last_key = nil
755
756
 
756
- while options[:start_key] != last_key && (count.nil? || count > result.length)
757
- options[:start_key] = last_key
758
- res = get_range_single(column_family, options.merge!(:start_key => last_key,
757
+ while count.nil? || count > num_results
758
+ res = get_range_single(column_family, options.merge!(:start_key => last_key || options[:start_key],
759
759
  :key_count => batch_size,
760
760
  :return_empty_rows => true
761
761
  ))
762
+ break if res.keys.last == last_key
763
+
762
764
  res.each do |key, columns|
763
- next if options[:start_key] == key
764
- next if result.length == count
765
+ next if last_key == key
766
+ next if num_results == count
765
767
 
766
768
  unless columns == {}
767
769
  if block_given?
@@ -769,12 +771,14 @@ class Cassandra
769
771
  else
770
772
  result[key] = columns
771
773
  end
774
+ num_results += 1
772
775
  end
776
+
773
777
  last_key = key
774
778
  end
775
779
  end
776
780
 
777
- result if !block_given?
781
+ result
778
782
  end
779
783
 
780
784
  ##
@@ -18,10 +18,11 @@ class Cassandra
18
18
 
19
19
  def column_name_class_for_key(column_family, comparator_key)
20
20
  property = column_family_property(column_family, comparator_key)
21
- property =~ /.*\.(.*?)$/
21
+ property =~ /[^(]*\.(.*?)$/
22
22
  case $1
23
23
  when "LongType" then Long
24
24
  when "LexicalUUIDType", "TimeUUIDType" then SimpleUUID::UUID
25
+ when /^CompositeType\(/ then Composite
25
26
  else
26
27
  String # UTF8, Ascii, Bytes, anything else
27
28
  end
@@ -73,8 +74,10 @@ class Cassandra
73
74
  def columns_to_hash_for_classes(columns, column_name_class, sub_column_name_class = nil)
74
75
  hash = OrderedHash.new
75
76
  Array(columns).each do |c|
76
- c = c.super_column || c.column || c.counter_column if c.is_a?(CassandraThrift::ColumnOrSuperColumn)
77
+ c = c.super_column || c.column || c.counter_column || c.counter_super_column if c.is_a?(CassandraThrift::ColumnOrSuperColumn)
77
78
  case c
79
+ when CassandraThrift::CounterSuperColumn
80
+ hash.[]=(column_name_class.new(c.name), columns_to_hash_for_classes(c.columns, sub_column_name_class)) # Pop the class stack, and recurse
78
81
  when CassandraThrift::SuperColumn
79
82
  hash.[]=(column_name_class.new(c.name), columns_to_hash_for_classes(c.columns, sub_column_name_class)) # Pop the class stack, and recurse
80
83
  when CassandraThrift::Column