How to convert Spark data into CSV

0 votes
I have a Spark Sql. I wanted to know how to convert this to a csv data. Or maybe export the Spark sql into a csv file. How can I do this?
Nov 21, 2018 in Big Data Hadoop by digger
• 26,740 points
4,492 views

1 answer to this question.

0 votes

You can use this:

df.write
  .option("header", "true")
  .csv("<path to the directory>/out.csv")

You can also convert the whole data frame like this:

df.coalesce(1).write
    .format("com.databricks.spark.csv")
    .option("header", "true")
    .save("<path to the directory>/out.csv")
answered Nov 21, 2018 by Omkar
• 69,220 points

I am getting a huge error when I use this. Are there any libraries to be imported?

df.write
  .option("header", "true")
  .csv("<path to the directory>/out.csv")
Can you share your error? It will help to solve the problem.

Related Questions In Big Data Hadoop

0 votes
1 answer

Spark.read.csv to create RDD into Dataframe

You can use a case class and ...READ MORE

answered Jan 22, 2019 in Big Data Hadoop by Omkar
• 69,220 points
5,858 views
0 votes
1 answer

How to import PIG data into HBase?

Follow the below steps to do it: # ...READ MORE

answered Feb 15, 2019 in Big Data Hadoop by Omkar
• 69,220 points
1,882 views
0 votes
1 answer

How to load data from HDFS into pig relation?

Hey, To load data from HDFS to pig ...READ MORE

answered May 7, 2019 in Big Data Hadoop by Gitika
• 65,770 points
3,252 views
0 votes
1 answer

How to load data from flat files into Hive?

Hey, You can load data from flat files ...READ MORE

answered Jun 26, 2019 in Big Data Hadoop by Gitika
• 65,770 points
3,441 views
+1 vote
2 answers
0 votes
1 answer

How to find the number of null contain in dataframe?

Hey there! You can use the select method of the ...READ MORE

answered May 3, 2019 in Apache Spark by Omkar
• 69,220 points
5,092 views
0 votes
1 answer

How to insert data into Cassandra table using Spark DataFrame?

Hi@akhtar, You can write the spark dataframe in ...READ MORE

answered Sep 21, 2020 in Apache Spark by MD
• 95,460 points
3,907 views
+1 vote
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 11,380 points
11,033 views
0 votes
1 answer

Hadoop Hive: How to convert multiple rows into comma separated values?

You can use the aggregator function collect_set to do ...READ MORE

answered Nov 14, 2018 in Big Data Hadoop by Omkar
• 69,220 points
5,426 views
0 votes
1 answer

Hadoop Hive Hbase: How to insert data into Hbase using Hive (JSON file)?

You can use the get_json_object function to parse the ...READ MORE

answered Nov 15, 2018 in Big Data Hadoop by Omkar
• 69,220 points
2,934 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP