简体   繁体   English

将n个元素的RDD转换为单个元素的RDD

[英]Transform an RDD of n elements into an RDD of single element

I have an RDD of strings like below 我有如下所示的字符串的RDD

val rdd1: RDD[String] = RDD("a","b","c","d")

I want to concatenate the elements of the above RDD and transform it into an RDD of single element like below 我想连接上述RDD的元素,并将其转换为单个元素的RDD,如下所示

RDD("a,b,c,d")

What is the best way of doing this? 最好的方法是什么?

Use the glom function: 使用glom函数:

val res: RDD[Array[String]] = RDD("a","b","c","d").glom
// > res = RDD(Array("a", "b", "c", "d"))

You can then convert the array into a string using the mkString function. 然后,您可以使用mkString函数将数组转换为字符串。

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

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