Inserting Data Into Cassandra table Using Spark DataFrame
<p>I'm using Scala Version 2.10.5 Cassandra 3.0 and Spark 1.6. I want to insert data into cassandra so I tried Out basic Example</p>

<pre><code>scala&gt; val collection = sc.parallelize(Seq(("cat", 30), ("fox", 40)))
scala&gt; collection.saveToCassandra("test", "words", SomeColumns("word", "count"))
</code></pre>

<p>Which Works and able insert data into Cassandra.So I had a csv file Which I wan to insert into Cassandra table by matching schema</p>

<pre><code>val person = sc.textFile("hdfs://localhost:9000/user/hduser/person")
import org.apache.spark.sql._
val schema =  StructType(Array(StructField("firstName",StringType,true),StructField("lastName",StringType,true),StructField("age",IntegerType,true)))
val rowRDD = person.map(_.split(",")).map(p =&amp;gt; org.apache.spark.sql.Row(p(0),p(1),p(2).toInt))
val personSchemaRDD = sqlContext.applySchema(rowRDD, schema)
 personSchemaRDD.saveToCassandra
</code></pre>

<p>When I am using SaveToCassndra Iam getting saveToCassandra is not part of personSchemaRDD. So taught of trying in different way </p>

<pre><code> df.write.format("org.apache.spark.sql.cassandra").options(Map( "table" -&gt; "words_copy", "keyspace" -&gt; "test")).save()
</code></pre>

<p>But getting the cannot connect to cassandra on ip:port.can any one tell me the best way to do it. I need to periodically save data to cassandra from the files.</p>