Tools for using Cassandra’s secondary indexes.
Example Usage:
>>> from pycassa.columnfamily import ColumnFamily
>>> from pycassa.pool import ConnectionPool
>>> from pycassa.index import *
>>>
>>> pool = ConnectionPool('Keyspace1')
>>> users = ColumnFamily(pool, 'Users')
>>> state_expr = create_index_expression('state', 'Utah')
>>> bday_expr = create_index_expression('birthdate', 1970, GT)
>>> clause = create_index_clause([state_expr, bday_expr], count=20)
>>> for key, user in users.get_indexed_slices(clause):
... print user['name'] + ",", user['state'], user['birthdate']
John Smith, Utah 1971
Mike Scott, Utah 1980
Jeff Bird, Utah 1973
This gives you all of the rows (up to 20) which have a ‘birthdate’ value above 1970 and a state value of ‘Utah’.
See also
SystemManager methods create_index() and drop_index()
Equality (==) operator for index expressions
Greater-than (>) operator for index expressions
Greater-than-or-equal (>=) operator for index expressions
Less-than (<) operator for index expressions
Less-than-or-equal (<=) operator for index expressions
Constructs an IndexExpression to use in an IndexClause
The expression will be applied to the column with name column_name. A match will only occur if the operator specified with op returns True when used on the actual column value and the value parameter.
The default operator is EQ, which tests for equality.
Constructs an IndexClause for use with get_indexed_slices()
expr_list should be a list of IndexExpression objects that must be matched for a row to be returned. At least one of these expressions must be on an indexed column.
Cassandra will only return matching rows with keys after start_key. If this is the empty string, all rows will be considered. Keep in mind that this is not as meaningful unless an OrderPreservingPartitioner is used.
The number of rows to return is limited by count, which defaults to 100.