Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions benchmarks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def benchmark(thread_class):
log.debug("Sleeping for two seconds...")
time.sleep(2.0)


# Generate the query
if options.read:
query = "SELECT * FROM {0} WHERE thekey = '{{key}}'".format(TABLE)
Expand Down Expand Up @@ -240,7 +239,6 @@ def parse_options():
parser.add_option('--read', action='store_true', dest='read', default=False,
help='Read mode')


options, args = parser.parse_args()

options.hosts = options.hosts.split(',')
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/callback_full_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def insert_next(self, previous_result=sentinel):
self.event.set()

i = next(self.num_started)
if i <= self.num_queries:
if i <= self.num_queries:
key = "{0}-{1}".format(self.thread_num, i)
future = self.run_query(key, timeout=None)
future.add_callbacks(self.insert_next, self.insert_next)
Expand Down
1 change: 1 addition & 0 deletions benchmarks/future_full_throttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

log = logging.getLogger(__name__)


class Runner(BenchmarkThread):

def run(self):
Expand Down
3 changes: 2 additions & 1 deletion cassandra/column_encryption/_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
AES256_KEY_SIZE = 256
AES256_KEY_SIZE_BYTES = int(AES256_KEY_SIZE / 8)

ColData = namedtuple('ColData', ['key','type'])
ColData = namedtuple('ColData', ['key', 'type'])


class AES256ColumnEncryptionPolicy(ColumnEncryptionPolicy):

Expand Down
2 changes: 2 additions & 0 deletions cassandra/cqlengine/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ def to_python(self, value):
value = value.date()
return util.Date(value)


class Time(Column):
"""
Stores a timezone-naive time-of-day, with nanosecond precision
Expand All @@ -625,6 +626,7 @@ def to_python(self, value):
return value
return util.Time(value)


class Duration(Column):
"""
Stores a duration (months, days, nanoseconds)
Expand Down
10 changes: 5 additions & 5 deletions cassandra/cqlengine/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ def register_connection(name, hosts=None, consistency=None, lazy_connect=False,
log.warning("Registering connection '{0}' when it already exists.".format(name))

if session is not None:
invalid_config_args = (hosts is not None or
consistency is not None or
lazy_connect is not False or
retry_connect is not False or
cluster_options is not None)
invalid_config_args = (hosts is not None
or consistency is not None
or lazy_connect is not False
or retry_connect is not False
or cluster_options is not None)
if invalid_config_args:
raise CQLEngineException(
"Session configuration arguments and 'session' argument are mutually exclusive"
Expand Down
2 changes: 2 additions & 0 deletions cassandra/cqlengine/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

from cassandra.cqlengine import UnicodeMixin, ValidationError


def get_total_seconds(td):
return td.total_seconds()


class QueryValue(UnicodeMixin):
"""
Base class for query filter values. Subclasses of these classes can
Expand Down
5 changes: 3 additions & 2 deletions cassandra/cqlengine/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _drop_keyspace(name, connection=None):
else:
_drop_keyspace(name)


def _get_index_name_by_column(table, column_name):
"""
Find the index name for a given table and column.
Expand Down Expand Up @@ -251,7 +252,7 @@ def _sync_table(model, connection=None):
col_meta = table_columns[db_name]
if col_meta.cql_type != col.db_type:
msg = format_log_context('Existing table {0} has column "{1}" with a type ({2}) differing from the model type ({3}).'
' Model should be updated.', keyspace=ks_name, connection=connection)
' Model should be updated.', keyspace=ks_name, connection=connection)
msg = msg.format(cf_name, db_name, col_meta.cql_type, col.db_type)
warnings.warn(msg)
log.warning(msg)
Expand Down Expand Up @@ -362,7 +363,7 @@ def _sync_type(ks_name, type_model, omit_subtypes=None, connection=None):
field_type = type_meta.field_types[defined_fields.index(field.db_field_name)]
if field_type != field.db_type:
msg = format_log_context('Existing user type {0} has field "{1}" with a type ({2}) differing from the model user type ({3}).'
' UserType should be updated.', keyspace=ks_name, connection=connection)
' UserType should be updated.', keyspace=ks_name, connection=connection)
msg = msg.format(type_name_qualified, field.db_field_name, field_type, field.db_type)
warnings.warn(msg)
log.warning(msg)
Expand Down
12 changes: 6 additions & 6 deletions cassandra/cqlengine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PolymorphicModelException(ModelException):
class UndefinedKeyspaceWarning(Warning):
pass


