atais / scassandra   0.1.0


Cassandra Datastax Driver - Scala Integration

Scala versions: 2.13 2.12 2.11 2.10

Cassandra Datastax Driver - Scala Integration

The project is based on numerous articles touching upon the topic of integration Cassandra Datastax driver with Scala. I was fed up copy-pasting those extra classes into all my projects. This is an open-source solution to that problem.

The integration is divided into two parts.


Minimal supported cassandra-driver-core version is 3.2.0.
Previous versions were based on guava 16.0.1 which was really difficult to use.

Cassandra Scala Integration

Project cassandra-scala allows for easier cassandra operations providing with CQL.

Add import com.github.atais.cassandra.ScalaIntegration._ to use it.

Example usage:

implicit protected val session: com.datastax.driver.core.Session
implicit protected val executor: java.util.concurrent.Executor

val selectCQL: ListenableFuture[PreparedStatement] = cql"SELECT * FROM $table WHERE key = ?"
val result: ListenableFuture[ResultSet] = execute(selectCQL, "my-key") =>

Available methods description:


Asynchronously create PreparedStatement for later reuse.

cql"SELECT * FROM $table WHERE key = ?"


Asynchronously execute PreparedStatement passing parameters.

ScalaIntegration.execute(cql"SELECT * FROM $table WHERE key = ?", "testValue")

ListenableFuture Scala Integration

Project listenable-future-scala allows for Scala-like handling of ListenableFuture.

Add import com.github.atais.listenablefuture.ListenableFutureScala._ to use it.

Available methods description:


       .map(text => text.length)
       .map(i    => i + 1)


       .flatMap(text => Futures.immediateFuture(text.length))
       .flatMap(i    => Futures.immediateCancelledFuture())

for-comprehension support

for {
  text   <- Futures.immediateFuture("abc")
  number <- Futures.immediateFuture(123)
} yield {
  text + number


scala.concurrent.Future uses PartialFunction to handle recover cases, however it is not possible with Guava. Instead one has to pass the Throwable class as function parameter matching with handling function.

       .map(_ => throw new UnsupportedOperationException)
       .recover[UnsupportedOperationException] {
         _: UnsupportedOperationException => "it's fine"


Has to be used similarly to recover, however function T => ListenableFuture[A] has to be provided.

       .map(_ => throw new UnsupportedOperationException)
       .recoverWith[UnsupportedOperationException] {
         _: UnsupportedOperationException => Futures.immediateFuture("it's fine")


Converts to scala.concurrent.Future



Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.