Skip to content

Instantly share code, notes, and snippets.

@mkwatson
Created September 20, 2016 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkwatson/ecdafc47720c74b2bee7586c2e2bf300 to your computer and use it in GitHub Desktop.
Save mkwatson/ecdafc47720c74b2bee7586c2e2bf300 to your computer and use it in GitHub Desktop.
case class Person(name: String, age: Long, ttl: Long)
val caseClassDF = Seq(Person("Andy", 32, 5000000), Person("Mark", 27, 1000000)).toDF()
caseClassDF.show()
// +----+---+-------+
// |name|age| ttl|
// +----+---+-------+
// |Andy| 32|5000000|
// |Mark| 27|1000000|
// +----+---+-------+
// With Table:
// CREATE TABLE IF NOT EXISTS test.person (
// name BIGINT,
// age BIGINT,
// PRIMARY KEY (name, age)
// )
caseClassDF.write
.format("org.apache.spark.sql.cassandra")
.options(Map( "table" -> "words_copy", "keyspace" -> "test", "ttl_column" -> "ttl"))
.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment