Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #169 from christian-blades-cb/master

Modifying multi_get_columns to get the keys and columns in a single request
  • Loading branch information...
commit f98fb8650fad6e613435b5afeee16e5494521203 2 parents 02ddacd + 3c4dff5
@natemueller natemueller authored
Showing with 25 additions and 7 deletions.
  1. +8 −7 lib/cassandra/cassandra.rb
  2. +17 −0 lib/cassandra/protocol.rb
View
15 lib/cassandra/cassandra.rb
@@ -570,9 +570,10 @@ def get_columns(column_family, key, *columns_and_options)
# * options - Valid options are:
# * :consistency - Uses the default read consistency if none specified.
#
- # FIXME Not real multi; needs to use a Column predicate
- def multi_get_columns(column_family, keys, *options)
- OrderedHash[*keys.map { |key| [key, get_columns(column_family, key, *options)] }._flatten_once]
+ def multi_get_columns(column_family, keys, *columns_and_options)
+ column_family, columns, sub_columns, options =
+ extract_and_validate_params(column_family, keys, columns_and_options, READ_DEFAULTS)
+ _multi_get_columns(column_family, keys, columns, sub_columns, options[:consistency])
end
##
@@ -582,8 +583,8 @@ def multi_get_columns(column_family, keys, *options)
#
# * column_family - The column_family that you are inserting into.
# * key - The row key to insert.
- # * columns - Either a single super_column or a list of columns.
- # * sub_columns - The list of sub_columns to select.
+ # * column - Either a single super_column or single column.
+ # * sub_column - A single sub_column to select.
# * options - Valid options are:
# * :count - The number of columns requested to be returned.
# * :start - The starting value for selecting a range of columns.
@@ -607,8 +608,8 @@ def get(column_family, key, *columns_and_options)
#
# * column_family - The column_family that you are inserting into.
# * keys - An array of keys to select.
- # * columns - Either a single super_column or a list of columns.
- # * sub_columns - The list of sub_columns to select.
+ # * column - Either a single super_column or a single column.
+ # * sub_column - A single ub_columns to select.
# * options - Valid options are:
# * :count - The number of columns requested to be returned.
# * :start - The starting value for selecting a range of columns.
View
17 lib/cassandra/protocol.rb
@@ -48,6 +48,23 @@ def _get_columns(column_family, key, columns, sub_columns, consistency)
klass = column_name_class(column_family)
(sub_columns || columns).map { |name| result[klass.new(name)] }
end
+
+ def _multi_get_columns(column_family, keys, columns, sub_columns, consistency)
+ result = if is_super(column_family) and sub_columns
+ predicate = CassandraThrift::SlicePredicate.new(:column_names => sub_columns)
+ column_parent = CassandraThrift::ColumnParent.new(
+ :column_family => column_family,
+ :super_column => columns.kind_of?(Array) ? columns[0] : columns )
+ multi_sub_columns_to_hash!(column_family, client.multiget_slice(keys, column_parent, predicate, consistency))
+ else
+ predicate = CassandraThrift::SlicePredicate.new(:column_names => columns)
+ column_parent = CassandraThrift::ColumnParent.new(:column_family => column_family)
+ multi_columns_to_hash!(column_family, client.multiget_slice(keys, column_parent, predicate, consistency))
+ end
+
+ klass = column_name_class(column_family)
+ OrderedHash[result.keys.map { |key| [key, (sub_columns || columns).map { |column| result[key][klass.new(column)] }] }]
+ end
def _multiget(column_family, keys, column, sub_column, count, start, finish, reversed, consistency)
# Single values; count and range parameters have no effect
Please sign in to comment.
Something went wrong with that request. Please try again.