Higher order connection MapReduce job written in Spark