Confusing API's for save to cassandra.
ScrapCodes opened this issue · 1 comments
ScrapCodes commented
I find it confusing the way we update data into cassandra.
for example
val cas = CasBuilder.cql3.withColumnFamily("casdemo", "words")
.saveWithQuery("update casdemo.words set count = ?")
Here we did not specify the key.
It goes in the key marshaller as following, I was wondering if we can do it in a better way.
implicit def keyMarshaller(x: (String, Int)): Map[String, ByteBuffer] =
Map("word" -> x._1)
milliondreams commented
What do you think about this?
case class Employee(deptId: Int, empId: Int, firstName: String, lastName: String)
val data = List(
Employee(31, 210, "emily", "richards"),
Employee(31, 211, "fanie", "mae"),
Employee(32, 208, "godric", "wolf"),
Employee(33, 202, "harry", "potter")
)
val rdd = sc.parallelize(data)
implicit def EmployeeToMap(e: Employee): Map[String, ByteBuffer] = {
Map("deptid" -> e.deptId, "empid" -> e.empId, "first_name" -> e.firstName, "last_name" -> e.lastName)
}
rdd.simpleSavetoCas(CQL_TEST_KEYSPACE,
CQL_TEST_OUTPUT_COLUMN_FAMILY,
List("deptid", "empid"), List("first_name", "last_name"))
The signature of this call is -
def simpleSavetoCas(keyspace: String, columnFamily: String, keyCols: List[String], valueCols: List[String])
(implicit marshaller: U => Map[String, ByteBuffer], um: ClassManifest[U])