Spark for Beginners: Tutorials – Connecting To Cassandra

Français Français

Welcome, we will discover in this tutorial how to connecting Spark with Cassandra database using the Java language. The code will be done in Java you will find it the Gist Github links in the tutorial.

Video Demo

Installing DataStax Distribution of Apache Cassandra

Download and install DataStax Community Edition v2.1.1 64-bit or chose another versions.

Adding dependencies Cassandra

To use Cassandra with Apache Spark we need Cassandra Connector for Spark.

First we’ll create a new Maven project with Eclipse, for this example I will create a small product management application. I choose tn.esprit as Group Id and cassandra  as Artifact Id.

We’re gonna change the pom.xml by adding dependencies. And we’ll specify the Java 1.8 version for the Maven compiler.

Create CassConnector(java class) that will connect to the cassandra database, and we’re going to create a new KEYSPACE  and use it.

Execution & test with Cassandra CQL shell

To run our application, we must first generate it with Manven by running maven install and  right click on the file and Run As Java Application .

Now test the creation of new KEYSPACE with Cassandra CQL shell