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
₱1399.99 ₱2000.99
Paperback
₱2500.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781783987061
Vendor :
Apache
Category :
Concepts :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 ₱260 each
Feature tick icon Exclusive print discounts
$279.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 ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 2,500.99
Spark Cookbook
₱2500.99
Total 2,500.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.