I am writing a Scala Spark script where I am storing (Hive partitions) HDFS paths as keys and their underlying file count as values. I want to write a for loop to check if the filepath exists (using key) and count is greater than 0. I have to reverse the whole map because I want to start checking for latest partition.
I couldn't find any method to reverse the map and loop through it. Here's my code:
val paths = collection.mutable.Map[String, Float]()
status.foreach( x => paths += (x.getPath.toString -> fs.getContentSummary(new Path(x.getPath.toString).getFileCount() )
This is what I am planning to do :
//Reverse the map to make last element as first element
var result = ""
for ((k,v) <- paths) {
if(!fs.exists(new Path(k)) && v < 1)
continue
else
result = k
break
}