scala spark中的scala方法toLowerCase

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39952151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:42:55  来源:igfitidea点击:

Scala method toLowerCase in spark

scalaapache-spark

提问by NaHeon

val file = sc.textFile(filePath)
val sol1=file.map(x=>x.split("\t")).map(x=>Array(x(4),x(5),x(1)))
val sol2=sol1.map(x=>x(2).toLowerCase)

In sol1, I have created an Rdd[Array[String]] and I want to put for every array the 3rd string element in LowerCase so call the method toLowerCase which should do that but instead it transform the string in lowercase char??

在 sol1 中,我创建了一个 Rdd[Array[String]] 并且我想为每个数组放入 LowerCase 中的第三个字符串元素,因此调用方法 toLowerCase 应该这样做,但它会将字符串转换为小写字符?

回答by NaHeon

I assume you want to convert 3rd array element to lower case

我假设您想将第三个数组元素转换为小写

val sol1=file.map(x=>x.split("\t"))
             .map(x => Array(x(4),x(5),x(1).toLowerCase))

In your code, sol2 will be the sequence of string, not the sequence of array.

在您的代码中, sol2 将是字符串序列,而不是数组序列。