首页 > 解决方案 > 如何在 spark 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: identifier expected but integer literal found.

标签: scala

解决方案


sc.wholeTextFiles() 返回 scala 元组(字符串,字符串)。要访问成员,请使用 x._1 和 x._2。

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

推荐阅读