lib/cassandra/cassandra.rb in sessionm-cassandra-1.1.0 vs lib/cassandra/cassandra.rb in sessionm-cassandra-1.1.1
- old
+ new
@@ -556,10 +556,29 @@
extract_and_validate_params(column_family, key, columns_and_options, READ_DEFAULTS)
_get_columns(column_family, key, columns, sub_columns, options[:consistency])
end
##
+ # Return a hash of column value pairs for the path you request.
+ #
+ # * 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.
+ # * options - Valid options are:
+ # * :consistency - Uses the default read consistency if none specified.
+ #
+ def get_columns_as_hash(column_family, key, columns, options=nil)
+ consistency = options ? (options[:consistency] || READ_DEFAULTS[:consistency]) : READ_DEFAULTS[:consistency]
+ if column_family.is_a?(CassandraThrift::ColumnParent)
+ _get_columns_as_hash(column_family, key, columns, nil, consistency)
+ else
+ _get_columns_as_hash(column_family, key, columns, nil, consistency)
+ end
+ end
+
+ ##
# Multi-key version of Cassandra#get_columns. Please note that this
# queries the server for each key passed in.
#
# Supports same parameters as Cassandra#get_columns
#
@@ -592,14 +611,34 @@
# * :reversed - If set to true the results will be returned in
# reverse order.
# * :consistency - Uses the default read consistency if none specified.
#
def get(column_family, key, *columns_and_options)
- multi_get(column_family, [key], *columns_and_options)[key]
+ if column_family.is_a?(CassandraThrift::ColumnParent)
+ column = columns_and_options.first
+ consistency = columns_and_options.last.is_a?(Hash) ? (columns_and_options.last[:consistency] || READ_DEFAULTS[:consistency]) : READ_DEFAULTS[:consistency]
+
+ get_slice(column_family, key, column, nil, nil, nil, nil, consistency)
+ else
+ column_family, column, sub_column, options =
+ extract_and_validate_params(column_family, key, columns_and_options, READ_DEFAULTS)
+
+ if column
+ get_value column_family, key, column, options[:consistency]
+ else
+ get_slice(column_family, key, column, options[:start], options[:finish], options[:count], options[:reversed], options[:consistency])
+ end
+ end
end
##
+ # Returns the value of the column
+ def get_value(column_family, key, column, consistency)
+ _get(column_family, key, column, consistency)
+ end
+
+ ##
# Multi-key version of Cassandra#get.
#
# This method allows you to select multiple rows with a single query.
# If a key that is passed in doesn't exist an empty hash will be
# returned.
@@ -1003,12 +1042,12 @@
options[:finish], options[:reversed], options[:consistency])
key_slices.inject(OrderedHash.new) {|h, key_slice| h[key_slice.key] = key_slice.columns; h }
end
- # Selecting a slice of a super column
- def get_slice(column_family, key, start, finish, count, reversed, consistency)
- _get_slice(column_family, key, start, finish, count, reversed, consistency)
+ # Selecting a slice of a column
+ def get_slice(column_family, key, column, start, finish, count, reversed, consistency)
+ _get_slice(column_family, key, column, start, finish, count, reversed, consistency)
end
protected
def calling_method