Permalink
Browse files

Use new unified insert API.

  • Loading branch information...
1 parent db8bf16 commit 33a72178f479d253f314221401b8ee55b15c3e5b Evan Weaver committed Aug 25, 2009
Showing with 20 additions and 29 deletions.
  1. +1 −1 CHANGELOG
  2. +9 −16 lib/cassandra/cassandra.rb
  3. +9 −8 lib/cassandra/columns.rb
  4. +1 −4 lib/cassandra/protocol.rb
View
@@ -1,5 +1,5 @@
-v0.5.5. to_guid for Long. Don't continually re-checkout the Git mirror. Use curl instead of wget, sigh.
+v0.5.5. to_guid for Long. Don't continually re-checkout the Git mirror. Use curl instead of wget, sigh. Use new unified insert API.
v0.5.4. Use wget instead of curl.
View
@@ -92,20 +92,14 @@ def inspect
# and <tt>:timestamp</tt> options.
def insert(column_family, key, hash, options = {})
column_family, _, _, options = params(column_family, [options], WRITE_DEFAULTS)
- timestamp = options[:timestamp] || Time.stamp
-
- mutation = if is_super(column_family)
- CassandraThrift::BatchMutationSuper.new(
- :key => key,
- :cfmap => {column_family => hash_to_super_columns(column_family, hash, timestamp)})
- else
- CassandraThrift::BatchMutation.new(
- :key => key,
- :cfmap => {column_family => hash_to_columns(column_family, hash, timestamp)})
- end
- # puts "insert() at #{timestamp}"
- args = [mutation, options[:consistency]]
+ args = [column_family, hash, options[:timestamp] || Time.stamp]
+ columns = is_super(column_family) ? hash_to_super_columns(*args) : hash_to_columns(*args)
+
+ args = [CassandraThrift::BatchMutation.new(
+ :key => key,
+ :cfmap => {column_family => columns}),
+ options[:consistency]]
@batch ? @batch << args : _insert(*args)
end
@@ -118,7 +112,6 @@ def remove(column_family, key, *columns_and_options)
column_family, column, sub_column, options = params(column_family, columns_and_options, WRITE_DEFAULTS)
timestamp = options[:timestamp] || Time.stamp
args = [column_family, key, column, sub_column, options[:consistency], timestamp]
- # puts "remove() at #{timestamp}"
@batch ? @batch << args : _remove(*args)
end
@@ -264,7 +257,7 @@ def compact_mutations
mutations = {}
# Insert delete operation
compact_batch << m
- else # BatchMutation, BatchMutationSuper
+ else # BatchMutation
# Do a nested hash merge
if mutation_class = mutations[m.class]
if mutation = mutation_class[m.key]
@@ -290,7 +283,7 @@ def dispatch_mutations
@batch.compact!
@batch.each do |args|
case args.first
- when CassandraThrift::BatchMutationSuper, CassandraThrift::BatchMutation
+ when CassandraThrift::BatchMutation
_insert(*args)
else
_remove(*args)
View
@@ -63,23 +63,24 @@ def columns_to_hash_for_classes(columns, column_name_class, sub_column_name_clas
end
hash
end
-
+
def hash_to_columns(column_family, hash, timestamp)
assert_column_name_classes(column_family, hash.keys)
- hash_to_columns_without_assertion(column_family, hash, timestamp)
- end
-
- def hash_to_columns_without_assertion(column_family, hash, timestamp)
hash.map do |column, value|
- CassandraThrift::Column.new(:name => column.to_s, :value => value, :timestamp => timestamp)
+ CassandraThrift::ColumnOrSuperColumn.new(:column =>
+ CassandraThrift::Column.new(:name => column.to_s, :value => value, :timestamp => timestamp))
end
- end
+ end
def hash_to_super_columns(column_family, hash, timestamp)
assert_column_name_classes(column_family, hash.keys)
hash.map do |column, sub_hash|
assert_column_name_classes(column_family, nil, sub_hash.keys)
- CassandraThrift::SuperColumn.new(:name => column.to_s, :columns => hash_to_columns_without_assertion(column_family, sub_hash, timestamp))
+ sub_columns = sub_hash.map do |sub_column, value|
+ CassandraThrift::Column.new(:name => sub_column.to_s, :value => value, :timestamp => timestamp)
+ end
+ CassandraThrift::ColumnOrSuperColumn.new(:super_column =>
+ CassandraThrift::SuperColumn.new(:name => column.to_s, :columns => sub_columns))
end
end
end
@@ -5,10 +5,7 @@ module Protocol #:nodoc:
private
def _insert(mutation, consistency)
- case mutation
- when CassandraThrift::BatchMutationSuper then @client.batch_insert_super_column(@keyspace, mutation, consistency)
- when CassandraThrift::BatchMutation then @client.batch_insert(@keyspace, mutation, consistency)
- end
+ @client.batch_insert(@keyspace, mutation, consistency)
end
def _remove(column_family, key, column, sub_column, consistency, timestamp)

0 comments on commit 33a7217

Please sign in to comment.