第61课:SparkSQl数据加载和保存内幕深度解密实战学习笔记

第61课:SparkSQl数据加载和保存内幕深度解密实战学习笔记

本期内容:

1 SparkSQL加载数据

2 SparkSQL保存数据

3 SparkSQL对数据处理的思考

 

操作SparkSQL主要就是操作DataFrameDataFrame提供了一些通用的LOADSAVE操作,

 

Spark版本:

大版本:主要是API变化的分支

版本:增加的特性

小版本:BUGS FIX版本
/**
 * Returns the dataset stored at path as a DataFrame,
 * using the default data source configured by spark.sql.sources.default.
 *
 *
@group genericdata
 *
@deprecated As of 1.4.0, replaced by `read().load(path)`. This will be removed in Spark 2.0.
 */
@deprecated("Use read.load(path). This will be removed in Spark 2.0.", "1.4.0")
def load(path: String): DataFrame = {
  read.load(path)
}

 

DataFrameReader:

* :: Experimental ::
* Interface used to load a
[[DataFrame]] from external storage systems (e.g. file systems,
* key-value stores, etc). Use
[[SQLContext.read]] to access this.

DataFrameReader中有format方法:

  /**

   * Specifies the input data source format.

   *

   * @since 1.4.0

   */

  def format(source: String): DataFrameReader = {

    this.source = source

    this

  }

读取数据时可以直接指定读取数据的文件类型,如JSONParquet

  /**

   * Specifies the input schema. Some data sources (e.g. JSON) can infer the input schema

   * automatically from data. By specifying the schema here, the underlying data source can

   * skip the schema inference step, and thus speed up data loading.

   *

   * @since 1.4.0

   */

  def schema(schema: StructType): DataFrameReader = {

    this.userSpecifiedSchema = Option(schema)

    this

  }

 

  /**

   * Loads input in as a [[DataFrame]], for data sources that require a path (e.g. data backed by

   * a local or distributed file system).

   *

   * @since 1.4.0

   */

  // TODO: Remove this one in Spark 2.0.

  def load(path: String): DataFrame = {

    option("path", path).load()

  }

 

  /**

   * Loads input in as a [[DataFrame]], for data sources that don't require a path (e.g. external

   * key-value stores).

   *

   *

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值