Rename Query to Statement to match Java driver

This commit is contained in:
Tyler Hobbs
2013-09-18 17:20:04 -05:00
parent 25f8314999
commit b87890d0a3
4 changed files with 35 additions and 32 deletions

View File

@@ -34,7 +34,7 @@ from cassandra.policies import (RoundRobinPolicy, SimpleConvictionPolicy,
ExponentialReconnectionPolicy, HostDistance,
RetryPolicy)
from cassandra.query import (SimpleStatement, PreparedStatement, BoundStatement,
bind_params, QueryTrace, Query)
bind_params, QueryTrace, Statement)
from cassandra.pool import (_ReconnectionHandler, _HostReconnectionHandler,
HostConnectionPool)
@@ -126,7 +126,7 @@ class Cluster(object):
default_retry_policy = RetryPolicy()
"""
A default :class:`.policies.RetryPolicy` instance to use for all
:class:`.Query` objects which do not have a :attr:`~.Query.retry_policy`
:class:`.Statement` objects which do not have a :attr:`~.Statement.retry_policy`
explicitly set.
"""
@@ -589,7 +589,7 @@ class Session(object):
If an error is encountered while executing the query, an Exception
will be raised.
`query` may be a query string or an instance of :class:`cassandra.query.Query`.
`query` may be a query string or an instance of :class:`cassandra.query.Statement`.
`parameters` may be a sequence or dict of parameters to bind. If a
sequence is used, ``%s`` should be used the placeholder for each
@@ -598,16 +598,16 @@ class Session(object):
If `trace` is set to :const:`True`, an attempt will be made to
fetch the trace details and attach them to the `query`'s
:attr:`~.Query.trace` attribute in the form of a :class:`.QueryTrace`
instance. This requires that `query` be a :class:`.Query` subclass
:attr:`~.Statement.trace` attribute in the form of a :class:`.QueryTrace`
instance. This requires that `query` be a :class:`.Statement` subclass
instance and not just a string. If there is an error fetching the
trace details, the :attr:`~.Query.trace` attribute will be left as
trace details, the :attr:`~.Statement.trace` attribute will be left as
:const:`None`.
"""
if trace and not isinstance(query, Query):
if trace and not isinstance(query, Statement):
raise TypeError(
"The query argument must be an instance of a subclass of "
"cassandra.query.Query when trace=True")
"cassandra.query.Statement when trace=True")
future = self.execute_async(query, parameters, trace)
try:

View File

@@ -73,7 +73,7 @@ class LoadBalancingPolicy(object):
def make_query_plan(self, working_keyspace=None, query=None):
"""
Given a :class:`~.query.Query` instance, return a iterable
Given a :class:`~.query.Statement` instance, return a iterable
of :class:`.Host` instances which should be queried in that
order. A generator may work well for custom implementations
of this method.
@@ -261,11 +261,11 @@ class TokenAwarePolicy(LoadBalancingPolicy):
This alters the child policy's behavior so that it first attempts to
send queries to :attr:`~.HostDistance.LOCAL` replicas (as determined
by the child policy) based on the :class:`.Query`'s
:attr:`~.Query.routing_key`. Once those hosts are exhausted, the
by the child policy) based on the :class:`.Statement`'s
:attr:`~.Statement.routing_key`. Once those hosts are exhausted, the
remaining hosts in the child policy's query plan will be used.
If no :attr:`~.Query.routing_key` is set on the query, the child
If no :attr:`~.Statement.routing_key` is set on the query, the child
policy's query plan will be used as is.
"""
@@ -482,7 +482,7 @@ class RetryPolicy(object):
:attr:`.Cluster.default_retry_policy` attribute to an instance of this
class or one of its subclasses.
To specify a retry policy per query, set the :attr:`.Query.retry_policy`
To specify a retry policy per query, set the :attr:`.Statement.retry_policy`
attribute to an instance of this class or one of its subclasses.
If custom behavior is needed for retrying certain operations,
@@ -516,7 +516,7 @@ class RetryPolicy(object):
as :attr:`.RETRY`) and a :class:`.ConsistencyLevel` to retry the
operation at or :const:`None` to keep the same consistency level.
`query` is the :class:`.Query` that timed out.
`query` is the :class:`.Statement` that timed out.
`consistency` is the :class:`.ConsistencyLevel` that the operation was
attempted at.
@@ -546,7 +546,7 @@ class RetryPolicy(object):
This is called when a write operation times out from the coordinator's
perspective (i.e. a replica did not respond to the coordinator in time).
`query` is the :class:`.Query` that timed out.
`query` is the :class:`.Statement` that timed out.
`consistency` is the :class:`.ConsistencyLevel` that the operation was
attempted at.
@@ -581,7 +581,7 @@ class RetryPolicy(object):
This means that the read or write operation was never forwared to
any replicas.
`query` is the :class:`.Query` that failed.
`query` is the :class:`.Statement` that failed.
`consistency` is the :class:`.ConsistencyLevel` that the operation was
attempted at.

View File

@@ -13,7 +13,7 @@ from cassandra.cqltypes import unix_time_from_uuid1
from cassandra.decoder import (cql_encoders, cql_encode_object,
cql_encode_sequence)
class Query(object):
class Statement(object):
"""
An abstract class representing a single query. There are two subclasses:
:class:`.SimpleStatement` and :class:`.BoundStatement`. These can
@@ -39,11 +39,6 @@ class Query(object):
to :attr:`.ConsistencyLevel.ONE`.
"""
keyspace = None
"""
The string name of the keyspace this query acts on.
"""
_routing_key = None
def __init__(self, retry_policy=None, tracing_enabled=False,
@@ -79,9 +74,17 @@ class Query(object):
components should be strings.
""")
class SimpleStatement(Query):
@property
def keyspace(self):
"""
A simple, un-prepared query. All attributes of :class:`Query` apply
The string name of the keyspace this query acts on.
"""
return None
class SimpleStatement(Statement):
"""
A simple, un-prepared query. All attributes of :class:`Statement` apply
to this class as well.
"""
@@ -91,7 +94,7 @@ class SimpleStatement(Query):
of parameter placeholders that will be filled through the
`parameters` argument of :meth:`.Session.execute()`.
"""
Query.__init__(self, *args, **kwargs)
Statement.__init__(self, *args, **kwargs)
self._query_string = query_string
@property
@@ -169,12 +172,12 @@ class PreparedStatement(object):
(self.query_string, consistency))
class BoundStatement(Query):
class BoundStatement(Statement):
"""
A prepared statement that has been bound to a particular set of values.
These may be created directly or through :meth:`.PreparedStatement.bind()`.
All attributes of :class:`Query` apply to this class as well.
All attributes of :class:`Statement` apply to this class as well.
"""
prepared_statement = None
@@ -190,13 +193,13 @@ class BoundStatement(Query):
def __init__(self, prepared_statement, *args, **kwargs):
"""
`prepared_statement` should be an instance of :class:`PreparedStatement`.
All other ``*args`` and ``**kwargs`` will be passed to :class:`.Query`.
All other ``*args`` and ``**kwargs`` will be passed to :class:`.Statement`.
"""
self.consistency_level = prepared_statement.consistency_level
self.prepared_statement = prepared_statement
self.values = []
Query.__init__(self, *args, **kwargs)
Statement.__init__(self, *args, **kwargs)
def bind(self, values):
"""

View File

@@ -17,7 +17,7 @@ from cassandra.policies import (RoundRobinPolicy, DCAwareRoundRobinPolicy,
RetryPolicy, WriteType,
DowngradingConsistencyRetryPolicy)
from cassandra.pool import Host
from cassandra.query import Query
from cassandra.query import Statement
class TestRoundRobinPolicy(unittest.TestCase):
@@ -191,7 +191,7 @@ class TokenAwarePolicyTest(unittest.TestCase):
policy.populate(cluster, hosts)
for i in range(4):
query = Query(routing_key=struct.pack('>i', i))
query = Statement(routing_key=struct.pack('>i', i))
qplan = list(policy.make_query_plan(None, query))
replicas = get_replicas(None, struct.pack('>i', i))
@@ -222,7 +222,7 @@ class TokenAwarePolicyTest(unittest.TestCase):
policy.populate(cluster, hosts)
for i in range(4):
query = Query(routing_key=struct.pack('>i', i))
query = Statement(routing_key=struct.pack('>i', i))
qplan = list(policy.make_query_plan(None, query))
replicas = get_replicas(None, struct.pack('>i', i))