0

I have a column family like this -

create column family TEST
with key_validation_class = 'UTF8Type'
and comparator = 'UTF8Type'
and default_validation_class = 'UTF8Type'
and column_metadata = [ {column_name : 'date', validation_class : DateType}];

And it's a dynamic column family which means we can insert lot of columns and there data at runtime... We want to keep only one column and its data in the above column family.. Which means we want to delete all other columns except that above one column and its data from this column family...

What is the best way to do this? Should we write a simple program to do this or there is any other way by which we can delete all the columns except that one column which I need and its data..

Thanks..

AKIWEB
  • 19,008
  • 67
  • 180
  • 294

1 Answers1

0

The simplest way would be to read out the one column you want to retain and copy it somewhere, then truncate the CF, then write the saved column back.

rs_atl
  • 8,935
  • 1
  • 23
  • 28
  • what will happen then for the application that are using those tables? Are you thinking of making a code change? – AKIWEB Oct 15 '13 at 18:56
  • If you're writing to this CF at the same time as you're running this delete, there's no way to guarantee you'll end up with only one column. I presume you're doing this to an offline CF; if not you'll need to manually delete the columns. If you do this you'll create tombstones, and you'll want to make sure your query doesn't have to read the entire list of tombstones before getting to your one row. This sounds like a terrible data model, FWIW. – rs_atl Oct 15 '13 at 20:36
  • The attributes that we need to delete, we are not writing it anymore... Only a single attribute that we need, we are just writing that into CF.. And whatever read is happening as well, it is happening only on that single column... – AKIWEB Oct 15 '13 at 21:14
  • Maybe you should describe your use case a bit. From the CLI snippet you posted and your problem description I'm pretty sure your data model could be improved to get rid of this problem entirely. – rs_atl Oct 15 '13 at 21:51