DEFAULT_KEYSPACE = None


Expand Down Expand Up @@ -412,16 +413,16 @@ def __init__(self, **values):

def __repr__(self):
return '{0}({1})'.format(self.__class__.__name__,
', '.join('{0}={1!r}'.format(k, getattr(self, k))
for k in self._defined_columns.keys()
if k != self._discriminator_column_name))
', '.join('{0}={1!r}'.format(k, getattr(self, k))
for k in self._defined_columns.keys()
if k != self._discriminator_column_name))

def __str__(self):
"""
Pretty printing of models by their primary key
"""
return '{0} <{1}>'.format(self.__class__.__name__,
', '.join('{0}={1}'.format(k, getattr(self, k)) for k in self._primary_keys.keys()))
', '.join('{0}={1}'.format(k, getattr(self, k)) for k in self._primary_keys.keys()))

@classmethod
def _routing_key_from_values(cls, pk_values, protocol_version):
Expand Down Expand Up @@ -562,7 +563,6 @@ def column_family_name(cls, include_keyspace=True):

return cf_name


@classmethod
def _raw_column_family_name(cls):
if not cls._table_name:
Expand All @@ -574,7 +574,7 @@ def _raw_column_family_name(cls):
table_name = cls.__table_name__.lower()
if cls.__table_name__ != table_name:
warn(("Model __table_name__ will be case sensitive by default in 4.0. "
"You should fix the __table_name__ value of the '{0}' model.").format(cls.__name__))
"You should fix the __table_name__ value of the '{0}' model.").format(cls.__name__))
cls._table_name = table_name
else:
if cls._is_polymorphic and not cls._is_polymorphic_base:
Expand Down
17 changes: 7 additions & 10 deletions cassandra/cqlengine/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def contains_(self, item):
"""
return WhereClause(str(self), ContainsOperator(), item)


def __eq__(self, other):
return WhereClause(str(self), EqualsOperator(), self._to_database(other))

Expand Down Expand Up @@ -149,7 +148,6 @@ class BatchQuery(object):
_connection = None
_connection_explicit = False


def __init__(self, batch_type=None, timestamp=None, consistency=None, execute_on_exception=False,
timeout=conn.NOT_SET, connection=None):
"""
Expand Down Expand Up @@ -384,7 +382,7 @@ def __init__(self, model):
self._count = None

self._batch = None
self._ttl = None
self._ttl = None
self._consistency = None
self._timestamp = None
self._if_not_exists = False
Expand Down Expand Up @@ -730,8 +728,8 @@ def filter(self, *args, **kwargs):
query_val = [column.to_database(v) for v in val]
elif isinstance(val, BaseQueryFunction):
query_val = val
elif (isinstance(operator, ContainsOperator) and
isinstance(column, (columns.List, columns.Set, columns.Map))):
elif (isinstance(operator, ContainsOperator)
and isinstance(column, (columns.List, columns.Set, columns.Map))):
# For ContainsOperator and collections, we query using the value, not the container
query_val = val
else:
Expand Down Expand Up @@ -1076,7 +1074,7 @@ def _validate_select_where(self):
# relationship with a primary key or indexed field. We also allow
# custom indexes to be queried with any operator (a difference
# between a secondary index)
equal_ops = [self.model._get_column_by_db_name(w.field) \
equal_ops = [self.model._get_column_by_db_name(w.field)
for w in self._where if not isinstance(w.value, Token)
and (isinstance(w.operator, EqualsOperator)
or self.model._get_column_by_db_name(w.field).custom_index)]
Expand Down Expand Up @@ -1366,9 +1364,8 @@ def _execute(self, statement):
connection = self.instance._get_connection() if self.instance else self.model._get_connection()
if self._batch:
if self._batch._connection:
if not self._batch._connection_explicit and connection and \
connection != self._batch._connection:
raise CQLEngineException('BatchQuery queries must be executed on the same connection')
if not self._batch._connection_explicit and connection and connection != self._batch._connection:
raise CQLEngineException('BatchQuery queries must be executed on the same connection')
else:
# set the BatchQuery connection from the model
self._batch._connection = connection
Expand Down Expand Up @@ -1477,7 +1474,7 @@ def save(self):
if self.instance._has_counter or self.instance._can_update():
if self.instance._has_counter:
warn("'create' and 'save' actions on Counters are deprecated. It will be disallowed in 4.0. "
"Use the 'update' mechanism instead.", DeprecationWarning)
"Use the 'update' mechanism instead.", DeprecationWarning)
return self.update()
else:
insert = InsertStatement(self.column_family_name, ttl=self._ttl, timestamp=self._timestamp, if_not_exists=self._if_not_exists)
Expand Down
25 changes: 13 additions & 12 deletions cassandra/cqlengine/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def update_context(self, ctx):
def get_context_size(self):
return 0


