Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
The recommended way to create new rows is with the models .create method. The values passed into a model’s init method are interpreted by the model as the values as they were read from a row. This allows the model to “know” which rows have changed since the row was read out of cassandra, and create suitable update statements.
Statement Ordering is not supported by CQL3 batches. Therefore, once cassandra needs resolving conflict(Updating the same column in one batch), The algorithm below would be used.
If timestamps are different, pick the column with the largest timestamp (the value being a regular column or a tombstone)
If timestamps are the same, and one of the columns in a tombstone (‘null’) - pick the tombstone
If timestamps are the same, and none of the columns are tombstones, pick the column with the largest value
Below is an example to show this scenario.
class MyMode(Model):
id = columns.Integer(primary_key=True)
count = columns.Integer()
text = columns.Text()
with BatchQuery() as b:
MyModel.batch(b).create(id=1, count=2, text='123')
MyModel.batch(b).create(id=1, count=3, text='111')
assert MyModel.objects(id=1).first().count == 3
assert MyModel.objects(id=1).first().text == '123'
The largest value of count is 3, and the largest value of text would be ‘123’.
The workaround is applying timestamp to each statement, then Cassandra would resolve to the statement with the lastest timestamp.
with BatchQuery() as b:
MyModel.timestamp(datetime.now()).batch(b).create(id=1, count=2, text='123')
MyModel.timestamp(datetime.now()).batch(b).create(id=1, count=3, text='111')
assert MyModel.objects(id=1).first().count == 3
assert MyModel.objects(id=1).first().text == '111'
When inserting with CQLEngine, None
is equivalent to CQL NULL
or to
issuing a DELETE
on that column. For example:
class MyModel(Model):
id = columns.Integer(primary_key=True)
text = columns.Text()
m = MyModel.create(id=1, text='We can delete this with None')
assert MyModel.objects(id=1).first().text is not None
m.update(text=None)
assert MyModel.objects(id=1).first().text is None
Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
cassandra
- Exceptions and Enumscassandra.cluster
- Clusters and Sessionscassandra.policies
- Load balancing and Failure Handling Policiescassandra.auth
- Authenticationcassandra.metadata
- Schema and Ring Topologycassandra.metrics
- Performance Metricscassandra.query
- Prepared Statements, Batch Statements, Tracing, and Row Factoriescassandra.pool
- Hosts and Connection Poolscassandra.protocol
- Protocol Featurescassandra.encoder
- Encoders for non-prepared Statementscassandra.decoder
- Data Return Formatscassandra.concurrent
- Utilities for Concurrent Statement Executioncassandra.connection
- Low Level Connection Infocassandra.util
- Utilitiescassandra.timestamps
- Timestamp Generationcassandra.io.asyncioreactor
- asyncio
Event Loopcassandra.io.asyncorereactor
- asyncore
Event Loopcassandra.io.eventletreactor
- eventlet
-compatible Connectioncassandra.io.libevreactor
- libev
Event Loopcassandra.io.geventreactor
- gevent
-compatible Event Loopcassandra.io.twistedreactor
- Twisted Event Loopcassandra.cqlengine.models
- Table models for object mappingcassandra.cqlengine.columns
- Column types for object mapping modelscassandra.cqlengine.query
- Query and filter model objectscassandra.cqlengine.connection
- Connection management for cqlenginecassandra.cqlengine.management
- Schema management for cqlenginecassandra.cqlengine.usertype
- Model classes for User Defined Types