spark的Datasets和DataFrames及其区别

本文详细介绍了Spark中的Datasets和DataFrames概念及其区别。Datasets是Spark 1.6引入的分布式数据集合,结合了RDD的强类型和lambda函数能力以及Spark SQL的优化执行。DataFrames则是组织为命名列的Datasets,类似于关系数据库的表或R/Python中的dataframe,但在底层具有更丰富的优化。两者均可从多种源构建,如结构化数据文件、Hive表、外部数据库或现有RDD。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spark的Datasets和DataFrames及其区别

A Dataset is a distributed collection of data. Dataset is a new interface added in Spark 1.6 that provides the benefits of RDDs (strong typing, ability to use powerful lambda functions) with the benefits of Spark SQL’s optimized execution engine. A Dataset can be constructed from JVM objects and then manipulated using functional transformations (map, flatMap, filter, etc.). The Dataset API is available in Scala and Java. Python does not have the support for the Dataset API. But due to Python’s dynamic nature, many of the benefits of the Dataset API are already available (i.e. you can access the field of a row by name naturally row.columnName). The case for R is similar.

Datasets是分布式数据集合。Dataset是Spark 1.6中添加的一个新接口,它提供了RDD的优势(强类型,使用强大的lambda函数的能力)以及Spark SQL优化执行引擎的优点。数据集可以从JVM对象中构造,然后使用转换函数(map,flatMap,filter等)进行操作。Datasets API在Scala和Java中可用。Python没有对Dataset API的支持。但由于Python的动态特性,Dataset API的许多好处已经可用(比如您可以通过名称自然地访问行的字段row.columnName)。 R的情况类似。

A DataFrame is a Dataset organized into named columns. It is conceptually equivalent to a table in a relational database or a data frame in R/Python, but with richer optimizations under the hood. DataFrames can be constructed from a wide array of sources such as: structured data files, tables in Hive, external databases, or existing RDDs. The DataFrame API is available in Scala, Java, Python, and R. In Scala and Java, a DataFrame is represented by a Dataset of Rows. In the Scala API, DataFrame is simply a type alias of Dataset[Row]. While, in Java API, users need to use Dataset<Row> to represent a DataFrame.

DataFrames是将Datasets一列一列地通过列名组合的集合。它在概念上等同于关系数据库中的表或R / Python中的data frame,但在相关计算引擎下具有更丰富的优化。DataFrame可以从多种来源构建,例如:结构化数据文件,Hive中的表,外部数据库或现有RDD。DataFrame API在Scala,Java,Python和R中可用。在Scala和Java中,DataFrame由行数据集表示。在Scala API中,DataFrame只是Dataset[Row]的类型别名。而在Java API中,用户需要使用数据集Dataset<Row>来表示DataFrame

参考文献:Spark SQL, DataFrames and Datasets Guide

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值