sparksql中保存数据的⼏种⽅式从官⽹来copy过来的⼏种模式描述:
Scala/Java Python Meaning
SaveMode.ErrorIfExists(default)"error"(default)When saving a DataFrame to a data source, if data already exists, an exception is expected to be thrown.
一个护士的故事SaveMode.Append"append"When saving a DataFrame to a data source, if data/table already exists, contents of the DataFrame are expected to be appended to existing data.袅袅的意思
SaveMode.Overwrite"overwrite"Overwrite mode means that when saving a DataFrame to a data source, if data/table already exists, existing data is expected to be overwritten by the contents of the DataFrame.
SaveMode.Ignore"ignore"Ignore mode means that when saving a DataFrame to a data source, if data already exists, the save operation is expected to not save the contents of the DataFrame and to not change the existing data. This is similar to a `CREATE TABLE IF NOT EXISTS` in SQL.
ErrorIfExists就是出现错误后,抛出错误
小鸟的家教案
Append顾名思义,就是追加信息
活动运营
春的拼音怎么写
内存清理Overwrite是覆盖
Ignore是如果存在则忽略节后上班第一天
火电影
另外,如果没有指定存储模式,那么默认应该是SaveMode.ErrorIfExists,因为我重复保存后报了:already exists错误来着。
如何使⽤:
import org.apache.spark.sql._
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
val df = sqlContext.load("/opt/modules/spark1.3.1/examples/src/main/resources/people.json")
df.save("/opt/test/1","json", SaveMode.Overwrite) //可以把SaveMode.Overwrite换成其他的⼏种形式喽