Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Apache Spark Quick Start Guide

You're reading from   Apache Spark Quick Start Guide Quickly learn the art of writing efficient big data applications with Apache Spark

Arrow left icon
Product type Paperback
Published in Jan 2019
Publisher Packt
ISBN-13 9781789349108
Length 154 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Akash Grade Akash Grade
Author Profile Icon Akash Grade
Akash Grade
Shrey Mehrotra Shrey Mehrotra
Author Profile Icon Shrey Mehrotra
Shrey Mehrotra
Arrow right icon
View More author details
Toc

A sample application

To better understand the life cycle of the Spark application, let's create a sample application and understand the execution step by step. The following example shows the content of the data file that we will use in our application. The sale.csv file stores information,such as PRODUCT_CODE, COUNTRY_CODE, and the order AMOUNT for each ORDER_ID:

$ cat sale.csv

ORDER_ID,PRODUCT_CODE,COUNTRY_CODE,AMOUNT
1,PC_01,USA,200.00
2,PC_01,USA,46.34
3,PC_04,USA,123.54
4,PC_02,IND,99.76
5,PC_44,IND,245.00
6,PC_02,AUS,654.21
7,PC_03,USA,75.00
8,PC_01,SPN,355.00
9,PC_03,USA,34.02
10,PC_03,USA,567.07

We shall now create a sample application using Python API to find out the total sales amount by country and sort them in descending order by the total amount. The following example shows the code of our sample application:

from pyspark.sql import SparkSession
from pyspark.sql.functions...
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 €18.99/month. Cancel anytime