I have a path to a csv I'd like to read from. This csv includes three columns: "topic, key, value" I am using spark to read this file as a csv file. The file looks like the following(lookupFile.csv):
Topic,Key,Value
fruit,aaa,apple
fruit,bbb,orange
animal,ccc,cat
animal,ddd,dog
//I'm reading the file as follows
val lookup = SparkSession.read.option("delimeter", ",").option("header", "true").csv(lookupFile)
I'd like to take what I just read and return a map that has the following properties:
- The map uses the topic as a key
- The value of this map is a map of the "Key" and "Value" columns
My hope is that I would get a map that looks like the following:
val result = Map("fruit" -> Map("aaa" -> "apple", "bbb" -> "orange"),
"animal" -> Map("ccc" -> "cat", "ddd" -> "dog"))
Any ideas on how I can do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…