SCALA : Use Cases for extracting particular values from Array -


 var word_count = rdd.flatmap(lines=>lines.split(",").map(words=>(words,1)).reducebykey(_+_).collect word_count:array[(string,int)] = array((ankita,1),(shelly,1),(a,2),(b,1)) 

//now writing below query results in empty string want extract (a,2) , (b,1) .

var filtered = word_count.filter(values=>(values=="a") || (values=="b")).collect  filtered:array[(string,int)] = array() 

it should be:

word_count.filter(x => (x._1 == "a") || (x._1 == "b")) 

or

word_count.filter(x => seq("a", "b").contains(x._1)) 

your code compares tuple2 string giving trivially false expression:

scala> ("a", 1) == "a" <console>:24: warning: comparing values of types (string, int) , string using `==' yield false        ("a", 1) == "a"             ^ res0: boolean = false 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -