Implementation of a Scala wrapper over the DataStax Java Driver for Cassandra
Switch branches/tags
Nothing to show
Clone or download


Quick up and running using Scala for Apache Cassandra

Use Vagrant to get up and running.

  1. Install Vagrant
  2. Install Virtual Box

Then once that is done (or if done already)

  1. git clone
  2. cd scala-cassandra
  3. vagrant up
  4. ./sbt test

Cassandra will be running in the virtual machine on and is accessible from your host machine.

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

     val newMetaObj = new MetaTableName(metaUUID, tMeta) //Saved to C*

     val savedMetaObj = new MetaTableName(metaUUID)
     val someNewTMeta = savedMetaObj.get()
     someNewTMeta.getId() must_== metaUUID.toString

     someNewTMeta.getDatum() must_== dataum

The example implementation is contained in the and you should mirror your implementation around this.

case class MetaTableName(id: UUID, blobMeta: TMeta) extends Table with Instrument {
  def this() = this(null, null)
  def this(id: UUID) = this(id, null)

  tableName = "MetaTableName"
  tableColumnNames = List("id uuid",blobColumnName + " blob")
  tablePrimaryKey = "id"

  def bindIdAndBlob(exec:(List[String])=>BoundStatement) = {
    val blobBytes: ByteBuffer = blobMeta 
    exec(List("id", blobColumnName)).bind(id,blobBytes)

  //bind just the id to some CQL call in the DAL
  def bindId(exec: (String)=>BoundStatement) = {

  //save the object we have, upsert
  def save() = {
    val context = time(MetaTableName,BlobMetric.insert)
    try {
    } finally {

  //just get back the stored serialized object just based on the one primary key
  def get(): TMeta = {     
    getBlob(new TMeta(), bindId(getSavedBlob)).asInstanceOf[TMeta]

This patern is what you need to-do moving forward. You need to setup the local binding functions so the Table trait knows nothing about your object but still can bind to your values you need passing in. You also need to implement the saving and get with a minimal of boilter plate for the access layer. And that is it.

Big Data Open Source Security LLC