Apache spark Spark中的多重分割与映射

Apache spark Spark中的多重分割与映射,apache-spark,rdd,Apache Spark,Rdd,在使用文件的#拆分后,我有以下内容 res64: Array[(String, String)] = Array((1,Animation|Children's|Comedy), (2,Adventure|Children's|Fantasy)) 如何获得唯一对(使用distinct),如(1,动画),(1,儿童的)等。。对于每个键(此处为电影id),如RDD中的1?可以简单到 rdd.mapValues(x => x.split('|'))\ .flatMapValues(x=>

在使用文件的
#
拆分后,我有以下内容

res64: Array[(String, String)] = Array((1,Animation|Children's|Comedy), (2,Adventure|Children's|Fantasy))
如何获得唯一对(使用distinct),如
(1,动画),(1,儿童的)
等。。对于每个
(此处为电影id),如
RDD中的1

可以简单到

rdd.mapValues(x => x.split('|'))\
.flatMapValues(x=>x)\ 
.distinct()\
.collect()