当前位置:网站首页>1 SparkSQL概述
1 SparkSQL概述
2022-07-17 05:09:00 【Mmj666】
1 SparkSQL概述
1.1 SparkSQL是什么
Spark SQL 是 Spark 用于结构化数据(structured data)处理的 Spark 模块。
1.2 Hive and SparkSQL
Shark出现了两个分支:SparkSQL 和 Hive on Spark
SparkSQL 作为 Spark 生态的一员继续发展,而不再受限于 Hive,只是兼容 Hive;
Hive on Spark 是一个 Hive 的发展计划,该计划将 Spark 作为 Hive 的底层引擎之一,也就是 说,Hive 将不再受限于一个引擎,可以采用 Map-Reduce、Tez、Spark 等引擎。
对于开发人员来讲,SparkSQL 可以简化 RDD 的开发,提高开发效率,且执行效率非常快,所以实际工作中,基本上采用的就是 SparkSQL。Spark SQL 为了简化 RDD 的开发, 提高开发效率,提供了 2 个编程抽象,类似 Spark Core 中的 RDD
- DataFrame
- DataSet
1.3 SparkSQL 特点
1.3.1 易整合
无缝的整合了 SQL 查询和 Spark 编程
1.3.2 统一的数据访问
使用相同的方式连接不同的数据源
1.3.3 兼容 Hive
在已有的仓库上直接运行 SQL 或者 HiveQL
1.3.4 标准数据连接
通过 JDBC 或者 ODBC 来连接
1.4 DataFrame
在 Spark 中,DataFrame 是一种以 RDD 为基础的分布式数据集,类似于传统数据库中的二维表格。
DataFrame 与 RDD 的主要区别:
- 前者带有 schema 元信息,即 DataFrame 所表示的二维表数据集的每一列都带有名称和类型。这使得 Spark SQL 得以洞察更多的结构 信息,从而对藏于 DataFrame 背后的数据源以及作用于 DataFrame 之上的变换进行了针对性的优化,最终达到大幅提升运行时效率的目标。
- RDD,由于无从得知所存数据元素的具体内部结构,Spark Core 只能在 stage 层面进行简单、通用的流水线优化。
与 Hive 类似,DataFrame 也支持嵌套数据类型(struct、array 和 map)。从 API 易用性的角度上看,DataFrame API 提供的是一套高层的关系操作,比函数式的 RDD API 要 更加友好,门槛更低。

左侧的 RDD[Person]虽然以 Person 为类型参数,但 Spark 框架本身不了解 Person 类的内 部结构。
右侧的 DataFrame 却提供了详细的结构信息,使得 Spark SQL 可以清楚地知道 该数据集中包含哪些列,每列的名称和类型各是什么。
DataFrame 是为数据提供了 Schema 的视图。可以把它当做数据库中的一张表来对待。
DataFrame 也是懒执行的,但性能上比 RDD 要高,主要原因:优化的执行计划,即查询计 划通过 Spark catalyst optimiser 进行优化。
1.5 DataSet 是什么
DataSet 是分布式数据集合。DataSet 是 Spark 1.6 中添加的一个新抽象,是 DataFrame 的一个扩展。它提供了 RDD 的优势(强类型,使用强大的 lambda 函数的能力)以及 Spark SQL 优化执行引擎的优点。DataSet 也可以使用功能性的转换(操作 map,flatMap,filter 等等)。
- DataSet 是 DataFrame API 的一个扩展,是 SparkSQL 最新的数据抽象
- 用户友好的 API 风格,既具有类型安全检查也具有 DataFrame 的查询优化特性;
- 用样例类来对 DataSet 中定义数据的结构信息,样例类中每个属性的名称直接映射到 DataSet 中的字段名称;
- DataSet 是强类型的。比如可以有 DataSet[Car],DataSet[Person];
- DataFrame 是 DataSet 的特列,DataFrame=DataSet[Row] ,所以可以通过 as 方法将 DataFrame 转换为 DataSet。Row 是一个类型,跟 Car、Person 这些的类型一样,所有的 表结构信息都用 Row 来表示。获取数据时需要指定顺序
资料来源:尚硅谷Spark 仅供学习使用
边栏推荐
- Constants and constant pointers
- What is the employment prospect of software testing? There is a large demand for talents and strong job stability
- Interviewer: how to solve the problem of a large number of requests for data that does not exist in redis, which affects the database?
- [AI] action recognition using simple neural network -- Based on coco key points
- 二叉树的先序、中序、后序遍历
- C language & bit field
- List与Map
- 3.东软跨境电商数仓项目架构设计
- Questions d'entrevue courantes du système d'exploitation
- Router loopback port experiment
猜你喜欢

Data Lakehouse的未来-开放

Solve the problem of inconsistent prediction effect between text detection training model and information model based on paddleocr

解决idea新建module 提示module xxxx does exitst

Buuctf miscellaneous - QR code

Online software testing training institutions lemon class and itest AI platform achieves strategic cooperation

Redis 源码分析-数据结构及实现(字典dict)

Face scum counter attack: thread pool lethal serial eighteen questions, the interviewer praised me straight

BUUCTF web WarmUp

Redis source code analysis - data structure and Implementation (Dictionary dict)

指针数组&数组指针
随机推荐
Some applications of special pointers
递归的应用
分布式存储-fastdfs
面试官:大量请求 Redis 不存在的数据,从而影响数据库,该如何解决?
C语言&位域
Beginner's Guide to learning penetration testing
What is the employment prospect of software testing? There is a large demand for talents and strong job stability
Cityengine 3D pipe modeling tutorial
一次全面的性能优化,从5秒优化到1秒
Teach you to reproduce log4j2 nuclear weapon level vulnerability hand in hand
Is the software testing training of lemon class reliable? This successful case of counter attack from the training class tells you
Talk about 12 business scenarios of concurrent programming
Redis source code analysis - data structure and Implementation (Dictionary dict)
A comprehensive performance optimization, from 5 seconds to 1 second
[bug solution] org apache. ibatis. type. TypeException: The alias ‘xxxx‘ is already mapped to the value ‘xxx‘
Three methods for cesium to obtain the longitude and latitude at the mouse click
From 20s to 500ms, I used these three methods
mysql - 索引
【函数的效率】
MySQL学习笔记(5)——JOIN联表查询,自连接查询,分页和排序,子查询与嵌套查询