I am joining two data frame in spark using scala . My code looks very ugly because of the multiple when condition . Can somebody please help me refracting my code . Here is my existing code . val columnsNameArray=schema.fieldNames All columns name are from the array columnsNameArray and in same sequence except val dfMainOutputRead more