如何将spark rdd用管道传输到python并从python返回rdd

问题描述 投票:1回答:1

这是我在scala文件中的代码

val data = List("cdn.resized-images.covethome.com")
val dataRDD = sc.makeRDD(data)
val scriptPath = "/Users/hareshbhuriya/Documents/final-python-integration/web_domain_cleansing.py"
val result = dataRDD.pipe(scriptPath)

我正在使用python文件读取该字符串

for line in sys.stdin:
    output = sample_function(line)
    print(output)

这里python文件的输出是pandas dataFrame,我想在调用管道函数的scala文件中获取它。

如果我直接将字符串作为line传递,而不是将cdn.resized-images.covethome.com作为参数传递给sample_function,我将获得所需的输出。

喜欢这个

for line in sys.stdin:
    output = sample_function("cdn.resized-images.covethome.com")
    print(output)

但是我想动态传递字符串。我应该如何处理/处理来自sys.stdin的字符串?请帮助

dataframe apache-spark pipe rdd
1个回答
0
投票

我需要使用line.rstrip(),然后一切正常。谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.