1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
tom
  • 14,273
  • 19
  • 65
  • 124

1 Answers1

1

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();
rs_atl
  • 8,935
  • 1
  • 23
  • 28
  • I am having a different problem now. If I just want to delete a single column, do I still have to do the superslice query which I believe it quite expensive? – tom Jun 07 '12 at 20:40
  • If you already know the keys you can simply create a list of mutations, one for each key, and provide the column name (same thing as in the answer above). If you don't know the keys you'll want a RangeSlicesQuery, where you can call setReturnKeysOnly() to avoid getting everything back. – rs_atl Jun 08 '12 at 13:59
  • It's also worth noting that you should investigate replacing your SCs with composites. See [this article](http://www.datastax.com/dev/blog/introduction-to-composite-columns-part-1) for details on composite columns. – rs_atl Jun 08 '12 at 14:00
  • got it, thanks a lot @rs_atl. can you please help on this question as well? http://stackoverflow.com/questions/10939411/hector-querysupercolumns-returns-only-partial-super-columns, it happens when there are large amount of supercolumns. – tom Jun 08 '12 at 16:01