从0开始学习pyspark--pyspark的核心概念[第0节]

在学习 PySpark时会遇到很多新的关键词,理解这些概念,对我们学习PySpark有极大的帮助,以下是一些PySpark的关键概念及其详细解释:

1. PySpark

PySparkApache Spark的Python API。Spark是一个用于大规模数据处理的开源分布式计算系统,支持内存计算和基于磁盘的数据处理,具有高性能和可扩展性。

2. SparkContext (SC)

SparkContext是所有Spark功能的入口点。它是Spark应用的主控对象,用于连接到集群并创建RDD(Resilient Distributed Datasets)。

3. Resilient Distributed Dataset (RDD)

RDDSpark的核心抽象,是一个不可变的分布式数据集合。RDD支持两种操作:Transformations(如map, filter)和Actions(如count, collect)。

4. DataFrame

DataFrameSpark SQL中的一个分布式数据集合,类似于PandasDataFrameDataFrame有更高层次的抽象,相比于RDD提供了更多优化和更简单的API

5. Spark SQL

Spark SQLSpark中处理结构化数据的组件,允许你使用SQL查询DataFrameRDD。它还支持从多种数据源读取数据,如JSONParquetJDBC等。

6. SparkSession

SparkSession是用于与Spark交互的新的入口点,它整合了SparkContextSQLContextHiveContext的功能。你可以通过SparkSession创建DataFrame和执行SQL查询。

from pyspark.sql import SparkSession

spark = SparkSession.builder \
    .appName("example") \
    .getOrCreate()

7. Transformations

Transformations是对RDD的惰性操作(lazy operations),即不会立即计算结果,而是生成一个新的RDD。当需要执行一个Action时,Spark才会开始计算。常见的Transformations包括:

  • map(func): 对RDD中的每个元素应用函数func,并返回一个新的RDD
  • filter(func): 保留RDD中使函数func返回True的元素,返回一个新的RDD
  • flatMap(func): 类似于map,但每个输入元素可以映射到0个或多个输出元素。

8. Actions

Actions是对RDD的操作,会触发计算并返回结果。常见的Actions包括:

  • collect(): 返回RDD中所有元素的列表。
  • count(): 返回RDD中元素的个数。
  • first(): 返回RDD中的第一个元素。

9. Lazy Evaluation

PySpark使用惰性求值(Lazy Evaluation),即Transformations不会立即执行,而是记录下需要进行的操作。当执行一个Action时,Spark会根据需要生成执行计划并优化执行。

10. Spark SQL and DataFrames

Spark SQL支持通过SQL语句查询数据,并且可以与DataFrame API无缝集成。

df = spark.read.json("example.json")
df.createOrReplaceTempView("example")
result = spark.sql("SELECT * FROM example WHERE age > 21")

11. Spark Streaming

Spark Streaming用于实时处理数据流,支持从多种数据源读取数据,如KafkaFlumeKinesis等。它将实时数据流分成小批次进行处理,并提供类似于RDD的API。

12. Machine Learning Library (MLlib)

MLlibSpark的机器学习库,提供了多种机器学习算法和工具,如分类、回归、聚类、协同过滤等。

13. GraphX

GraphXSpark的图计算库,提供了图算法和图操作的API,用于处理大规模图数据。

14. Spark的集群模式

Spark支持多种集群模式,包括本地模式Standalone模式YARN模式Mesos模式。不同的模式适用于不同的应用场景和集群配置。

About This Book, Learn why and how you can efficiently use Python to process data and build machine learning models in Apache Spark 2.0Develop and deploy efficient, scalable real-time Spark solutionsTake your understanding of using Spark with Python to the next level with this jump start guide, Who This Book Is For, If you are a Python developer who wants to learn about the Apache Spark 2.0 ecosystem, this book is for you. A firm understanding of Python is expected to get the best out of the book. Familiarity with Spark would be useful, but is not mandatory., What You Will Learn, Learn about Apache Spark and the Spark 2.0 architectureBuild and interact with Spark DataFrames using Spark SQLLearn how to solve graph and deep learning problems using GraphFrames and TensorFrames respectivelyRead, transform, and understand data and use it to train machine learning modelsBuild machine learning models with MLlib and MLLearn how to submit your applications programmatically using spark-submitDeploy locally built applications to a cluster, In Detail, Apache Spark is an open source framework for efficient cluster computing with a strong interface for data parallelism and fault tolerance. This book will show you how to leverage the power of Python and put it to use in the Spark ecosystem. You will start by getting a firm understanding of the Spark 2.0 architecture and how to set up a Python environment for Spark., You will get familiar with the modules available in PySpark. You will learn how to abstract data with RDDs and DataFrames and understand the streaming capabilities of PySpark. Also, you will get a thorough overview of machine learning capabilities of PySpark using ML and MLlib, graph processing using GraphFrames, and polyglot persistence using Blaze. Finally, you will learn how to deploy your applications to the cloud using the spark-submit command., By the end of this book, you will have established a firm understanding of the Spark Python API and how it can be used t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sssugarr

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值