1

How to transform:

(Map(UserLang -> en, UserName -> a),1)
(Map(UserLang -> jp, UserName -> b),1)

to

 (UserLang -> en, UserName -> a)
 (UserLang -> jp, UserName -> b)

How to do this via functional programming

2 Answers 2

1

Try something like this:

val map1: Map[(String, String),Int]
val map2: Map[String, String] = map1.keySet.toMap

.keySet discards the Int and turns your Map[(String, String),Int] into a Set[(String,String)] which you can then easily convert to a Mapby calling toMap.

Sign up to request clarification or add additional context in comments.

4 Comments

I am doing this in spark using scala,your example gave me idea atleast how to proceed there,thanks :)
If you expand on your question, I can also add more details to my answer :) Then we can also help people who might encounter this problem in the future!
stackoverflow.com/questions/38333479/… after getting your pointer,I am able to seggregate wanted MAP,using below code: topCounts60.foreachRDD( rdd => { for(item <- rdd.keys.collect().toArray) { println(item); } })
Maybe you should put that into your question, or feel free to edit my answer :)
1

(Map(UserLang -> en, UserName -> a),1) is type (Map[String,String], Int) and not Map[(String,String),Int] as stated in the question title.

For the former, try map(_._1). For the latter try keys.toMap.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.