· 10 years ago · Sep 21, 2016, 02:48 AM
1case class Person(name: String, age: Long, ttl: Long)
2
3val caseClassDF = Seq(Person("Andy", 32, 5000000), Person("Mark", 27, 1000000)).toDF()
4
5caseClassDF.show()
6// +----+---+-------+
7// |name|age| ttl|
8// +----+---+-------+
9// |Andy| 32|5000000|
10// |Mark| 27|1000000|
11// +----+---+-------+
12
13// With Table:
14// CREATE TABLE IF NOT EXISTS test.person (
15// name BIGINT,
16// age BIGINT,
17// PRIMARY KEY (name, age)
18// )
19
20caseClassDF.write
21 .format("org.apache.spark.sql.cassandra")
22 .options(Map( "table" -> "words_copy", "keyspace" -> "test", "ttl_column" -> "ttl"))
23 .save()