Issue with writing DF to textFile - Text Data supports only single column

Hi Everyone,

I was working on CCA problem 7 and I was trying to write the output of DF to a textfile as mentioned below

outdf.write.option(“sep”,":").text("/user/krish/problem7/solutionastxt")

I faced the following issue

Traceback (most recent call last):
pyspark.sql.utils.AnalysisException: u’Text data source supports only a single column, and you have 4 columns.;'

Were any one able to convert df to textfile . Appreciate your response

Regards,
K

1 Like

This is a method to do it.
val res=df.coalesce(1).rdd
res.map(x=>x.getString(0)).saveAsTextFile(“user/ansh1307/spark_practice/problem5/data/untraded_stocks”)

but when asked to save a text file you can use csv file format