Digital Library
Data Algorithms with Spark Recipes and Design Patterns for Scaling Up using PySpark (Mahmoud Parsian)(Z-Library)
Data Algorithms with Spark Recipes and Design Patterns for Scaling Up using PySpark (Mahmoud Parsian)(Z-Library)
algorithm
No Description
19
Views
0
Downloads
0.00
Total Donations
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
DATA “This book is a great resource for both readers looking to implement existing algorithms in a scalable fashion and readers who are developing new, custom algorithms using Spark.” —Matei Zaharia Asst. Professor of Computer Science, Stanford; Chief Technologist, Databricks; Original Creator of Apache Spark Data Algorithms with Spark ISBN: 978-1-492-08238-5 US $69.99 CAN $87.99 Twitter: @oreillymedia linkedin.com/company/oreilly-media youtube.com/oreillymedia Apache Spark’s speed, ease of use, sophisticated analytics, and multilanguage support makes practical knowledge of this cluster-computing framework a required skill for data engineers and data scientists. With this hands-on guide, anyone looking for an introduction to Spark will learn practical algorithms and examples using PySpark. In each chapter, author Mahmoud Parsian shows you how to solve a data problem with a set of Spark transformations and algorithms. You’ll learn how to tackle problems involving ETL, design patterns, machine learning algorithms, data partitioning, and genomics analysis. Each detailed recipe includes PySpark algorithms using the PySpark driver and shell script. With this book, you will: • Learn how to select Spark transformations for optimized solutions • Explore powerful transformations and reductions including reduceByKey(), combineByKey(), and mapPartitions() • Understand data partitioning for optimized queries • Build and apply a model using PySpark design patterns • Apply motif-finding algorithms to graph data • Analyze graph data by using the GraphFrames API • Apply PySpark algorithms to clinical and genomics data • Learn how to use and apply feature engineering in ML algorithms • Understand and use practical data design patterns Mahmoud Parsian, PhD in computer science, is a practicing software professional with 30 years of experience as a developer, designer, architect, and author. Over the past 15 years, he’s been involved in Java server-side computing, databases, MapReduce, Spark, PySpark, and distributed computing. Dr. Parsian leads Illumina’s Big Data team, which focuses on large-scale genome analytics and distributed computing using Spark and PySpark. Dr. Parsian also teaches machine learning and big data modeling and analytics at Santa Clara University.
Page
3
Mahmoud Parsian Data Algorithms with Spark Recipes and Design Patterns for Scaling Up Using PySpark Boston Farnham Sebastopol TokyoBeijing
Page
4
978-1-492-08238-5 [LSI] Data Algorithms with Spark by Mahmoud Parsian Copyright © 2022 Mahmoud Parsian. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Jessica Haberman Development Editor: Melissa Potter Production Editor: Christopher Faucher Copyeditor: Rachel Head Proofreader: Justin Billing Indexer: Potomac Indexing, LLC Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea April 2022: First Edition Revision History for the First Edition 2022-04-08: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781492082385 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Data Algorithms with Spark, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Page
5
This book is dedicated to my family: Behnaz, Maral, and Yaseen parents: Bagher and Monireh brother: Ahmad sister: Nayerazam
Page
6
(This page has no text content)
Page
7
Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Part I. Fundamentals 1. Introduction to Spark and PySpark. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Why Spark for Data Analytics 2 The Spark Ecosystem 5 Spark Architecture 6 The Power of PySpark 12 PySpark Architecture 15 Spark Data Abstractions 17 RDD Examples 17 Spark RDD Operations 18 DataFrame Examples 21 Using the PySpark Shell 24 Launching the PySpark Shell 25 Creating an RDD from a Collection 26 Aggregating and Merging Values of Keys 26 Filtering an RDD’s Elements 28 Grouping Similar Keys 28 Aggregating Values for Similar Keys 29 ETL Example with DataFrames 30 Extraction 31 Transformation 32 Loading 33 v
Page
8
Summary 33 2. Transformations in Action. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 The DNA Base Count Example 36 The DNA Base Count Problem 38 FASTA Format 39 Sample Data 39 DNA Base Count Solution 1 40 Step 1: Create an RDD[String] from the Input 41 Step 2: Define a Mapper Function 42 Step 3: Find the Frequencies of DNA Letters 44 Pros and Cons of Solution 1 47 DNA Base Count Solution 2 47 Step 1: Create an RDD[String] from the Input 49 Step 2: Define a Mapper Function 49 Step 3: Find the Frequencies of DNA Letters 51 Pros and Cons of Solution 2 52 DNA Base Count Solution 3 52 The mapPartitions() Transformation 52 Step 1: Create an RDD[String] from the Input 60 Step 2: Define a Function to Handle a Partition 60 Step 3: Apply the Custom Function to Each Partition 62 Pros and Cons of Solution 3 64 Summary 64 3. Mapper Transformations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Data Abstractions and Mappers 65 What Are Transformations? 67 Lazy Transformations 72 The map() Transformation 73 DataFrame Mapper 78 The flatMap() Transformation 80 map() Versus flatMap() 85 Apply flatMap() to a DataFrame 86 The mapValues() Transformation 89 The flatMapValues() Transformation 90 The mapPartitions() Transformation 91 Handling Empty Partitions 95 Benefits and Drawbacks 98 DataFrames and mapPartitions() Transformation 99 Summary 102 vi | Table of Contents
Page
9
4. Reductions in Spark. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Creating Pair RDDs 104 Reduction Transformations 105 Spark’s Reductions 108 Simple Warmup Example 110 Solving with reduceByKey() 111 Solving with groupByKey() 112 Solving with aggregateByKey() 112 Solving with combineByKey() 113 What Is a Monoid? 115 Monoid and Non-Monoid Examples 117 The Movie Problem 118 Input Dataset to Analyze 121 The aggregateByKey() Transformation 122 First Solution Using aggregateByKey() 124 Second Solution Using aggregateByKey() 127 Complete PySpark Solution Using groupByKey() 129 Complete PySpark Solution Using reduceByKey() 131 Complete PySpark Solution Using combineByKey() 134 The Shuffle Step in Reductions 137 Shuffle Step for groupByKey() 138 Shuffle Step for reduceByKey() 139 Summary 140 Part II. Working with Data 5. Partitioning Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Introduction to Partitions 146 Partitions in Spark 146 Managing Partitions 150 Default Partitioning 151 Explicit Partitioning 152 Physical Partitioning for SQL Queries 153 Physical Partitioning of Data in Spark 156 Partition as Text Format 156 Partition as Parquet Format 157 How to Query Partitioned Data 158 Amazon Athena Example 158 Summary 160 Table of Contents | vii
Page
10
6. Graph Algorithms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Introduction to Graphs 162 The GraphFrames API 164 How to Use GraphFrames 165 GraphFrames Functions and Attributes 168 GraphFrames Algorithms 169 Finding Triangles 169 Motif Finding 172 Real-World Applications 181 Gene Analysis 181 Social Recommendations 183 Facebook Circles 187 Connected Components 191 Analyzing Flight Data 193 Summary 202 7. Interacting with External Data Sources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Relational Databases 204 Reading from a Database 205 Writing a DataFrame to a Database 213 Reading Text Files 218 Reading and Writing CSV Files 220 Reading CSV Files 220 Writing CSV Files 224 Reading and Writing JSON Files 225 Reading JSON Files 226 Writing JSON Files 227 Reading from and Writing to Amazon S3 228 Reading from Amazon S3 229 Writing to Amazon S3 231 Reading and Writing Hadoop Files 232 Reading Hadoop Text Files 233 Writing Hadoop Text Files 236 Reading and Writing HDFS SequenceFiles 238 Reading and Writing Parquet Files 239 Writing Parquet Files 239 Reading Parquet Files 241 Reading and Writing Avro Files 242 Reading Avro Files 242 Writing Avro Files 242 Reading from and Writing to MS SQL Server 243 Writing to MS SQL Server 243 viii | Table of Contents
Page
11
Reading from MS SQL Server 244 Reading Image Files 244 Creating a DataFrame from Images 244 Summary 246 8. Ranking Algorithms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Rank Product 248 Calculation of the Rank Product 249 Formalizing Rank Product 249 Rank Product Example 250 PySpark Solution 251 PageRank 257 PageRank’s Iterative Computation 259 Custom PageRank in PySpark Using RDDs 261 Custom PageRank in PySpark Using an Adjacency Matrix 263 PageRank with GraphFrames 266 Summary 267 Part III. Data Design Patterns 9. Classic Data Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Input-Map-Output 272 RDD Solution 272 DataFrame Solution 275 Flat Mapper functionality 277 Input-Filter-Output 278 RDD Solution 279 DataFrame Solution 280 DataFrame Filter 280 Input-Map-Reduce-Output 282 RDD Solution 282 DataFrame Solution 285 Input-Multiple-Maps-Reduce-Output 287 RDD Solution 288 DataFrame Solution 290 Input-Map-Combiner-Reduce-Output 291 Input-MapPartitions-Reduce-Output 294 Inverted Index 298 Problem Statement 298 Input 298 Output 299 Table of Contents | ix
Page
12
PySpark Solution 299 Summary 302 10. Practical Data Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 In-Mapper Combining 304 Basic MapReduce Algorithm 305 In-Mapper Combining per Record 307 In-Mapper Combining per Partition 309 Top-10 312 Top-N Formalized 314 PySpark Solution 316 Finding the Bottom 10 318 MinMax 319 Solution 1: Classic MapReduce 319 Solution 2: Sorting 319 Solution 3: Spark’s mapPartitions() 320 The Composite Pattern and Monoids 323 Monoids 324 Monoidal and Non-Monoidal Examples 328 Non-Monoid MapReduce Example 331 Monoid MapReduce Example 332 PySpark Implementation of Monoidal Mean 334 Functors and Monoids 336 Conclusion on Using Monoids 338 Binning 338 Sorting 342 Summary 342 11. Join Design Patterns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 Introduction to the Join Operation 345 Join in MapReduce 348 Map Phase 348 Reducer Phase 349 Implementation in PySpark 350 Map-Side Join Using RDDs 351 Map-Side Join Using DataFrames 355 Step 1: Create Cache for Airports 357 Step 2: Create Cache for Airlines 357 Step 3: Create Facts Table 358 Step 4: Apply Map-Side Join 358 Efficient Joins Using Bloom Filters 359 Introduction to Bloom Filters 359 x | Table of Contents
Page
13
A Simple Bloom Filter Example 361 Bloom Filters in Python 362 Using Bloom Filters in PySpark 362 Summary 363 12. Feature Engineering in PySpark. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 Introduction to Feature Engineering 366 Adding New Features 368 Applying UDFs 369 Creating Pipelines 370 Binarizing Data 372 Imputation 373 Tokenization 375 Tokenizer 376 RegexTokenizer 376 Tokenization with a Pipeline 377 Standardization 377 Normalization 380 Scaling a Column Using a Pipeline 382 Using MinMaxScaler on Multiple Columns 383 Normalization Using Normalizer 384 String Indexing 385 Applying StringIndexer to a Single Column 385 Applying StringIndexer to Several Columns 386 Vector Assembly 386 Bucketing 387 Bucketizer 388 QuantileDiscretizer 389 Logarithm Transformation 390 One-Hot Encoding 391 TF-IDF 397 FeatureHasher 401 SQLTransformer 402 Summary 403 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 Table of Contents | xi
Page
14
(This page has no text content)
Page
15
Foreword When I started the Apache Spark project a decade ago, one of my main goals was to make it easier for a wide range of users to implement parallel algorithms. New algo‐ rithms acting on large-scale data are having a profound impact in all areas of comput‐ ing, and I wanted to help developers implement such algorithms and reason about their performance without having to build a distributed system from scratch. I am therefore very excited to see this new book by Dr. Mahmoud Parsian on data algorithms with Spark. Dr. Parsian has extensive research and practical experience with large-scale data-parallel algorithms, including developing new algorithms for bioinformatics as the lead of Illumina’s big data team. In this book, he introduces Spark through its Python API, PySpark, and shows how to implement a wide range of useful algorithms efficiently using Spark’s distributed computing primitives. He also explains the workings of the underlying Spark engine and how to optimize your algo‐ rithms through techniques such as controlling data partitioning. This book will be a great resource for both readers looking to implement existing algorithms in a scalable fashion and readers who are developing new, custom algorithms using Spark. I am also thrilled that Dr. Parsian has included working code examples for all the algorithms he discusses, using real-world problems where possible. These will serve as a great starting point for readers who want to implement similar computations. Whether you intend to use these algorithms directly or build your own custom algo‐ rithms using Spark, I hope that you enjoy this book as an introduction to the open source engine, its inner workings, and the modern parallel algorithms that are having such a broad impact across computing. — Matei Zaharia Assistant Professor of Computer Science, Stanford Chief Technologist, Databricks Original Creator of Apache Spark xiii
Page
16
(This page has no text content)
Page
17
Preface Spark has become the de facto standard for large-scale data analytics. I have been using and teaching Spark since its inception nine years ago, and I have seen tremen‐ dous improvements in Extract, Transform, Load (ETL) processes, distributed algo‐ rithm development, and large-scale data analytics. I started using Spark with Java, but I found that while the code is pretty stable, you have to write long lines of code, which can become unreadable. For this book, I decided to use PySpark (a Python API for Spark) because it is easier to express the power of Spark in Python: the code is short, readable, and maintainable. PySpark is powerful but simple to use, and you can express any ETL or distributed algorithm in it with a simple set of transformations and actions. Why I Wrote This Book This is an introductory book about data analysis using PySpark. The book consists of a set of guidelines and examples intended to help software and data engineers solve data problems in the simplest possible way. As you know, there are many ways to solve any data problem: PySpark enables us to write simple code for complex prob‐ lems. This is the motto I have tried to express in this book: keep it simple and use parameters so that your solution can be reused by other developers. My aim is to teach readers how to think about data and understand its origins and final intended form, as well as showing how to use fundamental data transformation patterns to solve a variety of data problems. Who This Book Is For To use this book effectively it will be helpful to know the basics of the Python pro‐ gramming language, such as how to use conditionals (if-then-else), iterate through lists, and define and call functions. However, if your background is in another pro‐ gramming language (such as Java or Scala) and you do not know Python, you will still xv
Page
18
be able to use the book as I have provided a reasonable introduction to Spark and PySpark. This book is primarily intended for people who want to analyze large amounts of data and develop distributed algorithms using the Spark engine and PySpark. I have pro‐ vided simple examples showing how to perform ETL operations and write distributed algorithms in PySpark. The code examples are written in such a way that you can cut and paste them to get the job done easily. The sample code provided on GitHub is a great resource to get you started with your own data projects. How This Book Is Organized The book consists of 12 chapters, organized into three parts: Part I, “Fundamentals” The first four chapters cover the fundamentals of Spark and PySpark and intro‐ duce data transformations such as mappers, filters, and reducers. They contain many practical examples to get you started on your own PySpark projects. Approximately 95% of all data problems can be tackled by using simple PySpark data transformations (such as map(), flatMap(), filter(), and reduceByKey()) introduced in the first four chapters of this book. Here’s a closer look at what you’ll find here: • Chapter 1, “Introduction to Spark and PySpark”, provides a high-level over‐ view of data algorithms and introduces the use of Spark and PySpark for solving data analytics problems. • Chapter 2, “Transformations in Action”, shows how to use Spark transforma‐ tions (mappers, filters, and reducers) to solve real data problems. • Chapter 3, “Mapper Transformations”, introduces the most frequently used mapper transformations: map(), filter(), flatMap(), and mapParti tions(). • Chapter 4, “Reductions in Spark”, focuses on reduction transformations (such as reduceByKey(), groupByKey(), and combineByKey()), which play a very important role in grouping data by keys. Many simple but useful exam‐ ples are given to make sure that you’ll be able to use these reductions effectively. xvi | Preface
Page
19
Part II, “Working with Data” The next four chapters cover partitioning data, graph algorithms, reading/writing data from/to many different data sources, and ranking algorithms: • Chapter 5, “Partitioning Data”, presents functions to physically partition data on specific data columns. This partitioning will enable your SQL queries (e.g., in Amazon Athena or Google BigQuery) to analyze a slice of the data rather than the whole dataset, which will improve query performance. • Chapter 6, “Graph Algorithms”, introduces one of the most important exter‐ nal Spark packages, GraphFrames, which can be used to analyze large graphs in Spark’s distributed environment. • Chapter 7, “Interacting with External Data Sources”, shows you how to read data from and write it to a variety of data sources. • Chapter 8, “Ranking Algorithms”, presents two important ranking algo‐ rithms, PageRank (used in search engines) and rank product (used in gene analysis). Part III, “Data Design Patterns” The final four chapters cover practical data design patterns, which are presented in an informal way with solid examples: • Chapter 9, “Classic Data Design Patterns”, introduces a selection of funda‐ mental data design patterns, or reusable solutions, that are commonly used to solve a variety of data problems. Examples include Input-Map-Output and Input-Filter-Output. • Chapter 10, “Practical Data Design Patterns”, introduces common and prac‐ tical data design patterns, for tasks such as combining, summarizing, filter‐ ing, and organizing data. These patterns are presented informally, with practical examples. • Chapter 11, “Join Design Patterns”, presents simple patterns for joining two or more datasets; some performance criteria are discussed to improve the efficiency of join algorithms. • Chapter 12, “Feature Engineering in PySpark”, presents the most common feature engineering techniques used in developing machine learning algorithms. Bonus Chapters Since I did not want to make this book too bulky, I have included additional material on topics such as TF-IDF, correlation, and k-mers as bonus chapters in the book’s GitHub repository. Preface | xvii
Page
20
Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/mahmoudparsian/data-algorithms-with-spark. If you have a technical question or a problem using the code examples, please send email to mahmoud.parsian@yahoo.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not xviii | Preface
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
【One-Line Pitch】
A practical cookbook for data engineers and scientists who want to master PySpark's core transformations and design patterns to scale data algorithms from single-machine prototypes to distributed cluster processing.
【Book Arc】
- **Opening (~0%–10%)**: Introduces Spark's architecture—driver, workers, cluster managers—and the PySpark API, establishing the mental model of distributed computing with RDDs and DataFrames.
- **Early (~10%–23%)**: Dives into the DNA Base Count problem as the first worked example, showing three different PySpark solutions that produce identical results but with different performance characteristics.
- **Early (~23%–32%)**: Explores mapper transformations in depth, covering map(), flatMap(), and mapValues(), with emphasis on when to use mapPartitions() for heavyweight initialization like database connections.
- **Middle (~39%–48%)**: Details the mechanics of map() and flatMap() with concrete examples, including DataFrame operations like explode() for array columns, and handling empty partitions.
- **Middle (~48%–52%)**: Shifts to reduction transformations—reduceByKey(), combineByKey(), groupByKey(), aggregateByKey()—for aggregating values in (key, value) pair RDDs.
【Key Takeaways】
- **Spark's architecture is the foundation** (Opening): Understanding the driver-worker-cluster manager model explains why RDDs are immutable, distributed, and read-only—and why collect() on large RDDs risks OOM exceptions. Use take() or takeSample() for debugging instead.
- **Multiple solutions exist for the same problem** (Early): The DNA Base Count example demonstrates three distinct PySpark implementations using different transformations, proving that performance varies significantly based on transformation choice even when outputs match.
- **mapPartitions() is for expensive initialization** (Early): Creating database connections or external library objects per element kills scalability; doing it once per partition via mapPartitions() is the correct pattern for heavyweight setup.
- **map() is 1-to-1, flatMap() is 1-to-many** (Middle): map() preserves element count while flatMap() flattens iterable results, allowing source and target RDDs to differ in size—critical for tokenization and record expansion.
- **reduceByKey() beats groupByKey() for aggregation** (Middle): For summing values per key, reduceByKey() is more efficient because it combines values locally before shuffling, while groupByKey() moves all data across the network first.
- **DataFrame explode() handles array columns** (Middle): When working with structured data containing array fields, explode() transforms each array element into a separate row, enabling row-level operations on nested data.
- **Empty partitions require explicit handling** (Middle): When writing custom partition functions, check for StopIteration to handle empty iterators gracefully, preventing crashes in production pipelines.
【Reading Tips】
- **Skim the architecture overview** (~0%–10%): If you already know Spark basics, jump ahead; the cluster manager details matter more for deployment than for algorithm design.
- **Deep-read the DNA Base Count chapter** (~19%–32%): This is the book's core teaching example—study all three solutions to internalize how transformation choice affects performance.
- **Focus on the mapper transformation tables** (~32%–48%): The comparison of map(), flatMap(), mapValues() with their 1-to-1 vs 1-to-many relationships is the most reusable reference material.
- **Pay special attention to mapPartitions()** (~29%–32%): This pattern appears repeatedly in real-world Spark jobs; understand the iterator-based function signature and empty partition handling.
- **Take away the reduction transformation cheat sheet** (~48%–52%): The *ByKey() family (reduceByKey, combineByKey, groupByKey, aggregateByKey) is essential for any aggregation task; note when each is appropriate.
【Coverage Limits】
Excerpts cover roughly the first half of the book (through Chapter 4 on reductions); later chapters on advanced algorithms, machine learning, and performance tuning are not represented in this guide.
Passage locations
Excerpt 1
52 DNA Base Count Solution 3 52 The mapPartitions() Transformation 52 Step 1: Create an RDD[String] from the Input 60 Step 2: Define a Function to Handle a P...
View in text
Excerpt 2
, filter(), flatMap(), or foreach(func). DataFrame Examples Similar to an RDD, a DataFrame in Spark is an immutable distributed collection of data. But unlik...
View in text
Excerpt 3
#end-for connection.close() # close db connection here u = <prepare object of type U from data_structures> return u #end-def The partition parameter is an it...
View in text
Excerpt 4
|max |FORTRAN |[] | Note that the names ted and dan were dropped since the exploded column value was an empty list. Next, we explode the education column: >>...
View in text
Support Author
0.00
Total Amount (¥)
0
Donation Count
Please enter an amount
Minimum ¥1
You will be redirected to Alipay to complete payment, then return here.
Order created — please complete Alipay payment
{{#payUrl}} Pay with Alipay {{/payUrl}} {{^payUrl}}{{message}}
{{/payUrl}}
Donation failed:{{message}}
Log in to link the donation to your account (anonymous payment also works)
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later