Cassandra

This module is available only if you have cassandra-driver installed

wrap_future

satella.cassandra.wrap_future(future)

Convert a Cassandra’s future to a normal Python future. The returned future will be marked as running.

future is returned when it’s already a Python future.

Parameters:

future (ResponseFuture) – cassandra future to wrap

Returns:

a standard Python future

Return type:

Future

parallel_for

If you have multiple async requests that would hit multiple nodes and you would prefer to make use of execute_async and want to better make use of them, here’s the routine to help you out.

satella.cassandra.parallel_for(cursor, query, arguments)

Syntactic sugar for

>>> futures = []
>>> for args in arguments:
>>>     futures.append(cursor.execute_async(query, args))
>>> for future in futures:
>>>     yield future.result()

If query is a string or a Cassandra Statement, or else

>>> futures = []
>>> for query, args in zip(query, arguments):
>>>     futures.append(cursor.execute_async(query, args))
>>> for future in futures:
>>>     yield future.result()

Note that if None is encountered in the argument iterable, session.execute() will be called with a single argument. You better have it as a BoundStatement then!

Deprecated since version 2.14.22: Use Cassandra feature for that

Parameters:
  • cursor – the Cassandra cursor to use (obtained using connection.session())

  • query (Union[List[str], str, Statement, List[Statement]]) – base query or a list of queries, if a different one is to be used

  • arguments (Iterable[tuple]) – iterable yielding arguments to use in execute_async

Return type:

Iterator[namedtuple]

Note that if you specify an iterable instead of a string or a cassandra.query.Statement, different query will be applied to those arguments, as stemming from their ordering.