Fix NPE in MapReduceStage and store result in cache

If the MapReduceTask fails, then it returns null. Check for this before
trying to check the size of the Map. Store the Map or the collated
object in the cache.
Make result key accessible