Search code examples
kunderacassandra-2.1

How to do delete rows based on indexed column in cassandra


Current Approach that i am using for deleting rows based on indexed column

  1. Select query with a limit 100.
  2. If there are rows Delete all the fetched rows one by one.
  3. Flush the entity Manager.
  4. Go to step 1.

Using cassandra 2.1.8 and kundera-cassandra-ds-driver for fetching rows from cassandra.

Is there any way to fire a delete query from Kundera.


Solution

  • You can do the following:

    Query findQuery = entityManager.createQuery("Delete from PersonCassandra p where p.age = 10",
                PersonCassandra.class);
    findQuery.setMaxResults(5000);
    findQuery.executeUpdate();
    

    PS: Cassandra does not allow deleting rows based on non-primary keys, Kundera handles this internally in a similar way that you are doing.