9

I have code that uses Hector to access Cassandra and needs to create column families on the fly if and only if they don't already exist. What is the proper way to check for the existence of a column family in a keyspace?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user430788
  • 2,143
  • 2
  • 17
  • 17
  • 1
    What happens if you try to create a CF that already exists? In the Cassandra CLI this throws an error. If the same happens in Hector then you could attempt to create the CF and catch the exception if the CF already exists. – DNA Jun 19 '11 at 20:55
  • 1
    This is pretty easy to deduce - it comes back as an HInvalidRequestException (our wrapping of the thrift exception) with a detailed error message. – zznate Jun 20 '11 at 22:54

1 Answers1

9

I posted some info in our Hector wiki.

https://github.com/rantav/hector/wiki/Getting-started-%285-minutes%29

Basically once you get the KeyspaceDef you can call:

keyspaceDef.getCfDefs() and see if the CF is there.

Patricio
  • 919
  • 1
  • 6
  • 8
  • How exactly do yo use getCfDefs()? Assuming keyspaceDef is a KeyspaceDefinition.`List lcf = keyspaceDef.getCfDefs();` should be correct, right? – Henry Aug 24 '11 at 21:19