saveToCassandra保存整个表而不是单行

时间:2016-01-20 18:17:36

标签: scala apache-spark cassandra

我有一个cassandra键空间和表,我正在查询数据,以便写入另一个键空间/表。我的代码如下:

val test = sc.cassandraTable("model","data")
.where("id = 9999999")
.select("id","cl1","cl2","data")
.filter(row => row.getString("data") == "Hello")


test.saveToCassandra("model","dataspark",SomeColumns("id","cl1","cl2","data"))

问题是出于某种原因,它正在将model.data中的所有内容写入我在val测试变量中指定的model.dataspark INSTEAD中。我必须有一些语法或错误。

如果我.collect并执行.foreach(println),它只显示我按预期查询的单个条目。我的saveToCassandra语句一定是错的,但我不确定它有什么问题。

我用一个案例类和相同的结果尝试了整个事情:

case class Record(id: Int, cl1: Int, cl2: Int, data: Option[String])
val test = sc.cassandraTable[Record]("model","data")
.where("id = 9999999").select("id","cl1","cl2","data")
test.saveToCassandra("model","dataspark", SomeColumns("id","cl1","cl2","data"))

1 个答案:

答案 0 :(得分:0)

我发现了问题。

val test = sc.cassandraTable("model","data")
.where("id = 9999999")

需要所有人都在同一条线上

val test = sc.cassandraTable("model","data").where("id = 9999999")