如何星火更换字写程序 [英] How to write program in Spark to replace word

查看:202
本文介绍了如何星火更换字写程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很容易让Hadoop的使用 .replace()例如:

it is easy for Hadoop to use .replace() for example

String[] valArray = value.toString().replace("\N", "")

但它在这么想的工作星火,我写在斯卡拉星火壳像下面

But it dosen't work in Spark,I write Scala in Spark-shell like below

val outFile=inFile.map(x=>x.replace("\N",""))

那么,该如何应对呢?

So,how to deal with it?

推荐答案

由于某种原因,你的 X 数组[字符串] 。你怎么会这样?您可以 .toString.replace ,如果你喜欢,但你想要的(反正会给Java中的错误输出),将可能不会得到你;你可能想要做地图的另一层, inFile.map(X =方式> x.map(_替换(\\ n,)))

For some reason your x is an Array[String]. How did you get it like that? You can .toString.replace it if you like, but that will probably not get you what you want (and would give the wrong output in java anyway); you probably want to do another layer of map, inFile.map(x => x.map(_.replace("\N","")))

这篇关于如何星火更换字写程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