Table Of ContentNext-Generation
Big Data
A Practical Guide to Apache Kudu, Impala,
and Spark
—
Butch Quinto
Next-Generation Big Data
A Practical Guide to Apache Kudu,
Impala, and Spark
Butch Quinto
Next-Generation Big Data: A Practical Guide to Apache Kudu, Impala, and Spark
Butch Quinto
Plumpton, Victoria, Australia
ISBN-13 (pbk): 978-1-4842-3146-3 ISBN-13 (electronic): 978-1-4842-3147-0
https://doi.org/10.1007/978-1-4842-3147-0
Library of Congress Control Number: 2018947173
Copyright © 2018 by Butch Quinto
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Susan McDermott
Development Editor: Laura Berendson
Coordinating Editor: Rita Fernando
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc
is a Delaware corporation.
For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484231463. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
This book is dedicated to my wife, Aileen; and my children,
Matthew, Timothy, and Olivia.
Table of Contents
About the Author ���������������������������������������������������������������������������������������������������xvii
About the Technical Reviewer ��������������������������������������������������������������������������������xix
Acknowledgments ��������������������������������������������������������������������������������������������������xxi
Introduction ����������������������������������������������������������������������������������������������������������xxiii
Chapter 1: Next-Generation Big Data ������������������������������������������������������������������������1
About This Book ����������������������������������������������������������������������������������������������������������������������������2
Apache Spark ��������������������������������������������������������������������������������������������������������������������������������2
Apache Impala ������������������������������������������������������������������������������������������������������������������������������3
Apache Kudu ���������������������������������������������������������������������������������������������������������������������������������3
Navigating This Book ��������������������������������������������������������������������������������������������������������������������3
Summary���������������������������������������������������������������������������������������������������������������������������������������5
Chapter 2: Introduction to Kudu �������������������������������������������������������������������������������7
Kudu Is for Structured Data ����������������������������������������������������������������������������������������������������������9
Use Cases �������������������������������������������������������������������������������������������������������������������������������������9
Relational Data Management and Analytics ��������������������������������������������������������������������������10
Internet of Things (IoT) and Time Series ��������������������������������������������������������������������������������11
Feature Store for Machine Learning Platforms ���������������������������������������������������������������������12
Key Concepts ������������������������������������������������������������������������������������������������������������������������������12
Architecture ��������������������������������������������������������������������������������������������������������������������������������13
Multi-Version Concurrency Control (MVCC) ���������������������������������������������������������������������������������14
Impala and Kudu �������������������������������������������������������������������������������������������������������������������������15
Primary Key ���������������������������������������������������������������������������������������������������������������������������15
Data Types �����������������������������������������������������������������������������������������������������������������������������16
Partitioning ����������������������������������������������������������������������������������������������������������������������������17
v
Table of ConTenTs
Spark and Kudu ��������������������������������������������������������������������������������������������������������������������������19
Kudu Context �������������������������������������������������������������������������������������������������������������������������19
Kudu C++, Java, and Python Client APIs �������������������������������������������������������������������������������������24
Kudu Java Client API ��������������������������������������������������������������������������������������������������������������24
Kudu Python Client API ����������������������������������������������������������������������������������������������������������27
Kudu C++ Client API ��������������������������������������������������������������������������������������������������������������29
Backup and Recovery �����������������������������������������������������������������������������������������������������������������34
Backup via CTAS ��������������������������������������������������������������������������������������������������������������������34
Copy the Parquet Files to Another Cluster or S3 �������������������������������������������������������������������������35
Export Results via impala-shell to Local Directory, NFS, or SAN Volume�������������������������������36
Export Results Using the Kudu Client API ������������������������������������������������������������������������������36
Export Results with Spark �����������������������������������������������������������������������������������������������������38
Replication with Spark and Kudu Data Source API ����������������������������������������������������������������38
Real-Time Replication with StreamSets ��������������������������������������������������������������������������������40
Replicating Data Using ETL Tools Such as Talend, Pentaho, and CDAP ���������������������������������41
Python and Impala ����������������������������������������������������������������������������������������������������������������������43
Impyla ������������������������������������������������������������������������������������������������������������������������������������43
pyodbc �����������������������������������������������������������������������������������������������������������������������������������44
SQLAlchemy ��������������������������������������������������������������������������������������������������������������������������44
High Availability Options �������������������������������������������������������������������������������������������������������������44
Active-Active Dual Ingest with Kafka and Spark Streaming ��������������������������������������������������45
Active-Active Kafka Replication with MirrorMaker ����������������������������������������������������������������45
Active-Active Dual Ingest with Kafka and StreamSets ����������������������������������������������������������46
Active-Active Dual Ingest with StreamSets ���������������������������������������������������������������������������47
Administration and Monitoring����������������������������������������������������������������������������������������������������47
Cloudera Manager Kudu Service �������������������������������������������������������������������������������������������47
Kudu Master Web UI ��������������������������������������������������������������������������������������������������������������47
Kudu Tablet Server Web UI ����������������������������������������������������������������������������������������������������48
Kudu Metrics �������������������������������������������������������������������������������������������������������������������������48
Kudu Command-Line Tools ����������������������������������������������������������������������������������������������������48
Known Issues and Limitations ����������������������������������������������������������������������������������������������������51
vi
Table of ConTenTs
Security ���������������������������������������������������������������������������������������������������������������������������������������52
Summary�������������������������������������������������������������������������������������������������������������������������������������53
References ����������������������������������������������������������������������������������������������������������������������������������53
Chapter 3: Introduction to Impala ��������������������������������������������������������������������������57
Architecture ��������������������������������������������������������������������������������������������������������������������������������57
Impala Server Components ���������������������������������������������������������������������������������������������������58
Impala SQL ����������������������������������������������������������������������������������������������������������������������������������63
Data Types �����������������������������������������������������������������������������������������������������������������������������63
SQL Statements ���������������������������������������������������������������������������������������������������������������������64
SET Statements ���������������������������������������������������������������������������������������������������������������������71
SHOW Statements �����������������������������������������������������������������������������������������������������������������72
Built-In Functions ������������������������������������������������������������������������������������������������������������������74
User-Defined Functions ���������������������������������������������������������������������������������������������������������������76
Complex Types in Impala ������������������������������������������������������������������������������������������������������������76
Querying Struct Fields �����������������������������������������������������������������������������������������������������������77
Querying Deeply Nested Collections��������������������������������������������������������������������������������������78
Querying Using ANSI-92 SQL Joins with Nested Collections �������������������������������������������������79
Impala Shell ��������������������������������������������������������������������������������������������������������������������������������79
Performance Tuning and Monitoring �������������������������������������������������������������������������������������������84
Explain �����������������������������������������������������������������������������������������������������������������������������������85
Summary �������������������������������������������������������������������������������������������������������������������������������85
Profile ������������������������������������������������������������������������������������������������������������������������������������86
Cloudera Manager �����������������������������������������������������������������������������������������������������������������87
Impala Performance Recommendations �������������������������������������������������������������������������������93
Workload and Resource Management ����������������������������������������������������������������������������������������95
Admission Control �����������������������������������������������������������������������������������������������������������������95
Hadoop User Experience �������������������������������������������������������������������������������������������������������������96
Impala in the Enterprise ��������������������������������������������������������������������������������������������������������������98
Summary�������������������������������������������������������������������������������������������������������������������������������������98
References ����������������������������������������������������������������������������������������������������������������������������������98
vii
Table of ConTenTs
Chapter 4: High Performance Data Analysis with Impala and Kudu ��������������������101
Primary Key �������������������������������������������������������������������������������������������������������������������������������101
Data Types ���������������������������������������������������������������������������������������������������������������������������������102
Internal and External Impala Tables ������������������������������������������������������������������������������������������103
Internal Tables ���������������������������������������������������������������������������������������������������������������������103
External Tables ��������������������������������������������������������������������������������������������������������������������104
Changing Data ���������������������������������������������������������������������������������������������������������������������������104
Inserting Rows ���������������������������������������������������������������������������������������������������������������������104
Updating Rows ��������������������������������������������������������������������������������������������������������������������105
Upserting Rows �������������������������������������������������������������������������������������������������������������������105
Deleting Rows ���������������������������������������������������������������������������������������������������������������������105
Changing Schema ���������������������������������������������������������������������������������������������������������������������106
Partitioning ��������������������������������������������������������������������������������������������������������������������������������106
Hash Partitioning �����������������������������������������������������������������������������������������������������������������106
Range Partitioning ���������������������������������������������������������������������������������������������������������������106
Hash-Range Partitioning �����������������������������������������������������������������������������������������������������107
Hash-Hash Partitioning ��������������������������������������������������������������������������������������������������������108
List Partitioning �������������������������������������������������������������������������������������������������������������������108
Using JDBC with Apache Impala and Kudu �������������������������������������������������������������������������������109
Federation with SQL Server Linked Server and Oracle Gateway ����������������������������������������������110
Summary�����������������������������������������������������������������������������������������������������������������������������������111
References ��������������������������������������������������������������������������������������������������������������������������������111
Chapter 5: Introduction to Spark ��������������������������������������������������������������������������113
Overview �����������������������������������������������������������������������������������������������������������������������������������113
Cluster Managers ����������������������������������������������������������������������������������������������������������������114
Architecture ������������������������������������������������������������������������������������������������������������������������������115
Executing Spark Applications����������������������������������������������������������������������������������������������������116
Spark on YARN ��������������������������������������������������������������������������������������������������������������������������116
Cluster Mode �����������������������������������������������������������������������������������������������������������������������116
Client Mode �������������������������������������������������������������������������������������������������������������������������117
viii
Table of ConTenTs
Introduction to the Spark-Shell �������������������������������������������������������������������������������������������������117
SparkSession �����������������������������������������������������������������������������������������������������������������������118
Accumulator ������������������������������������������������������������������������������������������������������������������������119
Broadcast Variables �������������������������������������������������������������������������������������������������������������119
RDD ��������������������������������������������������������������������������������������������������������������������������������������119
Spark SQL, Dataset, and DataFrames API ���������������������������������������������������������������������������������127
Spark Data Sources ������������������������������������������������������������������������������������������������������������������129
CSV ��������������������������������������������������������������������������������������������������������������������������������������129
XML��������������������������������������������������������������������������������������������������������������������������������������130
JSON ������������������������������������������������������������������������������������������������������������������������������������131
Relational Databases Using JDBC ���������������������������������������������������������������������������������������132
Parquet ��������������������������������������������������������������������������������������������������������������������������������136
HBase ����������������������������������������������������������������������������������������������������������������������������������136
Amazon S3 ��������������������������������������������������������������������������������������������������������������������������142
Solr ��������������������������������������������������������������������������������������������������������������������������������������142
Microsoft Excel ��������������������������������������������������������������������������������������������������������������������143
Secure FTP ��������������������������������������������������������������������������������������������������������������������������144
Spark MLlib (DataFrame-Based API) �����������������������������������������������������������������������������������������145
Pipeline ��������������������������������������������������������������������������������������������������������������������������������146
Transformer �������������������������������������������������������������������������������������������������������������������������146
Estimator �����������������������������������������������������������������������������������������������������������������������������146
ParamGridBuilder ����������������������������������������������������������������������������������������������������������������147
CrossValidator ���������������������������������������������������������������������������������������������������������������������147
Evaluator������������������������������������������������������������������������������������������������������������������������������147
Example ������������������������������������������������������������������������������������������������������������������������������������147
GraphX ��������������������������������������������������������������������������������������������������������������������������������������152
Spark Streaming �����������������������������������������������������������������������������������������������������������������������152
Hive on Spark ����������������������������������������������������������������������������������������������������������������������������152
Spark 1�x vs Spark 2�x ��������������������������������������������������������������������������������������������������������������152
ix
Table of ConTenTs
Monitoring and Configuration ���������������������������������������������������������������������������������������������������153
Cloudera Manager ���������������������������������������������������������������������������������������������������������������153
Spark Web UI �����������������������������������������������������������������������������������������������������������������������154
Summary�����������������������������������������������������������������������������������������������������������������������������������157
References ��������������������������������������������������������������������������������������������������������������������������������157
Chapter 6: High Performance Data Processing with Spark and Kudu ������������������159
Spark and Kudu ������������������������������������������������������������������������������������������������������������������������159
Spark 1�6�x ��������������������������������������������������������������������������������������������������������������������������159
Spark 2�x �����������������������������������������������������������������������������������������������������������������������������160
Kudu Context �����������������������������������������������������������������������������������������������������������������������������160
Inserting Data ����������������������������������������������������������������������������������������������������������������������161
Updating a Kudu Table ���������������������������������������������������������������������������������������������������������162
Upserting Data ���������������������������������������������������������������������������������������������������������������������163
Deleting Data �����������������������������������������������������������������������������������������������������������������������164
Selecting Data ���������������������������������������������������������������������������������������������������������������������165
Creating a Kudu Table ����������������������������������������������������������������������������������������������������������165
Inserting CSV into Kudu �������������������������������������������������������������������������������������������������������166
Inserting CSV into Kudu Using the spark-csv Package �������������������������������������������������������166
Insert CSV into Kudu by Programmatically Specifying the Schema ������������������������������������167
Inserting XML into Kudu Using the spark-xml Package ������������������������������������������������������168
Inserting JSON into Kudu ����������������������������������������������������������������������������������������������������171
Inserting from MySQL into Kudu ������������������������������������������������������������������������������������������173
Inserting from SQL Server into Kudu �����������������������������������������������������������������������������������178
Inserting from HBase into Kudu �������������������������������������������������������������������������������������������188
Inserting from Solr into Kudu ����������������������������������������������������������������������������������������������194
Insert from Amazon S3 into Kudu ����������������������������������������������������������������������������������������195
Inserting from Kudu into MySQL ������������������������������������������������������������������������������������������196
Inserting from Kudu into SQL Server �����������������������������������������������������������������������������������198
Inserting from Kudu into Oracle ������������������������������������������������������������������������������������������201
Inserting from Kudu to HBase ���������������������������������������������������������������������������������������������205
x
Description:Utilize this practical and easy-to-follow guide to modernize traditional enterprise data warehouse and business intelligence environments with next-generation big data technologies.Next-Generation Big Data takes a holistic approach, covering the most important aspects of modern enterprise big data.