Small code organization suggestion -- factor this into spark.Utils because you have another copy of this method in HadoopMapReduceUtil