Search code examples
scalaapache-sparkcassandraspark-cassandra-connector

Saving data from Spark to Cassandra results in java.lang.ClassCastException


I'm trying to save data from Spark to Cassandra in Scala using saveToCassandra for an RDD or save with a dataframe (both result in the same error). The full message is:

java.lang.ClassCastException: com.datastax.driver.core.DefaultResultSetFuture cannot be cast to com.google.common.util.concurrent.ListenableFuture

I've followed along with the code here and still seem to get the error.

I'm using Cassandra 3.6, Spark 1.6.1, and spark-cassandra-connector 1.6. Let me know if there's anything else I can provide to help with the debugging.


Solution

  • I had similar exception and fixed it after changing in build.sbt scala version:

    scalaVersion := "2.10.6"
    

    and library dependencies:

    libraryDependencies ++= Seq(
      "com.datastax.spark" %% "spark-cassandra-connector" % "1.6.0",
      "com.datastax.cassandra" % "cassandra-driver-core" % "3.0.2",
      "org.apache.spark" %% "spark-core" % "1.6.1" % "provided",
      "org.apache.spark" %% "spark-sql" % "1.6.1" % "provided"
    )
    

    With this configuration example from 5-minute quick start guide works fine.