简体   繁体   English

Spark(scala):计算RDD上整列的所有不同值

[英]Spark(scala): Count all distinct values of a whole column on RDD

I have this RDD: 我有这个RDD:

val resultRdd: RDD[(VertexId, String, Seq[Long])]

I want to count the distinct values in Seq of all records. 我想计算所有记录的Seq中的不同值。

for example, if I have 3 records with Seq values as follows: 例如,如果我有3条Seq值的记录,如下所示:

VertexId ------- String -------Seq[Long]
1 ----------------- x -------------  1, 3
2 ----------------- x -------------  1, 5
3 ----------------- x--------------- 2, 3, 6

the result should be = 5 , the count of {1,3,5,2,6} 结果应为= 5,计数{1,3,5,2,6}

Thanks :) 谢谢 :)

resultRdd.flatMap(_._3).distinct().count()

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

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