How to export data from Spark SQL to CSV

前端 未结 7 1244
迷失自我
迷失自我 2020-12-04 15:31

This command works with HiveQL:

insert overwrite directory \'/data/home.csv\' select * from testtable;

But with Spark SQL I\'m getting an e

7条回答
  •  醉梦人生
    2020-12-04 16:09

    With the help of spark-csv we can write to a CSV file.

    val dfsql = sqlContext.sql("select * from tablename")
    dfsql.write.format("com.databricks.spark.csv").option("header","true").save("output.csv")`
    

提交回复
热议问题