cassandrahector

Using hector, how to delete a range of super columns?


I have a super column family for which over the time need to remove a range of super columns. I searched around, didn't seem to find a solution for that using hector. Can anyone please help?


Solution

  • You'll have to do a column slice first to get the columns you want to delete, then loop through and generate a list of mutations. You can then send all these mutations to Cassandra in one Hector call:

    Mutator<..> mutator = HFactory.createMutator(keyspace, serializer);
    
    SuperSlice<..> result = HFactory.createSuperSliceQuery(keyspace, ... serializers ...)
                                    .setColumnFamily(cf)
                                    .setKey(key)
                                    .setRange("", "", false, Integer.MAX_VALUE)
                                    .execute()
                                    .get();
    
    for (HSuperColumn<..> col in result.getSuperColumns())
        mutator.addDeletion(key, cf, col.getName(), serializer);
    
    mutator.execute();