Это решит вашу проблему -
val df = Seq(
("a", 2, "c"),
("a", 2, "c"),
("a", 2, "c"),
("b", 2, "d"),
("b", 2, "d")
).toDF("col1", "col2", "col3")
df.repartition(5).map((row)=>row.toString())
.write.mode(SaveMode.Append)
.text("/Users/sokale/models/x")
/**
* [a,2,c]
* [b,2,d]
*/
df.repartition(5).select(concat_ws(",", df.columns.map(col): _*))
.write.mode(SaveMode.Append)
.text("/Users/sokale/models/x2")
/**
* a,2,c
* b,2,d
*/
edit-1 (на основе комментария)
Используйте десятичное число для всех управляющих символов
df.repartition(5).select(concat_ws("\001", df.columns.map(col): _*))
.write.mode(SaveMode.Append)
.text("/Users/sokale/models/x2")