thovex thovex - 1 month ago 12
Scala Question

Scala method toLowerCase in spark

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??

Answer

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.