-2

Brand new to Scala, sorry for the easy question. I need to produce map reduce logic in Scala that creates key-value pairs from words in a text file. The words are the keys and the count of the words are the values.

My issue: I need all keys to be lower case

My current code:

val test = sc.textFile("cat.txt");
val flattenMap = test.flatMap(line => line.split(" "));
val mapreduce = flattenMap.map(word => (word, 1)).reduceByKey((a,b) => a+b);

My keys are mixed case and I would like them to be all lower case. Thank you.

zach
  • 759
  • 1
  • 9
  • 21

1 Answers1

1

I solved the problem by using the following statement on line 3:

val mapreduce = flattenMap.map(word => (word.toLowerCase, 1)).reduceByKey((a,b) => a+b);
zach
  • 759
  • 1
  • 9
  • 21