You're viewing documentation for a previous version of Scylla Python Driver. Switch to the latest stable version.
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
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
cassandra- Exceptions and Enums
cassandra.cluster- Clusters and Sessions
cassandra.policies- Load balancing and Failure Handling Policies
cassandra.graph- Graph Statements, Options, and Row Factories
cassandra.metadata- Schema and Ring Topology
cassandra.metrics- Performance Metrics
cassandra.query- Prepared Statements, Batch Statements, Tracing, and Row Factories
cassandra.pool- Hosts and Connection Pools
cassandra.protocol- Protocol Features
cassandra.encoder- Encoders for non-prepared Statements
cassandra.decoder- Data Return Formats
cassandra.concurrent- Utilities for Concurrent Statement Execution
cassandra.connection- Low Level Connection Info
cassandra.timestamps- Timestamp Generation
gevent-compatible Event Loop
cassandra.io.twistedreactor- Twisted Event Loop
cassandra.cqlengine.models- Table models for object mapping
cassandra.cqlengine.columns- Column types for object mapping models
cassandra.cqlengine.query- Query and filter model objects
cassandra.cqlengine.connection- Connection management for cqlengine
cassandra.cqlengine.management- Schema management for cqlengine
cassandra.cqlengine.usertype- Model classes for User Defined Types
cassandra.datastax.graph- Graph Statements, Options, and Row Factories