Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Optimizing Databricks Workloads

You're reading from  Optimizing Databricks Workloads

Product type Book
Published in Dec 2021
Publisher Packt
ISBN-13 9781801819077
Pages 230 pages
Edition 1st Edition
Languages
Authors (3):
Anirudh Kala Anirudh Kala
Profile icon Anirudh Kala
Anshul Bhatnagar Anshul Bhatnagar
Profile icon Anshul Bhatnagar
Sarthak Sarbahi Sarthak Sarbahi
Profile icon Sarthak Sarbahi
View More author details

Table of Contents (13) Chapters

Preface 1. Section 1: Introduction to Azure Databricks
2. Chapter 1: Discovering Databricks 3. Chapter 2: Batch and Real-Time Processing in Databricks 4. Chapter 3: Learning about Machine Learning and Graph Processing in Databricks 5. Section 2: Optimization Techniques
6. Chapter 4: Managing Spark Clusters 7. Chapter 5: Big Data Analytics 8. Chapter 6: Databricks Delta Lake 9. Chapter 7: Spark Core 10. Section 3: Real-World Scenarios
11. Chapter 8: Case Studies 12. Other Books You May Enjoy

Understanding the collect() method

Spark's collect() function is an action, and it is used to retrieve all the elements of the Resilient Distributed Dataset (RDD) or DataFrame. We will first take a look at an example of using the function. Run the following code block:

from pyspark.sql.functions import *
airlines_1987_to_2008 = (
  spark
  .read
  .option("header",True)
  .option("delimiter",",")
  .option("inferSchema",True)
  .csv("dbfs:/databricks-datasets/asa/airlines/*")
)
display(airlines_1987_to_2008)

The preceding code block creates a Spark DataFrame and displays the first 1,000 records. Now, let's run some code with the collect() function:

airlines_1987_to_2008.select('Year').distinct().collect()

The preceding line of code returns a list of row objects for the Year column values. A row object is a collection of fields that can be iterated...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}