# alias for convenience
IsNotNull = IsNotNullClause

Expand Down Expand Up @@ -216,10 +217,10 @@ class SetUpdateClause(ContainerUpdateClause):
def __unicode__(self):
qs = []
ctx_id = self.context_id
if (self.previous is None and
self._assignments is None and
self._additions is None and
self._removals is None):
if (self.previous is None
and self._assignments is None
and self._additions is None
and self._removals is None):
qs += ['"{0}" = %({1})s'.format(self.field, ctx_id)]
if self._assignments is not None:
qs += ['"{0}" = %({1})s'.format(self.field, ctx_id)]
Expand Down Expand Up @@ -251,21 +252,21 @@ def _analyze(self):
def get_context_size(self):
if not self._analyzed:
self._analyze()
if (self.previous is None and
not self._assignments and
self._additions is None and
self._removals is None):
if (self.previous is None
and not self._assignments
and self._additions is None
and self._removals is None):
return 1
return int(bool(self._assignments)) + int(bool(self._additions)) + int(bool(self._removals))

def update_context(self, ctx):
if not self._analyzed:
self._analyze()
ctx_id = self.context_id
if (self.previous is None and
self._assignments is None and
self._additions is None and
self._removals is None):
if (self.previous is None
and self._assignments is None
and self._additions is None
and self._removals is None):
ctx[str(ctx_id)] = set()
if self._assignments is not None:
ctx[str(ctx_id)] = self._assignments
Expand Down
2 changes: 1 addition & 1 deletion cassandra/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# limitations under the License.

# This is only for backward compatibility when migrating from dse-driver.
from cassandra.datastax.graph import *
from cassandra.datastax.graph import *
1 change: 0 additions & 1 deletion cassandra/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

1 change: 0 additions & 1 deletion cassandra/io/asyncioreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ async def _push_msg(self, chunks):
for chunk in chunks:
self._write_queue.put_nowait(chunk)


async def handle_write(self):
while True:
try:
Expand Down
7 changes: 4 additions & 3 deletions cassandra/io/asyncorereactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

_dispatcher_map = {}


def _cleanup(loop):
if loop:
loop._cleanup()
Expand Down Expand Up @@ -389,7 +390,7 @@ def close(self):
self.error_all_requests(
ConnectionShutdown("Connection to %s was closed" % self.endpoint))

#This happens when the connection is shutdown while waiting for the ReadyMessage
# This happens when the connection is shutdown while waiting for the ReadyMessage
if not self.connected_event.is_set():
self.last_error = ConnectionShutdown("Connection to %s was closed" % self.endpoint)

Expand All @@ -416,8 +417,8 @@ def handle_write(self):
sent = self.send(next_msg)
self._readable = True
except socket.error as err:
if (err.args[0] in NONBLOCKING or
err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE)):
if (err.args[0] in NONBLOCKING
or err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE)):
with self.deque_lock:
self.deque.appendleft(next_msg)
else:
Expand Down
4 changes: 2 additions & 2 deletions cassandra/io/libevreactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ def handle_write(self, watcher, revents, errno=None):
try:
sent = self._socket.send(next_msg)
except socket.error as err:
if (err.args[0] in NONBLOCKING or
err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE)):
if (err.args[0] in NONBLOCKING
or err.args[0] in (ssl.SSL_ERROR_WANT_READ, ssl.SSL_ERROR_WANT_WRITE)):
if err.args[0] in NONBLOCKING:
self._socket_writable = False
with self._deque_lock:
Expand Down
Loading