chandrasekar.b03_190734 avatar image
chandrasekar.b03_190734 asked chandrasekar.b03_190734 commented

What is the difference between "BatchStatement" and "BatchQuery" in C*?

I have already asked a question about creating Batch Statements in C* python. I got an answer to use BatchQuery. I found very difficult to code using that.

I have then searched datastax docs for an alternate command and I found BatchStatement in C* package. So what is the difference between BatchQuery and BatchStatement?

Which one is good for querying CRUD op during denormalization? Will that be useful when deploying applications like SpaceCraft application on week 3 exercise?

If not, which approach will be useful for denormalization when deploying application ?

python driverbatch
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered chandrasekar.b03_190734 commented

Hi @chandrasekar.b03_190734,

the difference between BatchStatement and BatchQuery applies to the Python driver. They both write C* batch statements, logged and unlogged.

cqlengine is the Cassandra CQL 3 Object Mapper packaged with the later versions of the Datastax Python driver.

cqlengine supports batch queries using the BatchQuery class.

In order to use this BatchQuery class, you will need to implement the Object Mapper.

See here how to get started with that:

However, you can also create batches by using the BatchStatement, imported from cassandra.query. This does not need the Object Mapper.

This is the method we are using the in the Python Getting Started with Astra backend, by the way, see here for an example:

For the API reference, see here:

The batch type is by default BatchType.LOGGED.

To understand the difference between logged and unlogged batches, please also refer to the cql documentation re batches, and please note the performance caveats. While batches seem convenient, they can be detrimental for performance when multiple partitions are involved.

Also have a look at some other questions re batch statements here, for example:

I hope this helps!

1 comment Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

chandrasekar.b03_190734 avatar image chandrasekar.b03_190734 commented ·

Yes, now I totally understood what are batches and how they may affect the performance during multiple partition.

Thanks bettina for this help.

0 Likes 0 ·