A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://datastax.github.io/python-driver/cqlengine/faq.html below:

Frequently Asked Questions — Cassandra Driver 3.13.0 documentation

Frequently Asked Questions Why don’t updates work correctly on models instantiated as Model(field=value, field2=value2)?

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.

How to preserve ordering in batch query?

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.

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'
How can I delete individual values from a row?

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4