Syed Ammar Mustafa Syed Ammar Mustafa - 10 months ago 79
Java Question

Spark 1.5 and datastax-ddc-3.2.1 Cassandra Dependency Jars?

I am using Spark 1.5 and Cassandra 3.2.1 . Could anyone specify what are the exact jars required to be present in the build path to connect , query and insert data to Cassandra .

Right now I am using the follwing jars

With the above jars I am able to connect to cassandra . I am able to truncate tables , and drop tables . But I am unable to insert any data not even a simple insert query .

Following is the code :

import org.apache.spark.SparkConf;

import com.datastax.driver.core.Session;
import com.datastax.spark.connector.cql.CassandraConnector;

public class Test {

public static void main(String[] args) {

JavaSparkContext ctx = new JavaSparkContext(new SparkConf().setMaster("spark://blr-lt-203:7077").set("", "blr-lt-203").setAppName("testinsert").set("spark.serializer" ,"org.apache.spark.serializer.KryoSerializer").set("spark.kryoserializer.buffer.max" , "1024mb"));

CassandraConnector connector = CassandraConnector.apply(ctx.getConf());

Session session = connector.openSession();

session.execute("insert into test.table1 (name) values ('abcd')") ;



Following are the logs :

16/03/28 21:24:52 INFO BlockManagerMaster: Trying to register BlockManager
16/03/28 21:24:52 INFO BlockManagerMasterEndpoint: Registering block manager localhost:50238 with 944.7 MB RAM,BlockManagerId(driver, localhost, 50238)
16/03/28 21:24:52 INFO BlockManagerMaster: Registered BlockManager
16/03/28 21:24:53 INFO NettyUtil: Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
16/03/28 21:24:53 INFO Cluster: New Cassandra host localhost/ added
16/03/28 21:24:53 INFO CassandraConnector: Connected to Cassandra cluster: Test Cluster

It just stops here for some time and then times out with the foll exception :

Exception in thread "main" com.datastax.driver.core.exceptions.UnavailableException: Not enough replicas available for query at consistency LOCAL_QUORUM (2 required but only 1 alive)

  1. What am I doing wrong ?

  2. Please let me know what are the required jars or whether there is some version compatibility issues.

  3. What is the most stable versions of spark(1.5) and cassandra (?)

Thanks in Advance

Answer Source

The problem occurs due the conflicts between the google's guava libraries.

Solution is to shade the guava library present in the spark-cassandra-connector dependency. You can do so by using the maven shade plugin. Here is my pom.xml to shade off the guava library.

<project xmlns="" xmlns:xsi=""








After which you do a maven build which will generate a jar with all the dependency mentioned in the pom.xml also shading off the guava libraries using which you can submit spark jobs.