How to save a spark DataFrame as csv on disk?

后端 未结 4 2021
你的背包
你的背包 2020-11-29 03:05

For example, the result of this:

df.filter(\"project = \'en\'\").select(\"title\",\"count\").groupBy(\"title\").sum()

would return an Array

4条回答
  •  心在旅途
    2020-11-29 03:37

    Writing dataframe to disk as csv is similar read from csv. If you want your result as one file, you can use coalesce.

    df.coalesce(1)
          .write
          .option("header","true")
          .option("sep",",")
          .mode("overwrite")
          .csv("output/path")
    

    If your result is an array you should use language specific solution, not spark dataframe api. Because all these kind of results return driver machine.

提交回复
热议问题