Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Spark SQL

You're reading from  Learning Spark SQL

Product type Book
Published in Sep 2017
Publisher Packt
ISBN-13 9781785888359
Pages 452 pages
Edition 1st Edition
Languages
Author (1):
Aurobindo Sarkar Aurobindo Sarkar
Profile icon Aurobindo Sarkar

Table of Contents (19) Chapters

Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Getting Started with Spark SQL 2. Using Spark SQL for Processing Structured and Semistructured Data 3. Using Spark SQL for Data Exploration 4. Using Spark SQL for Data Munging 5. Using Spark SQL in Streaming Applications 6. Using Spark SQL in Machine Learning Applications 7. Using Spark SQL in Graph Applications 8. Using Spark SQL with SparkR 9. Developing Applications with Spark SQL 10. Using Spark SQL in Deep Learning Applications 11. Tuning Spark SQL Components for Performance 12. Spark SQL in Large-Scale Application Architectures

Using Spark with JSON data


JSON is a simple, flexible, and format used extensively as a data-interchange format in web services. Spark's support for JSON is great. There is no need for defining the schema for the data, as the schema is automatically inferred. In addition, Spark greatly simplifies the query syntax required to access fields in complex JSON data structures. We will present detailed examples of JSON data in Chapter 12, Spark SQL in Large-Scale Application Architectures

The dataset for this example contains approximately 1.69 million Amazon reviews for the electronics category, and can be downloaded from: http://jmcauley.ucsd.edu/data/amazon/.

We can directly read a JSON dataset to create Spark SQL DataFrame. We will read in a sample set of order records from a JSON file:

scala> val reviewsDF = spark.read.json("file:///Users/aurobindosarkar/Downloads/reviews_Electronics_5.json")

You can print the schema of the newly created DataFrame to verify the fields and their characteristics...

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 €14.99/month. Cancel anytime}