简体   繁体   English

更新Cassandra行中设置类型的列

[英]update column of set type in Cassandra row

I have one RDD [PersonType] = [pid,cid,firstname, lastname, age, source, sourceType, message] value as RDD = [1000,100,Vikash,Singh,33,source,sourceType,message] 我有一个RDD [PersonType] = [pid,cid,firstname,lastname,age,source,sourceType,message]值,作为RDD = [1000,100,Vikash,Singh,33,source,sourceType,message]

and I have csaandra row as [pid,cid,firstname,lastname,age,dept,mrids] here mrids is set . 我有csaandra row作为[pid,cid,firstname,lastname,age,dept,mrids],这里设置了mrids。 suppose value in cassandra is [1000,100,vikash,singh,33,bank,{sourceold.sourceTypeold.messageold} 假设cassandra中的值为[1000,100,vikash,singh,33,bank,{sourceold.sourceTypeold.messageold}

I want to update the cassandra column mrids with both old and new value. 我想用新旧值更新cassandra列的内容。 so My new updated value in cassandra should be [1000,100,vikash,singh,33,bank,{sourceold.sourceTypeold.messageold, source.sourceType.message} 因此,我在cassandra中的新更新值应为[1000,100,vikash,singh,33,bank,{sourceold.sourceTypeold.messageold,source.sourceType.message}

Please tell me how to update mrids column. 请告诉我如何更新mrids栏。

val rdd[personType] = rdd1
val rdd2 = sc.cassandraTable(keyspace,tablename)
              .select("p_id","c_id", "mrids")

what code should i write next to achieve this? 接下来我应该写什么代码来实现这一目标?

This should get you started. 这应该使您入门。

It shows you how to do join of rdd based on key, and append data into set of another rdd. 它显示了如何基于密钥进行rdd的联接,以及如何将数据附加到另一个rdd的集合中。

val temp = List((1, 4, Set(1)),
                    (2, 5, Set(2)),
                    (3, 6, Set(3))
                    )
val temp2 = List((1, 11, 11),
                  (2, 11, 22),
                  (3, 11, 33)
                )
val temp_rdd = sc.parallelize(temp)

val temp2_rdd = sc.parallelize(temp2)

val test = temp_rdd.map{case(key, data, set)=>((key),(data, set))}
                        .join(temp2_rdd.map{case(key, data, set_new_value)=>((key),(data, set_new_value))})
                        .map{case(key, ((data1, set),(data2, set_new_value)))=>(key, set.toSet + set_new_value)}


test.collect().foreach(println)

at the end you can use rdd.saveToCassandra to save the rdd resultset. 最后,您可以使用rdd.saveToCassandra保存rdd结果集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM