I recently wanted to know how to save a HashMap
to file and later read it back. The user Carrie posted a similar question, but the accepted top answer can't be correct. Since I don't have enough reputation to comment that answer, I'm explaining one way to do this, in case someone has the same question.
Question
I have a lookup map for a custom hash function where Integers are mapped to Sets of (hash: Int, value: String)
tuples.
val lookupMap: Map[Int, Set[(Int, String)]] = ... // filling this map is a different story
I want to save this Map to a file and later read it bas as a map. This answer suggests to use sc.textFile("...").collectAsMap
, but that doesn't work, because textFile
returns RDD[String]
.