sparksql 保存点_spark sql中保存数据的几种方式

从官网来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换成其他的几种形式喽

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值