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,680 points
1,638 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,030 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 21, 2019 in Big Data Hadoop by Omkar
• 69,030 points
3,403 views
0 votes
1 answer

How to import PIG data into HBase?

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

answered Feb 14, 2019 in Big Data Hadoop by Omkar
• 69,030 points
591 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
• 51,280 points
710 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
• 51,280 points
1,284 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,030 points
1,004 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 in Apache Spark by MD
• 79,930 points
240 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
• 10,950 points
6,366 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,030 points
2,461 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,030 points
1,441 views