DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

chandrasekar.b03_190734 avatar image
chandrasekar.b03_190734 asked ·

What libraries should I import to create Cassandra batch statements in python ?

I have a keyspace killrvideo. I have 3 tables named "addProduct", "productDetails", "buyProduct". Now when I insert or update any one of the tables, I needed it to be copied to the related tables also. My choice is to use batch statement (With caution). I can execute it in CLI but unable to execute it in python. So how do I create batch statements in python? What libraries should I import for that other than cassandra-driver? Note: I'm running a single node cluster on docker compose with rf=1 and SimpleStrategy.

python driver
10 |1000 characters needed characters left characters exceeded

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

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

To run BATCH queries, you need to import BatchQuery:

from cassandra.cqlengine.query import BatchQuery

and create a BatchQuery instance, for example:

b = BatchQuery()

For details and examples, see Batch Queries in the Python driver. cheers!

1 comment Share
10 |1000 characters needed characters left characters exceeded

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

Hi Erick,

I'm so sorry that I'm not able to understand the code given in the link https://docs.datastax.com/en/developer/python-driver/3.24/cqlengine/batches/ in a section "Batch Query genral use pattern".

If possible could you kindly clarify with a simple code to insert a record using batch :)

That would be very helpful:)

0 Likes 0 · ·