Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Spark Cookbook
Spark Cookbook

Spark Cookbook: With over 60 recipes on Spark, covering Spark Core, Spark SQL, Spark Streaming, MLlib, and GraphX libraries this is the perfect Spark book to always have by your side

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Spark Cookbook

Chapter 2. Developing Applications with Spark

In this chapter, we will cover:

  • Exploring the Spark shell
  • Developing a Spark application in Eclipse with Maven
  • Developing Spark applications in Eclipse with SBT
  • Developing a Spark application in Intellij IDEA with Maven
  • Developing a Spark application in Intellij IDEA with SBT

Introduction

To create production quality Spark jobs/application, it is useful to use various integrated development environments (IDEs) and build tools. This chapter will cover various IDEs and build tools.

Exploring the Spark shell

Spark comes bundled with a REPL shell, which is a wrapper around the Scala shell. Though the Spark shell looks like a command line for simple things, in reality a lot of complex queries can also be executed using it. This chapter explores different development environments in which Spark applications can be developed.

How to do it...

Hadoop MapReduce's word count becomes very simple with the Spark shell. In this recipe, we are going to create a simple 1-line text file, upload it to the Hadoop distributed file system (HDFS), and use Spark to count occurrences of words. Let's see how:

  1. Create the words directory by using the following command:
    $ mkdir words
    
  2. Get into the words directory:
    $ cd words
    
  3. Create a sh.txt text file and enter "to be or not to be" in it:
    $ echo "to be or not to be" > sh.txt
    
  4. Start the Spark shell:
    $ spark-shell
    
  5. Load the words directory as RDD:
    Scala> val words = sc.textFile("hdfs://localhost:9000/user/hduser/words...

Developing Spark applications in Eclipse with Maven

Maven as a build tool has become the de-facto standard over the years. It's not surprising if we look little deeper into the promise Maven brings. Maven has two primary features and they are:

  • Convention over configuration: Build tools prior to Maven gave developers freedom about where to put source files, where to put test files, where to put compiled files, and so on. Maven takes away that freedom. With this freedom, all the confusion about locations also goes. In Maven, there is a specific directory structure for everything. The following table shows a few of the most common locations:

    /src/main/scala

    Source code in Scala

    /src/main/java

    Source code in Java

    /src/main/resources

    Resources to be used by source code such as configuration files

    /src/test/scala

    Test code in Scala

    /src/test/java

    Test code in Java

    /src/test/resources

    Resources to be used by test code such as configuration files

  • Declarative dependency management...

Developing Spark applications in Eclipse with SBT

Simple Build Tool (SBT) is a build tool made especially for Scala-based development. SBT follows Maven-based naming conventions and declarative dependency management.

SBT provides the following enhancements over Maven:

  • Dependencies are in the form of key-value pairs in the build.sbt file as opposed to pom.xml in Maven
  • It provides a shell that makes it very handy to perform build operations
  • For simple projects without dependencies, you do not even need the build.sbt file

In build.sbt, the first line is the project definition:

lazy val root = (project in file("."))

Each project has an immutable map of key-value pairs. This map is changed by settings in SBT like so:

lazy val root = (project in file("."))
  settings(
    name := "wordcount"
  )

Every change in the settings leads to a new map, as it's an immutable map.

How to do it...

Here's how we go about adding the sbteclipse plugin:

  1. Add this to the global plugin...

Developing a Spark application in IntelliJ IDEA with Maven

IntelliJ IDEA comes bundled with support for Maven. We will see how to create a new Maven project in this recipe.

How to do it...

Perform the following steps to develop a Spark application on IntelliJ IDEA with Maven:

  1. Select Maven in new project window and click on Next:
    How to do it...
  2. Enter three dimensions of the project:
    How to do it...
  3. Enter the project's name and location:
    How to do it...
  4. Click on Finish and the Maven project is ready.

Developing a Spark application in IntelliJ IDEA with SBT

Before Eclipse became famous, IntelliJ IDEA was considered best of the breed in IDEs. IDEA has not shed its former glory yet and a lot of developers love IDEA. IDEA also has a community edition, which is free. IDEA provides native support for SBT, which makes it ideal for SBT and Scala development.

How to do it...

Perform the following steps to develop a Spark application on IntelliJ IDEA with SBT:

  1. Add the sbt-idea plugin.
  2. Add to the global plugin file:
    $mkdir /home/hduser/.sbt/0.13/plugins
    $echo addSbtPlugin("com.github.mpeltone" % "sbt-idea" % "1.6.0" )  > /home/hduser/.sbt/0.12/plugins/plugin.sbt
    

    Alternatively, you can add to your project as well:

    $cd <project-home>
    $ echo addSbtPlugin("com.github.mpeltone" % "sbt-idea" % "1.6.0" ) > plugin.sbt
    

IDEA is ready to use with SBT.

Now you can develop Spark code using Scala and build using SBT.

Left arrow icon Right arrow icon

Description

If you are a data engineer, an application developer, or a data scientist who would like to leverage the power of Apache Spark to get better insights from big data, then this is the book for you.

Who is this book for?

If you are a data engineer, an application developer, or a data scientist who would like to leverage the power of Apache Spark to get better insights from big data, then this is the book for you.

What you will learn

  • Install and configure Apache Spark with various cluster managers
  • Set up development environments
  • Perform interactive queries using Spark SQL
  • Get to grips with realtime streaming analytics using Spark Streaming
  • Master supervised learning and unsupervised learning using MLlib
  • Build a recommendation engine using MLlib
  • Develop a set of common applications or project types, and solutions that solve complex big data problems
  • Use Apache Spark as your single big data compute platform and master its libraries

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 27, 2015
Length: 226 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987078
Vendor :
Apache
Category :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 27, 2015
Length: 226 pages
Edition : 1st
Language : English
ISBN-13 : 9781783987078
Vendor :
Apache
Category :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 36.99
Spark Cookbook
€36.99
Total 36.99 Stars icon

Table of Contents

13 Chapters
1. Getting Started with Apache Spark Chevron down icon Chevron up icon
2. Developing Applications with Spark Chevron down icon Chevron up icon
3. External Data Sources Chevron down icon Chevron up icon
4. Spark SQL Chevron down icon Chevron up icon
5. Spark Streaming Chevron down icon Chevron up icon
6. Getting Started with Machine Learning Using MLlib Chevron down icon Chevron up icon
7. Supervised Learning with MLlib – Regression Chevron down icon Chevron up icon
8. Supervised Learning with MLlib – Classification Chevron down icon Chevron up icon
9. Unsupervised Learning with MLlib Chevron down icon Chevron up icon
10. Recommender Systems Chevron down icon Chevron up icon
11. Graph Processing Using GraphX Chevron down icon Chevron up icon
12. Optimizations and Performance Tuning Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(18 Ratings)
5 star 66.7%
4 star 16.7%
3 star 11.1%
2 star 0%
1 star 5.6%
Filter icon Filter
Top Reviews

Filter reviews by




Amazon Customer Nov 03, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A simple book to get you started on Spark. Way to go for students. Well organized.
Amazon Verified review Amazon
CP95 Nov 02, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Accurate Concepts and IdeasConciseVery Easy to understandVery Helpful Real Time examplesWell-WrittenWell-FormattedAttractive to ReadI totally recommend this book. I tried to solve a programming problem for a week and with this book I understood how to fix it in about half an hour. I read the whole book and practice all the examples which are mention it is very easy to understand and the examples are also easy to implement. I Loved it. One of the most recommended book to be a expert in spark.
Amazon Verified review Amazon
Sanjay Nov 20, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book. Very Clear information for beginner & advanced developer. Information is to the point & practical. I like the way the chapters are laid out , progressing along from a hadoop developer, then transitioning to a Spark developer.....I hope the author enhances the content to include Spark 1.5 & 1.6 with details on EMR & EC2 usage for Spark
Amazon Verified review Amazon
Venkat M Jul 26, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very comprehensive book on Spark. Well organized and covers a wide range of topics. Must read book for anyone using Spark.
Amazon Verified review Amazon
Amazon Customer Nov 01, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I listened to this entire book in just a few days. it is interesting and informative I have new motivation to exercise! I never thought about how exercise could affect my mind and happiness. I highly recommend. Wonderful!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.