Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何删除spark scala中的新行字符_Scala - Fatal编程技术网

如何删除spark scala中的新行字符

如何删除spark scala中的新行字符,scala,Scala,下面的代码在python中运行良好。我在用scala编写等效代码时遇到困难 map(lambda x:x[1].replace("\n","|")) Scala中的等效代码是什么 我尝试在Scala中运行下面的命令,并得到下面的错误 scala> val read_rdd=sc.wholeTextFiles("/user/test/test1.txt").map(x => x[1].replace("\n","\u001F")) <console>:1: error:

下面的代码在python中运行良好。我在用scala编写等效代码时遇到困难

map(lambda x:x[1].replace("\n","|"))
Scala中的等效代码是什么

我尝试在Scala中运行下面的命令,并得到下面的错误

scala> val read_rdd=sc.wholeTextFiles("/user/test/test1.txt").map(x => x[1].replace("\n","\u001F"))
<console>:1: error: identifier expected but integer literal found.

scala>val read\u rdd=sc.wholeTextFiles(“/user/test/test1.txt”).map(x=>x[1]。替换(“\n”,“\u001F”))
:1:错误:应为标识符,但找到整数文字。
sc.wholeTextFiles()返回scala元组(字符串,字符串)。要访问成员,请使用x._1和x._2

val read_rdd=sc.wholeTextFiles("e_edge.csv").map(x => x._2.replace("\n","\u001F"))

您的输入数据是什么?它是否包含
\n
s?您在Scala中写了什么?你能给我们一些test.val read\u rdd=sc.wholeTextFiles(“test1.txt”).map(x=>x[1]。replace(“\n”,“\u001F”))的示例输入吗?这是我正在尝试的。但是它得到的错误是
x[1]
不是Scala语法。您可以使用Scala lambda的简短版本:.map(\uu.\u 2.replace(“\n”,“\u001F”))