1

Currently, I have setup a project with springboot, I can use the CassandraRepository to query the data from cassandra database.

But now, I have faced some problems:

  1. How can I use the BatchStatment in cassandra with CassandraRepository?
  2. How to create the Statement by CassandraRepository?

I want to use BatchStatment.add(Statement) to implement the batch query. MappingManager.getSession().execute(statement)

2 Answers 2

4

To use Springs version there is CassandraBatchOperations from CassandraTemplate.batchOps().

The MappingManager is from the DataStax ORM so its kinda mixing things up. While it doesn't directly support batching (because it's usually wrong thing to do) you can call the mapper.saveQuery(obj) method to get the raw Statement and add it to a new BatchStatement() you created yourself and pass that to the Session.execute.

Be sure you actually need batches (for the atomicity). They are slow, expensive and don't scale as well as normal inserts.

Sign up to request clarification or add additional context in comments.

1 Comment

Plus one for that last sentence. In fact, maybe we should bold that.
0

The best approach to write to cassandra is through concurrent async writes.(supported by Datastax driver).

Does batch operation contains mixed partition key , if yes then batch would be slower compare to async writes

for mixed partition batch queries, we have implemented token aware batch statement method that really showed good performance with large set of data.

Follow that link for details: https://dzone.com/articles/efficient-cassandra-write

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.