Convert a simple one line string to RDD in Spark

杀马特。学长 韩版系。学妹 提交于 2019-12-21 03:14:18

问题


I have a simple line:

line = "Hello, world"

I would like to convert it to an RDD with only one element. I have tried

sc.parallelize(line)

But it get:

sc.parallelize(line).collect()
['H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd']

Any ideas?


回答1:


try using List as parameter:

sc.parallelize(List(line)).collect()

it returns

res1: Array[String] = Array(hello,world)



回答2:


The below code works fine in Python

sc.parallelize([line]).collect()

['Hello, world']

Here we are passing the parameter "line" as a list.



来源:https://stackoverflow.com/questions/26157620/convert-a-simple-one-line-string-to-rdd-in-spark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!