Archive for November, 2013

Using Cassandra from Scala

November 16, 2013 5 comments

I have started a new open source project that is a Scala wrapper for CQL  specifically its a wrapper of the DataStax java-driver.

Test cases are a good entry point so lets start here

class ScalaCassandraSpec extends Specification {


    "Meta objects" should {
      "be able to store & retrieve their binary state" in {

      //we use a Thrift object here for portability of the data stored
      val tMeta = new TMeta()

      //setting up some randomness so we can confirm what we are writing is what we get back
      val metaUUID = UUID.randomUUID()
      val dataum = Random.alphanumeric.take(1000000).mkString

      tMeta.setDatum(dataum) //Saved to C*

      val someNewTMeta = Meta(metaUUID)
      someNewTMeta.getId() must_== metaUUID.toString

      someNewTMeta.getDatum() must_== dataum

The Meta class (contained in the file) is like a Widget… Whats a Widget? For us lets consider its like “sample code”.

When you want to add something different than a widget create a new thrift file in the `thrift/interface` directory

Then in that directory (lets say you created an IDL called Music.thrift) then run `thrift -gen java Music.thrift` which we did for you already and copy the jar outputted from a `mvn package` to the `lib` folder so you don’t have to worry about it. You can even just keep using the Meta implementaiotn and just shove JSON or XML or whatever you want into it; however, it makes more sense to partition the objects some so you can create wider rows with a collection key in your table along with your partition key. You can also flatten the things by storing a HashMap on the table and retrieving it.