Azure HDInsight Developer Guide
Azure HDInsight Developer Guide
Developer Guide
Table of Contents
Overview
What is Azure HDInsight?
Iterative data exploration
Data Warehouse on demand
ETL at scale
Streaming at scale
Machine learning
Batch & Interactive Processing
Run Custom Programs
Upload Data to HDInsight
Azure HDInsight and Hadoop Architecture
HDInsight Architecture
Hadoop Architecture
Lifecycle of an HDInsight Cluster
High availability model
Capacity planning
Configuring the Cluster
Use SSH with HDInsight
Use SSH tunneling
Use HDInsight in a Virtual Network
Scaling best practices
Configuring Hive and Oozie Metadata Storage
Configuring Identity and Access Controls
Manage authorized Ambari users
Authorize user access to Ranger
Add ACLs at the file and folder levels
Sync users from Azure Active Directory to cluster
Use on-demand HDInsight clusters from Data Factory
Monitoring and managing the HDInsight cluster
Key scenarios to monitor
Monitoring and managing with Ambari
Monitoring with the Ambari REST API
Administering HDInsight using the Azure Portal
Manage configurations with Ambari
Manage cluster logs
Adding storage accounts to a running cluster
Use script actions to customize cluster setup
Develop script actions
OS patching for HDInsight cluster
Developing Hive applications
Hive and ETL Overview
Connect to Hive with JDBC or ODBC
Writing Hive applications using Java
Writing Hive applications using Python
Creating user defined functions
Process and analyze JSON documents with Hive
Hive samples
Query Hive using Excel
Analyze stored sensor data using Hive
Analyze stored tweets using beeline and Hive
Analyze flight delay data with Hive
Analyze website logs with Hive
Developing Spark applications
Spark Scenarios
Use Spark with HDInsight
Use Spark SQL with HDInsight
Run Spark from the Shell
Use Spark with notebooks
Use Zeppelin notebooks with Spark
Use Jupyter notebook with Spark
Use external packages with Jupyter using cell magic
Use external packages with Jupyter using script action
Use Spark with IntelliJ
Create apps using the Azure Toolkit for IntelliJ
Debug jobs remotely with IntelliJ
Spark samples
Analyze Application Insights telemetry with Spark
Analyze website logs with Spark SQL
Developing Spark ML applications
Creating Spark ML Pipelines
Creating Spark ML models in notebooks
Deep Learning with Spark
Use Caffe for deep learning with Spark
Developing R scripts on HDInsight
What is R Server?
Selecting a compute context
Analyze data from Azure Storage and Data Lake Store using R
Submit jobs from Visual Studio Tools for R
Submit R jobs from R Studio Server
Developing Spark Streaming applications
What is Spark Streaming (DStreams)?
What is Spark Structured Streaming?
Use Spark DStreams to process events from Kafka
Use Spark DStreams to process events from Event Hubs
Use Spark Structured Streaming to process events from Kafka
Use Spark Structured Streaming to process events from Event Hubs
Creating highly available Spark Streaming jobs in YARN
Creating Spark Streaming jobs with exactly once event processing guarantees
Optimizing Spark Performance
Optimizing and configuring Spark jobs for performance
Configuring Spark settings
Choosing between Spark RDD, dataframe and dataset
Use HBase
What is HBase?
What is HBase?
Understanding the HBase storage options
Using the HBase shell
Using the HBase REST SDK
Configure HBase backup and replication
Using Spark with HBase
Monitor HBase with OMS
HBase - Migrating to a New Version
Use Phoenix with HBase on HDInsight
Phoenix in HDInsight
Get started using Phoenix with SQLLine
Bulk Loading with Phoenix with psql
Using Spark with Phoenix
Using the Phoenix Query Server REST SDK
Phoenix performance monitoring
Apache Open Source Ecosystem
Install HDInsight apps
Install and use Dataiku
Install and use Datameer
Install and use H2O
Install and use Streamsets
Install and use Cask
Advanced Scenarios and Deep Dives
Advanced Analytics Deep Dive
ETL Deep Dive
Operationalize Data Pipelines with Oozie
Streaming and Business Intelligence
Troubleshooting
Troubleshooting a failed or slow HDInsight cluster
Debug jobs by analyzing HDInsight logs
Debug Tez jobs using Hive views in Ambari
Common problems FAQ
Introduction to Azure HDInsight, the Hadoop
technology stack, and Hadoop clusters
8/16/2017 • 9 min to read • Edit Online
This article provides an introduction to Azure HDInsight, a cloud distribution of the Hadoop technology stack. It also
covers what a Hadoop cluster is and when you would use it.
Ambari
Apache Ambari is for provisioning, managing, and monitoring Apache Hadoop clusters. It includes an intuitive
collection of operator tools and a robust set of APIs that hide the complexity of Hadoop, simplifying the operation
of clusters. HDInsight clusters on Linux provide both the Ambari web UI and the Ambari REST API. Ambari Views on
HDInsight clusters allow plug-in UI capabilities. See Manage HDInsight clusters using Ambari and Apache Ambari
API reference.
Avro (Microsoft .NET Library for Avro )
The Microsoft .NET Library for Avro implements the Apache Avro compact binary data interchange format for
serialization for the Microsoft .NET environment. It defines a language-agnostic schema so that data serialized in
one language can be read in another. Detailed information on the format can be found in the Apache Avro
Specification. The format of Avro files supports the distributed MapReduce programming model: Files are
“splittable”, meaning you can seek any point in a file and start reading from a particular block. To find out how, see
Serialize data with the Microsoft .NET Library for Avro. Linux-based cluster support to come.
HDFS
Hadoop Distributed File System (HDFS) is a file system that, with YARN and MapReduce, is the core of Hadoop
technology. It's the standard file system for Hadoop clusters on HDInsight. See Query data from HDFS-compatible
storage.
Hive & HCatalog
Apache Hive is data warehouse software built on Hadoop that allows you to query and manage large datasets in
distributed storage by using a SQL-like language called HiveQL. Hive, like Pig, is an abstraction on top of
MapReduce, and it translates queries into a series of MapReduce jobs. Hive is closer to a relational database
management system than Pig, and is used with more structured data. For unstructured data, Pig is the better
choice. See Use Hive with Hadoop in HDInsight.
Apache HCatalog is a table and storage management layer for Hadoop that presents you with a relational view of
data. In HCatalog, you can read and write files in any format that works for a Hive SerDe (serializer-deserializer).
Mahout
Apache Mahout is a library of machine learning algorithms that run on Hadoop. Using principles of statistics,
machine learning applications teach systems to learn from data and to use past outcomes to determine future
behavior. See Generate movie recommendations using Mahout on Hadoop.
MapReduce
MapReduce is the legacy software framework for Hadoop for writing applications to batch process big data sets in
parallel. A MapReduce job splits large datasets and organizes the data into key-value pairs for processing.
MapReduce jobs run on YARN. See MapReduce in the Hadoop Wiki.
Oozie
Apache Oozie is a workflow coordination system that manages Hadoop jobs. It is integrated with the Hadoop stack
and supports Hadoop jobs for MapReduce, Pig, Hive, and Sqoop. It can also be used to schedule jobs specific to a
system, like Java programs or shell scripts. See Use Oozie with Hadoop.
Phoenix
Apache Phoenix is a relational database layer over HBase. Phoenix includes a JDBC driver that allows you to query
and manage SQL tables directly. Phoenix translates queries and other statements into native NoSQL API calls -
instead of using MapReduce - thus enabling faster applications on top of NoSQL stores. See Use Apache Phoenix
and SQuirreL with HBase clusters.
Pig
Apache Pig is a high-level platform that allows you to perform complex MapReduce transformations on large
datasets by using a simple scripting language called Pig Latin. Pig translates the Pig Latin scripts so they’ll run
within Hadoop. You can create User-Defined Functions (UDFs) to extend Pig Latin. See Use Pig with Hadoop.
Sqoop
Apache Sqoop is a tool that transfers bulk data between Hadoop and relational databases such as SQL, or other
structured data stores, as efficiently as possible. See Use Sqoop with Hadoop.
Tez
Apache Tez is an application framework built on Hadoop YARN that executes complex, acyclic graphs of general
data processing. It's a more flexible and powerful successor to the MapReduce framework that allows data-
intensive processes, such as Hive, to run more efficiently at scale. See "Use Apache Tez for improved performance"
in Use Hive and HiveQL.
YARN
Apache YARN is the next generation of MapReduce (MapReduce 2.0, or MRv2) and supports data processing
scenarios beyond MapReduce batch processing with greater scalability and real-time processing. YARN provides
resource management and a distributed application framework. MapReduce jobs run on YARN. See Apache
Hadoop NextGen MapReduce (YARN).
ZooKeeper
Apache ZooKeeper coordinates processes in large distributed systems using a shared hierarchical namespace of
data registers (znodes). Znodes contain small amounts of meta information needed to coordinate processes: status,
location, configuration, and so on. See an example of ZooKeeper with an HBase cluster and Apache Phoenix.
Next steps
Get started with Hadoop in HDInsight: A quick-start tutorial for provisioning HDInsight Hadoop clusters and
running sample Hive queries.
Get started with Spark in HDInsight: A quick-start tutorial for creating a Spark cluster and running interactive
Spark SQL queries.
Use R Server on HDInsight: Start using R Server in HDInsight Premium.
Provision HDInsight clusters: Learn how to provision an HDInsight Hadoop cluster through the Azure portal,
Azure CLI, or Azure PowerShell.
Iterative Data Exploration
8/15/2017 • 7 min to read • Edit Online
Traditional data storage and management systems such as data warehouses, data models, and reporting and
analytical tools provide a wealth of information on which to base business decisions. However, while traditional BI
works well for business data that can easily be structured, managed, and processed in a dimensional analysis
model, some kinds of analysis require a more flexible solution that can derive meaning from less obvious sources
of data such as log files, email messages, tweets, and more. There's a great deal of useful information to be found
in these less structured data sources, which often contain huge volumes of data that must be processed to reveal
key data points. This kind of data processing is what big data solutions such as HDInsight were designed to handle.
It provides a way to process extremely large volumes of unstructured or semi-structured data, often by performing
complex computation and transformation batch processing of the data, to produce an output that can be visualized
directly or combined with other datasets.
If you do not intend to reuse the information from the analysis, but just want to explore the data, you may choose
to consume it directly in an analysis or visualization tool such as Microsoft Excel.
Text files and compressed binary files can be loaded directly into the cluster storage, while stream data will usually
need to be collected and handled by a suitable stream capture mechanism (see Upload data for Hadoop jobs in
HDInsight for more information). The output data may be combined with other datasets within your visualization
and reporting tools to augment the information and to provide comparisons, as you will see later in this topic.
When using HDInsight for iterative data exploration, you will often do so as an interactive process. For example,
you might use the Power Query add-in for Excel to submit a query to an HDInsight cluster and wait for the results
to be returned, usually within a few seconds or even a few minutes. You can then modify and experiment with the
query to optimize the information it returns.
However, keep in mind that these are batch operations that are submitted to all of the servers in the cluster for
parallel processing, and queries can often take minutes or hours to complete when there are very large volumes of
source data. For example, you might use Pig to process an input file, with the results returned in an output file
some time later—at which point you can perform the analysis by importing this file into your chosen visualization
tool.
The decision flow
One of the typical uses of a big data solution such as HDInsight is to explore data that you already have, or data
you collect speculatively, to see if it can provide insights into information that you can use within your
organization. The decision flow shown below is an example of how you might start with a guess based on intuition,
and progress towards a repeatable solution that you can incorporate into your existing BI systems. Or, perhaps, to
discover that there is no interesting information in the data, but the cost of discovering this has been minimized by
using a "pay for what you use" mechanism that you can set up and then tear down again very quickly and easily.
Combining your data with datasets available from Azure Marketplace or other commercial data sources can
reveal useful information that might otherwise remain hidden in your data.
Data sources
The input data for this model typically includes the following:
Social data, log files, sensors, and applications that generate data files.
Datasets obtained from Azure Marketplace and other commercial data providers.
Internal data extracted from databases or data warehouses for experimentation and one-off analysis.
Streaming data that is captured, filtered, and pre-processed through a suitable tool or framework (see
Upload data for Hadoop jobs in HDInsight).
Notice that, as well as externally obtained data, you might process data from within your organization's existing
database or data warehouse. HDInsight is an ideal solution when you want to perform offline exploration of
existing data in a sandbox. For example, you may join several datasets from your data warehouse to create large
datasets that act as the source for some experimental investigation, or to test new analysis techniques. This avoids
the risk of interrupting existing systems, affecting performance of your data warehouse system, or accidently
corrupting the core data.
The capability to store schema-less data, and apply a schema only when processing the data, may also simplify the
task of combining information from different systems because you do not need to apply a schema beforehand, as
you would in a traditional data warehouse.
Often you need to perform more than one query on the data to get the results into the form you need. It's not
unusual to base queries on the results of a preceding query; for example, using one query to select and
transform the required data and remove redundancy, a second query to summarize the data returned from the
first query, and a third query to format the output as required. This iterative approach enables you to start with
a large volume of complex and difficult to analyze data, and get it into a structure that you can consume
directly from an analytical tool such as Excel, or use as input to a managed BI solution.
Output targets
The results from your exploration processes can be visualized using any of the wide range of tools that are
available for analyzing data, combining it with other datasets, and generating reports. Typical examples for the
iterative exploration model are:
Interactive analytical tools such as Excel, Power Query, Power Pivot, Power View, and Power Map.
SQL Server Reporting Services using Report Builder.
Custom or third party analysis and visualization tools.
Considerations
There are some important points to consider when choosing the iterative exploration model:
This model is typically used when you want to:
Experiment with new types or sources of data.
Generate one-off reports or visualizations of external or internal data.
Monitor a data source using visualizations to detect changes or to predict behavior.
Combine the output with other data to generate comparisons or to augment the information.
You will usually choose this model when you do not want to persist the results of the query after analysis, or
after the required reports have been generated. It is typically used for one-off analysis tasks where the
results are discarded after use; and so differs from the other models described in this guide in which the
results are stored and reused.
Very large datasets are likely to preclude the use of an interactive approach due to the time taken for the
queries to run. However, after the queries are complete you can connect to the cluster and work interactively
with the data to perform different types of analysis or visualization.
Data arriving as a stream, such as the output from sensors on an automated production line or the data
generated by GPS sensors in mobile devices, requires additional considerations. A typical technique is to
capture the data using a stream processing technology such as Storm or StreamInsight and persist it, then
process it in batches or at regular intervals. The stream capture technology may perform some pre-
processing, and might also power a real time visualization or rudimentary analysis tool, as well as feeding it
into an HDInsight cluster. A common technique is micro-batch processing, where incoming data is persisted
in small increments, allowing near real-time processing by the big data solution.
You are not limited to running a single query on the source data. You can follow an iterative pattern in
which the data is passed through the cluster multiple times, each pass refining the data until it is suitably
prepared for use in your analytical tool. For example, a large unstructured file might be processed using a
Pig script to generate a smaller, more structured output file. This output could then be used as the input for
a Hive query that returns aggregated data in tabular form.
Next steps
HDInsight Architecture
Data Warehouse on Demand
Upload data for Hadoop jobs in HDInsight
Data Warehouse on Demand
8/16/2017 • 8 min to read • Edit Online
Hadoop-based big data solutions such as HDInsight can provide a robust, high performance, and cost-effective
data storage and parallel job processing mechanism. Data is replicated in the storage system, and jobs are
distributed across the nodes for fast parallel processing. In the case of HDInsight, the data is saved in Azure blob
storage or Azure Data Lake Store, which is also replicated three times.
This combination of capabilities means that you can use HDInsight as a basic data warehouse. The low cost of
storage when compared to most relational database mechanisms that have the same level of reliability also means
that you can use it simply as a commodity storage mechanism for huge volumes of data, even if you decide not to
transform the data into Hive tables.
If you need to store vast amounts of data, irrespective of the format of that data, an HDInsight Hadoop-based
solution can reduce administration overhead and save money by minimizing the need for the high
performance database servers and storage clusters used by traditional relational database systems. With
HDInsight, you can also reduce the administration overhead and running costs compared to on-premises
deployment of a Hadoop-based cluster.
In this model, when you need to process the stored data, you create an HDInsight Hadoop-based cluster that uses
the Azure blob storage container holding that data. When you finish processing the data you can tear down the
cluster without losing the original archived data (see Using external metadata stores for information about
preserving or recreating metadata such as Hive table definitions when you tear down and then recreate an
HDInsight cluster).
You might also consider storing partly processed data where you have performed some translation or summary of
the data, but it is still in a relatively raw form that you want to keep in case it is useful in the future. For example,
you might use a stream capture tool to allocate incoming positional data from a fleet of vehicles into separate
categories or areas, add some reference keys to each item, and then store the results ready for processing at a later
date. Stream data may arrive in rapid bursts, and typically generates very large files, so using HDInsight to capture
and store the data helps to minimize the load on your existing data management systems.
This model is also suitable for use as a data store where you do not need to implement the typical data warehouse
capabilities. For example, you may just want to minimize storage cost when saving large tabular format data files
for use in the future, large text files such as email archives or data that you must keep for legal or regulatory
reasons but you do not need to process, or for storing large quantities of binary data such as images or
documents. In this case you simply load the data into the storage associated with cluster, without creating Hive
tables for it.
You might, as an alternative, choose to use just an HBase cluster in this model. HBase can be accessed directly from
client applications through the Java APIs and the REST interface. You can load data directly into HBase and query it
using the built-in mechanisms.
Data sources
Data sources for this model are typically data collected from internal and external business processes. However, it
may also include reference data and datasets obtained from other sources that can be matched on a key to existing
data in your data store so that it can be used to augment the results of analysis and reporting processes. Some
examples are:
Data generated by internal business processes, websites, and applications.
Reference data and data definitions used by business processes.
Datasets obtained from Azure Marketplace and other commercial data providers.
If you adopt this model simply as a commodity data store rather than a data warehouse, you might also load data
from other sources such as social media data, log files, and sensors; or streaming data that is captured, filtered, and
processed through a suitable tool or framework (see Upload data for Hadoop jobs in HDInsight).
Output targets
The main intention of this model is to provide the equivalent to a data warehouse system based on the traditional
relational database model, and expose it as Hive tables. You can use these tables in a variety of ways, such as:
Combining the datasets for analysis, and using the result to generate reports and business information.
Generating ancillary information such as “related items” or recommendation lists for use in applications and
websites.
Providing external access to the results through web applications, web services, and other services.
Powering information systems such as SharePoint server through web parts and the Business Data
Connector (BDC).
If you adopt this model simply as a commodity data store rather than a data warehouse, you might use the data
you store as an input for any of the models described here.
The data in an HDInsight data warehouse can be analyzed and visualized directly using any tools that can consume
Hive tables. Typical examples are:
SQL Server Reporting Services
SQL Server Analysis Services
Interactive analytical tools such as Excel, Power Query, Power Pivot, Power View, and Power Map
Custom or third party analysis and visualization tools
Considerations
There are some important points to consider when choosing the data warehouse on demand model:
This model is typically used when you want to:
Create a central point for analysis and reporting by multiple users and tools.
Store multiple datasets for use by internal applications and tools.
Host your data in the cloud to benefit from reliability and elasticity, to minimize cost, and to reduce
administration overhead.
Store both externally collected data and data generated by internal tools and processes.
Refresh the data at scheduled intervals or on demand.
You can use Hive to:
Define tables that have the familiar row and column format, with a range of data types for the columns
that includes both primitive types (including timestamps) and complex types such as arrays, maps, and
structures.
Load data from storage into tables, save data to storage from tables, and populate tables from the results
of running a query.
Create indexes for tables, and partition tables based on a clustered index so that each has a separate
metadata definition and can be handled separately.
Rename, alter and drop tables, and modify columns in a table as required.
Create views based on tables, and create functions for use in both tables and queries.
The main limitation of Hive tables is that you cannot create constraints such as foreign key relationships that
are automatically managed. For more details of how to work with Hive tables, see Hive Data Definition
Language on the Apache Hive website.
You can store the Hive queries and views within HDInsight so that they can be used to extract data on
demand in much the same way as the stored procedures in a relational database. However, to minimize
response times you will probably need to pre-process the data where possible using queries within your
solution, and store these intermediate results in order to reduce the time-consuming overhead of complex
queries. Incoming data may be processed by any type of query, not just Hive, to cleanse and validate the
data before converting it to table format.
You can use the Hive ODBC connector in SQL Server with HDInsight to create linked servers. This allows you
to write Transact-SQL queries that join tables in a SQL Server database to tables stored in an HDInsight data
warehouse.
If you want to be able to delete and restore the cluster, as is typically the case for this model, there are
additional considerations when creating a cluster. See Using external metadata stores for more information.
Next steps
HDInsight Architecture
Iterative Data Exploration
Upload data for Hadoop jobs in HDInsight
Using external metadata stores
ETL at Scale
8/16/2017 • 8 min to read • Edit Online
Extract, Transform and Load (ETL) is the process by which data is acquired from the various sources, collected in a
standard location, cleansed and processed and ultimately loaded into a datastore from which it can be queried.
Legacy ETL processes import data, clean it in place, and then store it in a relational data engine. With HDInsight, a
wide variety of Hadoop ecosystem components are enabled to support performing ETL, and due to the scalable
nature of HDInsight in terms of storage and processing, support performing ETL at scale.
The use of HDInsight in the ETL process can be summarized by this pipeline:
The sections that follow explore each of the ETL phases and the components utilized.
Orchestration
Spanning across all phases of the ETL pipeline is orchestration. ETL jobs in HDInsight often involved several
different products working in conjunction with each other. You might use Hive to clean some portion of the data,
while Pig cleans another portion. You might use Azure Data Factory to load data into Azure SQL Database from
Azure Data Lake Store.
Orechestration is needed to run the appropriate job at the appropriate time.
Oozie
Apache Oozie is a workflow/coordination system that manages Hadoop jobs. It runs within an HDInsight cluster
and is integrated with the Hadoop stack. It supports Hadoop jobs for Apache MapReduce, Apache Pig, Apache Hive,
and Apache Sqoop. It can also be used to schedule jobs that are specific to a system, such as Java programs or shell
scripts.
For more information, see Use Oozie with Hadoop to define and run a workflow on HDInsight
For a deep dive showing how to use Oozie to drive an end-to-end pipeline, see Operationalize the Data Pipeline
Azure Data Factory
Azure Data Factory provides orchestration capabilities in the form of platform-as-a-service. It is a cloud-based data
integration service that allows you to create data-driven workflows in the cloud for orchestrating and automating
data movement and data transformation. Using Azure Data Factory, you can create and schedule data-driven
workflows (called pipelines) that can ingest data from disparate data stores, process/transform the data by using
compute services such as Azure HDInsight Hadoop, Spark, Azure Data Lake Analytics, Azure Batch, and Azure
Machine Learning, and publish output data to data stores such as Azure SQL Data Warehouse for business
intelligence (BI) applications to consume.
For more information on Azure Data Factory, see the documentation.
Transform
Once data exists in the chosen location, we need to actually clean it, combine it, or prepare it for a specific usage
pattern. Hive, Pig, and Spark SQL are all very good choices for that kind of work. They are all supported on
HDInsight.
See Using Apache Hive as an ETL Tool for more information on Hive.
See Use Pig with Hadoop on HDInsight for more information on Pig.
Streaming at Scale
8/16/2017 • 5 min to read • Edit Online
Many of today's Big Data solutions must act on data in motion at any given point in time. In other words, realtime
streaming data. In most cases, this data is most valuable at its time of arrival. Being able to quickly scale your
solution by adding nodes on demand can be the difference between missing out on incoming information and
making a key decision.
To ease the process of scaling streaming platforms, HDInsight offers an elegant scale model without the need to
throttle your resources. All of the necessary steps are handled for you when scaling is performed through the
HDInsight utilities.
displayed in real-time on a business intelligence dashboard, such as Power BI, Tableau, or a custom web page.
Apache Kafka
Apache Kafka provides high throughput, low-latency message queueing service, originally developed at LinkedIn,
and is now part of the Apache suite of Open Source Software (OSS). It uses a publish and subscribe messaging
model and stores streams of partitioned data safely in a distributed, replicated cluster. When needed, it scales
linearly as throughput increases.
Read Introducing Apache Kafka on HDInsight (preview) for more information.
Apache Storm
Apache Storm is one of the stream processing engines we displayed in the first and second diagram at the top of
this article. In summary, it is a distributed, fault-tolerant, open-source computation system that is optimized for
processing streams of data in real time with Hadoop. The core unit of data for an event is in the form of a Tuple,
which is an immutable set of key/value pairs. An unbounded sequence of these Tuples form a Stream, which is
provided by a Spout. The Spout wraps a streaming data source (such as Kafka), and emits Tuples. A storm
Topology is a sequence of transformations on these streams.
Read What is Apache Storm on Azure HDInsight? for more information.
Deploy a new Azure virtual network with Kafka and Storm clusters:
Spark Streaming
The other stream processing engine we displayed in the diagram was Spark Streaming. Since it is an extension to
Spark, Spark Streaming allows you to reuse the same code that you use for batch processing, and even allows you
to combine both batch and interactive queries in the same application. Unlike Storm, Spark Streaming provides
stateful exactly-once processing semantics out of the box. When used in combination with the Kafka Direct API,
which ensures that all Kafka data is received by Spark Streaming exactly once, it is possible to achieve end-to-end
exactly-once gurantees. One of Spark Streaming's strengths is its fault-tolerant capabilities, recovering faulted
nodes rapidly when multiple nodes are being used within the cluster.
Read What is Spark Streaming? for more information.
Use the following button to deploy a new Azure virtual network, Kafka, and Spark clusters to your Azure
subscription:
Scale
Although you can specify the number of nodes in your cluster during creation, you may want to grow or shrink the
cluster to match workload. All HDInsight clusters allow you to change the number of nodes in the cluster. Also,
Spark clusters can be dropped with no loss of data since all the data is stored in Azure Storage or Data Lake Store.
Scaling the Stream Buffering layer
There are advantages to decoupling technologies as we've shown in the first two diagrams. For instance, since
Kafka is an event buffering technology, it is very IO-heavy and does not need a lot of processing power. The stream
processors such as Spark Streaming, on the other hand, are very compute-heavy, requiring more powerful VMs by
comparison. By having these technologies decoupled into different clusters, you can scale them independently and
also use correctly sized VMs within those clusters for cost savings.
The two options we've shown for handling the stream buffering tasks, Event Hubs and Kafka, both use partitions,
and consumers read from the those partitions. Scaling the input throughput means scaling up the number of
partitions. Adding partitions means increasing parallelism. In Event Hubs, the partition count cannot be changed
after deployment so it is important to start with the target scale in mind. With Kafka, it is possible to add partitions,
even while it is processing data. Kafka provides a tool to reassign partitions, called [Link] .
As mentioned earlier in this article, HDInsight provides a partition replica rebalancing tool, called
rebalance_rackaware.py . Under the covers, this tool executes the [Link] tool, but does so in
such a way that each replica is in a separate fault domain and update domain, making Kafka rack aware, increasing
fault tolerance as well as rebalancing the partitions.
Scaling the Stream Processing layer
Focusing on HDInsight for the topic of scaling the stream processors, both Apache Storm and Spark Streaming
support adding worker nodes to their clusters, even while data is being processed.
To take advantage of new nodes added through scaling when using Storm, you need to rebalance any Storm
topologies started before the cluster size was increased. This can be performed through the Storm web UI or the
Command-line interface (CLI) tool. Refer to the Apache Storm documentation for more details.
Apache Spark uses three key parameters for configuring its environment, depending on application requirements:
[Link] , [Link] , and [Link] . An Executor is a process that is
launched for a Spark application. It runs on the worker node and is responsible for carrying out the tasks for the
application. The default number of executors and the executor sizes for each cluster is calculated based on the
number of worker nodes and the worker node size. These are stored in the [Link] on the cluster
head nodes.
The three configuration parameters can be configured at the cluster level (for all applications that run on the
cluster) or can be specified for each individual application as well. Detailed information on these settings and how
to manage the configuration can be found within the Managing resources for Apache Spark cluster on Azure
HDInsight article.
Next steps
Learn more about real-time analytics solutions with Storm and Apache Spark on HDInsight:
Get started with Apache Storm on HDInsight
Example topologies for Apache Storm on HDInsight
Introduction to Spark on HDInsight
Start with Apache Kafka on HDInsight
Machine learning on HDInsight
8/16/2017 • 4 min to read • Edit Online
HDInsight enables machine learning against big data, providing the ability to obtain valuable insight from large
(petabytes, or even exabytes) of structured, unstructured, and fast-moving data. There are several machine learning
options that run in HDInsight:
R
R is currently the most popular statistical programming language in the world. It is an open source data
visualization tool with a community of over 2.5 million users and growing. Given its thriving user base, and over
8,000 contributed packages, R is the natural choice for many companies who require machine learning. As part of
HDInsight, you can now create an HDInsight cluster with R Server ready to be used with massive datasets and
models. This new capability provides data scientists and statisticians with a familiar R interface that can scale on-
demand through HDInsight, without the overhead of cluster setup and maintenance.
The edge node of a cluster provides a convenient place to connect to the cluster and to run your R scripts. You also
have the option to run them across the nodes of the cluster by using ScaleR’s Hadoop Map Reduce or Spark
compute contexts.
Using R Server on HDInsight with Spark, you can parallelize training across the nodes of a cluster by using a Spark
compute context. You can run R scripts directly on the edge node, using all available cores in parallel, if desired.
Alternately, you can run your code from the edge node to kick off processing that is distributed across all nodes in
the cluster. R Server on HDInsight with Spark also enables parallelizing functions from open source R packages, if
desired.
Azure Machine Learning provides tools to model predictive analytics, as well as a fully managed service you can
use to deploy your predictive models as ready-to-consume web services. Azure Machine Learning provides tools
for creating complete predictive analytics solutions in the cloud to quickly create, test, operationalize, and manage
predictive models. You do not need to buy any hardware nor manually manage virtual machines. Select from a
large algorithm library, use a web-based studio for building models, and easily deploy your model as a web service.
Create features for data in an HDInsight Hadoop cluster using Hive queries. Feature engineering attempts to
increase the predictive power of learning algorithms by creating features from raw data that help facilitate the
learning process. You can run HiveQL queries from Azure ML, and access data processed in Hive and stored in blob
storage, by using the Import Data module.
Deep learning
Deep learning is a branch of machine learning that uses deep neural networks, inspired by the biological processes
of the human brain. Many researchers see deep learning as a very promising approach for making artificial
intelligence better. Some examples of deep learning are spoken language translators, image recognition systems,
and machine reasoning.
To help advance its own work in deep learning, Microsoft has developed the free, easy-to-use, open-source
Microsoft Cognitive Toolkit. The toolkit is being used extensively by a wide variety of Microsoft products, by
companies worldwide with a need to deploy deep learning at scale, and by students interested in the very latest
algorithms and techniques.
See also
Scenarios
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Generate movie recommendations with Mahout
Hive and Azure Machine Learning
Hive and Azure Machine Learning end-to-end
Machine learning with Spark on HDInsight
Deep learning resources
Deep learning toolkit with Spark
Embarrassingly parallel image classification with Cognitive toolkit + Tensorflow on Spark
Achieving Batch & Interactive with Hadoop & Spark
8/16/2017 • 24 min to read • Edit Online
Hadoop and Spark on HDInsight provide various data processing options, from real-time stream processing, to
complicated batch processing that can take from tens of minutes to days to complete. Interactive querying means
querying batch data at "human" interactive speeds, meaning results are ready in time frames measured in seconds
to minutes. The purpose of this article is to introduce batch and interactive query processing concepts, and how
Hadoop and Spark help you achieve those goals.
The map function splits the contents of the text input into an array of strings using anything that is not an
alphabetic character as a word delimiter. Each string in the array is then used as the key of a new key/value pair
with the value set to 1.
Each key/value pair generated by the map function is passed to the reduce function, which sums the values in
key/value pairs that have the same key. Working together, the map and reduce functions determine the total
number of times each unique word appeared in the source data, as shown here:
Aardvark 2
About 7
Above 12
Action 3
...
This diagram shows how streaming executes the map and reduce components as separate processes. The
schematic does not attempt to illustrate all of the standard map/reduce stages, such as sorting and merging the
intermediate results or using multiple instances of the reduce component.
When using Hadoop Streaming, each node passes the data for the map part of the process to a separate process
through the standard input ( stdin ), and accepts the results from the code through the standard output ( stdout ),
instead of internally invoking a map component written in Java. In the same way, the node(s) that execute the
reduce process pass the data as a stream to the specified code or component, and accept the results from the code
as a stream, instead of internally invoking a Java reduce component.
Streaming has the advantage of decoupling the map/reduce functions from the Hadoop core, allowing almost any
type of components to be used to implement the mapper and the reducer. The only requirement is that the
components must be able to read from and write to the standard input and output.
Using the streaming interface does have a minor impact on performance. The additional movement of the data
over the streaming interface can marginally increase query execution time. Streaming tends to be used mostly to
enable the creation of map and reduce components in languages other than Java. It is quite popular when using
Python, and also enables the use of .NET languages such as C# and F# with HDInsight.
For more information, see Hadoop Streaming.
For more information on using Hadoop MapReduce on HDInsight, see Use MapReduce in Hadoop on HDInsight
For examples of using Hadoop streaming with HDInsight, see the following documents:
Develop C# MapReduce jobs
Develop Python MapReduce jobs
Batch processing using Hive
Hive uses tables to impose a schema on data, and to provide a query interface for client applications. The key
difference between Hive tables and those in traditional database systems, such as SQL Server, is that Hive adopts a
"schema on read" (as mentioned earlier in the article) approach that enables you to be flexible about the specific
columns and data types that you want to project onto your data.
Hive supports most of the data types you would expect ( bigint , binary , boolean , char , decimal , double ,
float , int , smallint , string , timestamp , and tinyint ), but also has specialized support for arrays, maps,
and structs.
You can create multiple tables with different schemas from the same underlying data, depending on how you want
to use that data. You can also create views and indexes over Hive tables, and partition tables. Moving data into a
Hive-controlled namespace is usually an instantaneous operation.
You can use the Hive command line on the HDInsight cluster to work with Hive tables, and build an automated
solution that includes Hive queries by using the HDInsight .NET SDKs and with a range of Hadoop-related tools
such Oozie and WebHCat. You can also use the Hive ODBC driver to connect to Hive from any ODBC-capable client
application.
In addition to its more usual use as a querying mechanism, Hive can be used to create a simple data warehouse
containing table definitions applied to data that you have already processed into the appropriate format. Azure
storage is relatively inexpensive, and so this is a good way to create a commodity storage system when you have
huge volumes of data.
Hive queries are written in HiveQL (see HiveQL language reference), which is a query language similar to SQL. Here
are a few example queries for different scenarios:
Creating a table
You create tables by using the HiveQL CREATE TABLE statement, which in its simplest form looks similar to the
equivalent statement in Transact-SQL. You specify the schema in the form of a series of column names and types,
and the type of delimiter that Hive will use to delineate each column value as it parses the data. You can also specify
the format for the files in which the table data will be stored if you do not want to use the default format (where
data files are delimited by an ASCII code 1 (Octal \001) character, equivalent to Ctrl + A). For example, the following
code creates a table named mytable and specifies that the data files for the table should be tab-delimited.
Hive tables are simply metadata definitions imposed on data in underlying files. By default, Hive stores table data in
the user/hive/warehouse/table_name path in storage (the default path is defined in the configuration property
[Link] ), so the previous code sample will create the table metadata definition and an empty
folder at user/hive/warehouse/mytable. When you delete the table by executing the DROP TABLE statement, Hive
will delete the metadata definition from the Hive database and it will also remove the
user/hive/warehouse/mytable folder and its contents.
However, you can specify an alternative path for a table by including the LOCATION clause in the CREATE TABLE
statement. The ability to specify a non-default location for the table data is useful when you want to enable other
applications or users to access the files outside of Hive. This allows data to be loaded into a Hive table simply by
copying data files of the appropriate format into the folder, or downloaded directly from storage. When the table is
queried using Hive, the schema defined in its metadata is automatically applied to the data in the files.
An additional benefit of specifying the location is that this makes it easy to create a table for data that already exists
in that location (perhaps the output from a previously executed map/reduce job or Pig script). After creating the
table, the existing data in the folder can be retrieved immediately with a HiveQL query.
However, one consideration for using managed tables is that, when the table is deleted, the folder it references will
also be deleted — even if it already contained other data files when the table was created. If you want to manage
the lifetime of the folder containing the data files separately from the lifetime of the table, you must use the
EXTERNAL keyword in the CREATE TABLE statement to indicate that the folder will be managed externally from Hive,
as shown in the following code sample:
When designing an overall data processing solution with HDInsight, you may choose to perform complex
processing logic in custom MapReduce components or Pig scripts and then create a layer of Hive tables over the
results of the earlier processing, which can be queried by business users who are familiar with basic SQL syntax.
However, you can use Hive for all processing, in which case some queries may require logic that is not possible to
define in standard HiveQL functions.
In addition to common SQL semantics, HiveQL supports the use of:
Custom MapReduce scripts embedded in a query through the MAP and REDUCE clauses.
Custom user-defined functions (UDFs) that are implemented in Java, or that call Java functions available in the
existing installed libraries.]
XPath functions for parsing XML data using XPath.
This extensibility enables you to use HiveQL to perform complex transformations on data as it is queried. To help
you decide on the right approach, consider the following guidelines:
If the source data must be extensively transformed using complex logic before being consumed by business
users, consider using custom MapReduce components or Pig scripts to perform most of the processing, and
create a layer of Hive tables over the results to make them easily accessible from client applications.
If the source data is already in an appropriate structure for querying and only a few specific but complex
transforms are required, consider using MapReduce scripts embedded in HiveQL queries to generate the
required results.
If queries will be created mostly by business users, but some complex logic is still regularly required to generate
specific values or aggregations, consider encapsulating that logic in custom UDFs because these will be simpler
for business users to include in their HiveQL queries than a custom MapReduce script.
For more information on Hive and HiveQL, see What is Apache Hive and HiveQL on Azure HDInsight?.
Batch processing using Pig
Pig Latin syntax has some similarities to LINQ, and encapsulates many functions and expressions that make it easy
to create a sequence of complex data transformations with just a few lines of simple code. Pig Latin is a good choice
for creating relations and manipulating sets, and for working with unstructured source data. You can always create
a Hive table over the results of a Pig Latin query if you want table format output. However, the syntax of Pig Latin
can be complex for non-programmers to master. Pig Latin is not as familiar or as easy to use as HiveQL, but Pig can
achieve some tasks that are difficult, or even impossible, when using Hive.
You can run Pig Latin statements interactively in the Hadoop command line window or in a command line Pig shell
named Grunt. You can also combine a sequence of Pig Latin statements in a script that can be executed as a single
job, and use user-defined functions you previously uploaded to HDInsight. The Pig Latin statements are used by the
Pig interpreter to generate jobs, but the jobs are not actually generated and executed until you call either a DUMP
statement (which is used to display a relation in the console, and is useful when interactively testing and debugging
Pig Latin code) or a STORE statement (which is used to store a relation as a file in a specified folder).
Pig scripts generally save their results as text files in storage, where they can easily be viewed on demand, perhaps
by using the Hadoop command line window. However, the results can be difficult to consume or processes in client
applications unless you copy the output files and import them into client tools such as Excel.
Executing a Pig script
As an example of using Pig, suppose you have a tab-delimited text file containing source data similar to the
following:
Value1 1
Value2 3
Value3 2
Value1 4
Value3 6
Value1 2
Value2 8
Value2 5
You could process the data in the source file with the following simple Pig Latin script:
This script loads the tab-delimited data into a relation named A, imposing a schema that consists of two columns:
col1, which uses the default byte array data type, and col2, which is a long integer. The script then creates a
relation named B, in which the rows in A are grouped by col1, and then creates a relation named C, in which the
col2 value is aggregated for each group in B.
After the data has been aggregated, the script creates a relation named D, in which the data is sorted based on the
total that has been generated. The relation D is then stored as a file in the /mydata/results folder, which contains
the following text:
Value1 7
Value3 8
Value2 16
For more information about the Pig Latin syntax, see Pig Latin Reference Manual 1 and Pig Latin Reference Manual
2.
See Use Pig with Hadoop on HDInsight for more information on using Pig on HDInsight.
Batch processing using Spark
Apache Spark running on HDInsight provides another avenue for batch processing. Spark is a unified framework,
meaning that you can use the same code for both batch processing and realtime stream processing. The underlying
components of Spark are Spark Core and the RDD API, which let you perform parallel operations on Spark's
distributed data. Atop this sits the Spark SQL module, which provides the DataFrame API and DataSet API as well as
support for issuing SQL queries directly against the DataFrame API.
A DataFrame is a distributed collection of data organized into named columns. It is important to note that the
columns are named only, not typed. DataFrames are conceptually equivalent to a table in a relational database or a
data frame in R/Python, but with richer optimizations under the hood. They can be constructed from a wide array of
sources such as: structured data files, tables in Hive, external databases, or existing RDDs. The DataFrame API is
available in Scala, Java, and Python.
DataFrames and DataSets are higher-level abstractions that improve batch processing efforts due to their
expressiveness and higher performance over raw RDD APIs.
Learn more about using Spark with HDInsight, including for batch processing.
The query creates an index on the purchasetype and paymentamount columns. The CompactIndexHandler is the Java
class that implements indexing. The WITH DEFERRED REBUILD statement creates an empty index. It has to be rebuilt
later.
To manually populate the index, execute the following, using the ALTER INDEX and REBUILD statements:
Note: The above query populates the index_total_sales with data. To verify, navigate to your Azure Storage account
on the Azure Portal, and search index_total_sales in the bookstore container.
Indexes are also automatically created when using the ORC file format, as recommended earlier. The ORC file
format is a column-oriented storage format that is an optimized version of RC file format. It provides much better
compression and faster query performance than the RC file format. ORC file format groups row data into stripes,
with stripe metadata stored in a file footer. The default stripe size is 250 MB.
The file footer contains a list of stripes, number of rows per stripe, and column data type. It also contains
lightweight indexes with column-level aggregations sum , max , min , and count . At the end of the file, a postscript
contains compression parameters and size of the compressed footer.
Partitioning
Hive allows for splitting data into two or more horizontal partitions based on column values. This improves queries
that filter data on specific column values. This, in effect, also helps you to prune large data sets, resulting in faster
query times. The reason for this, is that when you partition your data, the ORC files are stored in the filesystem
under the partition's respective name. For example, if you partition by state, then queries for "California" search
within that state's directory, ignoring all of the other directories' worth of data files during the query processing
step.
The above query creates an ORC format table partitioned on the state and city columns. With dynamic partitioning
enabled, Hive automatically creates partitions based on the specified column values. The setting
[Link] = non-strict indicates there are no static partitions and all partitions are
dynamic. If a table has both dynamic and static partitions, [Link] should be set to
strict .
4. Click on the toggle switch to enable the Interactive Query. Click Save on the version control bar to save the
changes made.
Please note, this feature is currently in preview and is not officially supported.
Spark SQL enables you to run unmodified Hive queries on existing data. It reuses the Hive frontend and
metastore, giving users full compatibility with existing Hive data, queries, and UDFs.
Indexes
Spark SQL does not yet support indexes, at this time. This includes Hive table indexes, meaning if you use a
HiveContext in Spark to query a Hive table that has explicit indexes, they will not be used in the query processing.
However, as with Hive, you can take advantage of the automatically created inline indexes generated by ORC files
when you save your data in that format.
Partitions
Partitioning in Spark SQL works in the same way as with Hive (as detailed under "Interactive querying using Hive
and Tez" above), creating subfolders named after the column partition with the related values stored within. This
effectively prunes the data by excluding entire directories-worth of data when querying by partition. You can
partition your DataFrame by using the partitionBy method prior to invoking the save method:
[Link]("orc").partitionBy("state").save("mydata")
The partitionBy method accepts a list of column names by which to partition the data. In this case, we're
partitioning by the "state" column.
Next steps
In this article, we covered the various options by which we can perform batch processing and interactive querying,
using Hadoop and Spark on HDInsight. Learn more about the batch and interactive processing by following the
links below:
Batch processing through Iterative data exploration
Batch processing with Data warehouse on demand
Learn more about ETL with the ETL deep dive and ETL at scale
Batch processing with MapReduce in Hadoop on HDInsight
More about Hive and HiveQL on Azure HDInsight
Use Pig with Hadoop on HDInsight for batch processing
Overview of Spark on HDInsight
See Changing configs via Ambari for recommended performance settings
See Use Interactive Hive in HDInsight (Preview) for LLAP
Learn more about Apache Spark with Spark scenarios, Spark SQL with HDInsight, and Spark-specific
performance enhancements with Spark settings
Run Custom Programs
8/16/2017 • 6 min to read • Edit Online
Hadoop-based big data systems such as HDInsight enable data processing using a wide range of tools and
technologies. This article provides comparisons between the commonly used tools and technologies to help you
choose the most appropriate for your own scenarios, then goes into detail on how to run custom map/reduce
programs.
The following table shows the main advantages and considerations for each one.
Hive using HiveQL An excellent solution for batch It requires the source data to
processing and analysis of large have at least some identifiable
amounts of immutable data, for structure.
data summarization, and for ad It is not suitable for real-time
hoc querying. It uses a familiar queries and row level updates. It
SQL-like syntax. is best used for batch jobs over
It can be used to produce large sets of data.
persistent tables of data that can It might not be able to carry out
be easily partitioned and some types of complex
indexed. processing tasks.
Multiple external tables and
views can be created over the
same data.
It supports a simple data
warehouse implementation that
provides massive scale out and
fault tolerance capabilities for
data storage and processing.
Pig using Pig Latin An excellent solution for SQL users may find Pig Latin is
manipulating data as sets, less familiar and more difficult to
merging and filtering datasets, use than HiveQL.
applying functions to records or The default output is usually a
groups of records, and for text file and so it is more difficult
restructuring data by defining to use with visualization tools
columns, by grouping values, or such as Excel. Typically you will
by converting columns to rows. layer a Hive table over the
It can use a workflow-based output.
approach as a sequence of
operations on data.
QUERY MECHANISM ADVANTAGES CONSIDERATIONS
Custom map/reduce It provides full control over the It is more difficult than using Pig
map and reduce phases and or Hive because you must create
execution. your own map and reduce
It allows queries to be optimized components.
to achieve maximum Processes that require the
performance from the cluster, or joining of sets of data are more
to minimize the load on the difficult to implement.
servers and the network. Even though there are test
The components can be written frameworks available, debugging
in a range of widely known code is more complex than a
languages that most developers normal application because they
are likely to be familiar with. run as a batch job under the
control of the Hadoop job
scheduler.
Apache Spark One execution model for Does not handle a large number
multiple tasks: Apache Spark of small files well.
leverages a common execution Requires more compute power
model for doing multiple tasks compared to some other
like ETL, batch queries, options, due to in-memory
interactive queries, real-time processing. The need for extra
streaming, machine learning, RAM could cause Spark
and graph processing on data solutions to be more costly,
stored in Azure Storage. depending upon the nature of
In-memory processing for your data.
interactive scenarios: Apache
Spark persists data in-memory
and disk if needed to achieve up
to 100x faster queries while
processing large datasets in
Hadoop. This makes Spark for
Azure HDInsight ideal to speed
up intensive big data
applications.
Developer friendly: Spark
supports a variety of
development languages like
Java, Python, and Scala APIs to
ease development. You can write
sophisticated parallel
applications with a collection of
over 80 operators, allowing
developers to rapidly iterate
over data.
Typically, you will use the simplest of these approaches that can provide the results you require. For example, it
may be that you can achieve these results by using just Hive, but for more complex scenarios you may need to use
Pig or even write your own map and reduce components. You may also decide, after experimenting with Hive or
Pig, that custom map and reduce components can provide better performance by allowing you to fine tune and
optimize the processing.
Replace USERNAME with the SSH user account for your cluster. Replace CLUSTERNAME with the cluster name. If
you used a password to secure the SSH account, you are prompted to enter the password. If you used a certificate,
you may need to use the -i parameter to specify the private key file.
Next, connect to the cluster using SSH.
ssh USERNAME@[Link]
From the SSH session, execute your MapReduce program through YARN.
This command submits the MapReduce job to YARN. The input file is /example/data/[Link] , and the output
directory is /example/data/logoutput . Both the input file and the output file(s) are stored to the default storage for
the cluster.
Next steps
This article introduced the landscape of commonly used tools that can be used to process your data, ending off with
detailing how to run custom MapReduce programs. Learn more about the various available data processing tools,
and methods to create and run custom programs that use them, by following the links below.
Use C# with MapReduce streaming on Hadoop in HDInsight
Develop Java MapReduce programs for Hadoop on HDInsight
Develop Python streaming MapReduce programs for HDInsight
Use Azure Toolkit for Eclipse to create Spark applications for an HDInsight cluster
Use Python User Defined Functions (UDF) with Hive and Pig in HDInsight
Upload data for Hadoop jobs in HDInsight
8/16/2017 • 10 min to read • Edit Online
Azure HDInsight provides a full-featured Hadoop distributed file system (HDFS) over Azure Blob storage. It is
designed as an HDFS extension to provide a seamless experience to customers. It enables the full set of
components in the Hadoop ecosystem to operate directly on the data it manages. Azure Blob storage and HDFS
are distinct file systems that are optimized for storage of data and computations on that data. For information
about the benefits of using Azure Blob storage, see Use Azure Blob storage with HDInsight.
Prerequisites
Note the following requirement before you begin:
An Azure HDInsight cluster. For instructions, see Get started with Azure HDInsight or Provision HDInsight
clusters.
Command-line utilities
Microsoft provides the following utilities to work with Azure Blob storage:
Azure Command-Line ✔ ✔ ✔
Interface
Azure PowerShell ✔
TOOL LINUX OS X WINDOWS
AzCopy ✔
Hadoop command ✔ ✔ ✔
NOTE
While the Azure CLI, Azure PowerShell, and AzCopy can all be used from outside Azure, the Hadoop command is only
available on the HDInsight cluster and only allows loading data from the local file system into Azure Blob storage.
Azure CLI
The Azure CLI is a cross-platform tool that allows you to manage Azure services. Use the following steps to
upload data to Azure Blob storage:
[! IMPORTANT] Azure CLI support for managing HDInsight resources using Azure Service Manager (ASM) is
deprecated, and was removed on January 1, 2017. The steps in this document use the new Azure CLI
commands that work with Azure Resource Manager.
Please follow the steps in Install and configure Azure CLI to install the latest version of the Azure CLI. If you have
scripts that need to be modified to use the new commands that work with Azure Resource Manager, see
Migrating to Azure Resource Manager-based development tools for HDInsight clusters for more information.
1. Install and configure the Azure CLI for Mac, Linux and Windows.
2. Open a command prompt, bash, or other shell, and use the following to authenticate to your Azure
subscription.
azure login
When prompted, enter the user name and password for your subscription.
3. Enter the following command to list the storage accounts for your subscription:
4. Select the storage account that contains the blob you want to work with, then use the following command
to retrieve the key for this account:
This should return Primary and Secondary keys. Copy the Primary key value because it will be used in
the next steps.
5. Use the following command to retrieve a list of blob containers within the storage account:
6. Use the following commands to upload and download files to the blob:
To upload a file:
azure storage blob upload -a <storage-account-name> -k <primary-key> <source-file>
<container-name> <blob-name>
To download a file:
NOTE
If you will always be working with the same storage account, you can set the following environment variables instead of
specifying the account and key for every command:
AZURE_STORAGE_ACCOUNT: The storage account name
AZURE_STORAGE_ACCESS_KEY: The storage account key
Azure PowerShell
Azure PowerShell is a scripting environment that you can use to control and automate the deployment and
management of your workloads in Azure. For information about configuring your workstation to run Azure
PowerShell, see Install and configure Azure PowerShell.
IMPORTANT
Azure PowerShell support for managing HDInsight resources using Azure Service Manager is deprecated, and was
removed on January 1, 2017. The steps in this document use the new HDInsight cmdlets that work with Azure Resource
Manager.
Please follow the steps in Install and configure Azure PowerShell to install the latest version of Azure PowerShell. If you
have scripts that need to be modified to use the new cmdlets that work with Azure Resource Manager, see Migrating to
Azure Resource Manager-based development tools for HDInsight clusters for more information.
$resourceGroupName = "<AzureResourceGroupName>"
$storageAccountName = "<StorageAccountName>"
$containerName = "<ContainerName>"
$fileName ="<LocalFileName>"
$blobName = "<BlobName>"
3. Paste the script into the Azure PowerShell console to run it to copy the file.
For example PowerShell scripts created to work with HDInsight, see HDInsight tools.
AzCopy
AzCopy is a command-line tool that is designed to simplify the task of transferring data into and out of an Azure
Storage account. You can use it as a standalone tool or incorporate this tool in an existing application. Download
AzCopy.
The AzCopy syntax is:
For more information, see AzCopy - Uploading/Downloading files for Azure Blobs.
Hadoop command line
The Hadoop command line is only useful for storing data into blob storage when the data is already present on
the cluster head node.
In order to use the Hadoop command, you must first connect to the headnode using one of the following
methods:
Windows-based HDInsight: Connect using Remote Desktop
Linux-based HDInsight: Connect using SSH (the SSH command or PuTTY)
Once connected, you can use the following syntax to upload a file to storage.
Because the default file system for HDInsight is in Azure Blob storage, /example/[Link] is actually in Azure Blob
storage. You can also refer to the file as:
wasb:///example/data/[Link]
or
wasb://<ContainerName>@<StorageAccountName>.[Link]/example/data/[Link]
For a list of other Hadoop commands that work with files, see [Link]
project-dist/hadoop-common/[Link]
WARNING
On HBase clusters, the default block size used when writing data is 256KB. While this works fine when using HBase APIs or
REST APIs, using the hadoop or hdfs dfs commands to write data larger than ~12GB results in an error. See the
storage exception for write on blob section below for more information.
Graphical clients
There are also several applications that provide a graphical interface for working with Azure Storage. The
following is a list of a few of these applications:
CLIENT LINUX OS X WINDOWS
CloudXplorer ✔
Azure Explorer ✔
Cyberduck ✔ ✔
2. In the list of containers to the left of the interface, click the name of the container that is associated with your
HDInsight cluster. By default, this is the name of the HDInsight cluster, but may be different if you entered a
specific name when creating the cluster.
3. From the tool bar, select the upload icon.
4. Specify a file to upload, and then click Open. When prompted, select Upload to upload the file to the root
of the storage container. If you want to upload the file to a specific path, enter the path in the Destination
field and then select Upload.
Once the file has finished uploading, you can use it from jobs on the HDInsight cluster.
Services
Azure Data Factory
The Azure Data Factory service is a fully managed service for composing data storage, data processing, and data
movement services into streamlined, scalable, and reliable data production pipelines.
Azure Data Factory can be used to move data into Azure Blob storage, or to create data pipelines that directly use
HDInsight features such as Hive and Pig.
For more information, see the Azure Data Factory documentation.
Apache Sqoop
Sqoop is a tool designed to transfer data between Hadoop and relational databases. You can use it to import data
from a relational database management system (RDBMS), such as SQL Server, MySQL, or Oracle into the
Hadoop distributed file system (HDFS), transform the data in Hadoop with MapReduce or Hive, and then export
the data back into an RDBMS.
For more information, see Use Sqoop with HDInsight.
Development SDKs
Azure Blob storage can also be accessed using an Azure SDK from the following programming languages:
.NET
Java
[Link]
PHP
Python
Ruby
For more information on installing the Azure SDKs, see Azure downloads
Troubleshooting
Storage exception for write on blob
Symptoms: When using the hadoop or hdfs dfs commands to write files that are ~12GB or larger on an HBase
cluster, you may encounter the following error:
Cause: HBase on HDInsight clusters default to a block size of 256KB when writing to Azure storage. While this
works for HBase APIs or REST APIs, it will result in an error when using the hadoop or hdfs dfs command-line
utilities.
Resolution: Use [Link] to specify a larger block size. You can do this on a per-use basis
by using the -D parameter. The following is an example using this parameter with the hadoop command:
You can also increase the value of [Link] globally by using Ambari. The following steps
can be used to change the value in the Ambari Web UI:
1. In your browser, go to the Ambari Web UI for your cluster. This is
[Link] where CLUSTERNAME is the name of your cluster.
When prompted, enter the admin name and password for the cluster.
2. From the left side of the screen, select HDFS, and then select the Configs tab.
3. In the Filter... field, enter [Link] . This will display the field and current value in the
middle of the page.
4. Change the value from 262144 (256KB) to the new value. For example, 4194304 (4MB).
For more information on using Ambari, see Manage HDInsight clusters using the Ambari Web UI.
Next steps
Now that you understand how to get data into HDInsight, read the following articles to learn how to perform
analysis:
Get started with Azure HDInsight
Submit Hadoop jobs programmatically
Use Hive with HDInsight
Use Pig with HDInsight
HDInsight Architecture
8/16/2017 • 13 min to read • Edit Online
An HDInsight cluster consists of several linux Azure Virtual Machines (nodes) that are used for distributed
processing of tasks. Azure HDInsight handles implementation details of installation and configuration of individual
nodes, so you only have to provide general configuration information. An HDInsight cluster is deloyed by first
selecting a cluster type, which determines what components are installed and the specific topology of virtual
machines that is deployed.
This article describes all of the available cluster types, their constituent nodes, the services the nodes run, as well
the network and data storage architectures.
Cluster types
Azure HDInsight currently provides the following cluster types, each with a set of components that provide certain
functionalities.
IMPORTANT
HDInsight clusters are available in various types, each for a single workload or technology. There is no supported method to
create a cluster that combines multiple types, such as Storm and HBase on one cluster. If your solution requires
technologies that are spread across multiple HDInsight cluster types, an Azure virtual network can connect the required
cluster types.
Interactive Hive (Preview) In-memory caching for interactive and faster Hive queries,
leveraging Live Long and Process (LLAP) technology. See Use
Interactive Hive in HDInsight.
Node types
Each cluster type may contain different types of nodes that have a specific purpose in the cluster. The following
table summarizes these node types.
TYPE DESCRIPTION
Head node For the Hadoop, Interactive Hive, Kafka, Spark, HBase and R
Server cluster types, the head nodes hosts the processes that
manage execution of the distributed application. In addition,
for the Hadoop, Interactive Hive, Kafka, Spark, and HBase
cluster types the head node represents the node you can SSH
into and execute applications that are then coordinated to
run across the cluster resources. The number of head nodes is
fixed at two for all cluster types.
Nimbus node For the Storm cluster type, the Nimbus node provides
functionality similar to the Head node. The Nimbus node
assigns tasks to other nodes in a cluster through Zookeeper-
it coordinates the running of Storm topologies.
ZooKeeper node Represents the nodes hosting the ZooKeeper process and
data, which is used to coordinate tasks between the nodes
performing the processing, leader election of the head node,
and for keeping track of on which head node a master service
is active on. The number of ZooKeeper nodes is fixed at two
for all cluster types having ZooKeeper nodes.
R Server Edge node The R Server Edge node represents the node you can SSH
into and execute applications that are then coordinated to
run across the cluster resources. An edge node itself does not
actively participate in data analysis within the cluster. In
addition, this node hosts R Studio Server, enabling you to run
R application using a browser.
Region node For the HBase cluster type, the region node (also referred to
as a Data Node) runs the Region Server that is responsible for
serving and managing a portion of the data managed by
HBase. Region nodes can be added or removed from the
cluster to increase or decrease computing capability and to
manage costs.
Supervisor node For the Storm cluster type, the supervisor node executes the
instructions provided by the Nimbus node to peforming the
desired processing.
ZooKeeper
Apache ZooKeeper provides services that are core to the operation of a cluster: a distributed configuration service,
a synchronization service and a naming registry for distributed services. Many of the HDInsight cluster types rely
on ZooKeeper for the coordination of processes in the cluster, the sharing of configuration and for coordinating
the election of the primary head node.
ZooKeeper coordinates processes in large distributed systems using a shared hierarchical namespace of data
registers known as znodes. The hierarchical structure is similar to a filesystem consisting of folders and files.
Correspondingly, each znode is identified by a path, where the root is "/" and path elements are further
separeated by a slash (such as /myapplication/settings). Znodes contain small amounts of metadata needed to
coordinate processes: status, location, configuration, and so on.
Clients, typically processes running in the Head and Worker nodes of the HDInsight cluster, establish bi-directional
TCP connections with ZooKeeper and get high-throughput, high availability and low latency access to the data it
manages. ZooKeeper is designed to be fast for read heavy workloads, such as might be expected when nodes in
the cluster are retrieving settings or are looking up the name of a service.
ZooKeeper replicates it data in HDInsight over three nodes to ensure there is no single point of failure. The data
managed by ZooKeeper is maintained in an in-memory database where updates are logged to disk for
recoverability, and writes are serialized to disk before they are applied. Clients can connect to any of the
ZooKeeper nodes and are guaranteed to see the same view of the data regardless of the node to which they
connect.
In addition to an OS disk and a temp disk, Azure Virtual Machines support data disks. A data disk is a VHD that's
attached to a virtual machine to store application data, or other data you need to keep. In general, the VMs in an
HDInsight cluster do not support the attachment of data disks, although there are some exceptions as show in the
table.
All other cluster types Only OS and temporary disks. No additional disks supported.
NOTE
For more information on the nodes the virtual machine sizes available to them, see Default node configuration and virtual
machine sizes for clusters in "What are the Hadoop components and versions in HDInsight?"
Gateway Nodes
In addition to the node type previously described, in every HDInsight cluster there are another two nodes that are
invisibly supporting communication with the cluster. These are the Gateway nodes. The Gateway nodes provide
load balanced HTTPS access to the cluster (such as when accessing Ambari), provide SSL support, handles cluster
credential validation, and act as a reverse proxy to communicate with a subset of Hadoop services running on the
cluster.
[Link]
Then you are communicating with the cluster through one of the Gateway nodes.
It is important to note that the Gateway nodes do not provide support for SSH access to the cluster, as that is
accomplished thru direct access to the head nodes.
For instructions about adding additional storage accounts, see HDInsight using Azure Storage, and for details on
using Data Lake Store see HDInsight using Data Lake Store.
Metadata Storage
HDInsight supports the use of a custom metastore for Hive and Oozie. The Hive metastore persists the metadata
which describes the mappings of Hive tables to their locations in HDFS and the schemas of those tables. The
metastore is also used by Spark as it stores metadata for Hive tables created with Spark SQL.
By default, the metastore data is stored internally by the HDInsight cluster. However, you can configure the cluster
to use an external Azure SQL Database instance instead by configuring a custom metastore. Custom metastores
can only be configured during the cluster creation process.
Oozie uses a metastore to store details about current and completed worklflows. To increase performance when
using Oozie, you can use SQL Database as a custom metastore. The metastore can also provide access to Oozie
job data after you delete your cluster.
By combining use of SQL Database as your metastore with Azure Storage or Data Lake Store for persisting your
data, you ensure that you can re-create your cluster without first having to reload either the data or the metadata.
Network Architecture
By default when you create an HDInsight cluster, the VM nodes within that cluster are configured to communicate
with each other, but Internet access to any of the cluster nodes is restricted to just the Head or Edge nodes (and
limited to SSH or HTTPS). There are scenarios that need a greater degree of access into the networking
environment of the cluster nodes, for example:
You need to directly access services on HDInsight that aren't exposed over the Internet. For example, you have
consumers or producers that need to directly work with Kafka brokers or clients that need to use the HBase
Java API.
You need to connect on-premises services to HDInsight. For example, use Oozie to import or export data to
from an on-premises SQL Server.
You need to create solutions that involve multiple HDInsight clusters of different types. For example, you might
want to use Spark or Storm clusters to analyze data stored in a Kafka cluster.
You want to restrict access to HDInsight. For example, to prevent inbound traffic from the internet.
Greater control over the HDInsight networking environment is achieved by deploying your cluster into an Azure
Virtual Network. An Azure Virtual Network allows you to create a secure, persistent network containing the
resources you need for your solution. Cloud resources that you want to connect with your HDInsight cluster, such
as Virtual Machines and other instances of HDInsight can then be provisioned into the same Virtual Network.
You can create a site-to-site or point-to-site VPN connection to enable connectivity between resources in an on-
premises network and your HDInsight cluster.
You can also connect two different Virtual Network instances by configuring a VNET-to-VNET connection.
You can also secure the network perimeter by using Network Security Groups to restrict traffic based on protocol,
source and destination.
In addition to securing in-bound traffic by applying NSGs to subnet of the Virtual Network, you can also configure
user-defined routes and control the flow of network traffic through a virtual firewall appliance by deploying your
HDInsight cluster into a Virtual Network.
For more details on using HDInsight within a Virtual Network, see Use Virtual Network
Next steps
Hadoop Components on HDInsight: Learn about the Hadoop ecosystem components and versions in Azure
HDInsight, as well as the Standard and Premium service levels.
Architecture of Hadoop on HDInsight
8/16/2017 • 6 min to read • Edit Online
Hadoop includes two core components, the High Density File System (HDFS) which provides storage and Yet
Another Resource Negotiator (YARN) which provides processing. With storage and processing capabilities a cluster
becomes capable of running MapReduce programs that perform the desired data processing.
IMPORTANT
As described in HDInsight Architecture, HDFS is not typically deployed within the HDInsight cluster to provide storage.
Instead, an HDFS compatible interface layer is exposed to Hadoop ecosystem components and the actual storage capability is
provide by either Azure Storage or Azure Data Lake Store. In the Hadoop case, MapReduce jobs executing on the HDInsight
cluster run as if HDFS were actually present and require no changes to support their storage needs. This simplifies the
discussion of the architecture of Hadoop on HDInsight, as storage is outsourced, but the processing which uses YARN
remains a core component.
This article introduces YARN and how it coordinates the execution of applications on HDInsight, and then shows
how Spark utilizes YARN to run Spark jobs.
YARN basics
YARN is what governs and orchestrates data processing in Hadoop. It is structured as having two core services that
run as processes on nodes in the cluster:
ResourceManager
NodeManager
The ResourceManager grants cluster compute resources to applications like MapReduce jobs. It grants these
resources in for the form of containers, which are themselves a way to describe an allocation of CPU cores and
RAM memory. If you combined all the resources available in cluster and then distributed it in blocks of a predefined
number of cores and memory, each block of resources is a container. Each node in the cluster has a capacity for a
certain number of containers and therefore the cluster has a fixed limit on the number of containers available. The
allotment of resources in a container is configurable.
When a MapReduce application needs to run on a cluster, it is the ResourceManager that provides it the containers
in which to execute. The ResourceManager tracks the status of running applications, available cluster capacity and
tracks applications as they complete and release the resources they utilized.
The ResourceManager also runs a web server process that provides a web user interface you can access to monitor
the status of applications.
When a user submits a MapReduce application to run on the cluster, it is submitted to the ResourceManager. In
turn, the ResourceManager allocates a container on an available NodeManager nodes. The NodeManager nodes
are where the application actually executes. In the first container allocated is run a special application called the
ApplicationMaster. This ApplicationMaster is responsible for acquiring resources, in the form of subsequent
containers, needed to run the submitted application. To do this, the ApplicationMaster examines the stages of the
application (e.g, the map stage and reduce stage), factors in how much data needs to be processed and then
requests the resources from the ResourceManager on behalf of the application (in a process called "negotiating").
The ResourceManager in turn grants resources from the NodeManagers in the cluster to the ApplicationMaster for
it to use in executing the application.
These NodeManagers run the tasks that make up the application and report their progress and status back to
ApplicationMaster. The ApplicationMaster, in turn reports the status of the application back to the
ResourceManager. The ResourceManager, in turn, returns any results to the client.
YARN on HDInsight
All HDInsight cluster types deploy YARN. The ResourceManger is deployed in a high-availability fashion having a
primary and secondary instance, which run on the first and second head nodes within the cluster respectively. Only
the one instance of the ResourceManager is active at a time. The NodeManager instances run across the available
Worker Nodes in the cluster.
In order to understand the lifecycle of a Spark job, you'll also need to consider Spark objects in your cluster. As
shown below, Spark uses a driver process, which runs the SparkContext along with the YARN resource manager to
schedule and run the Spark jobs submitted to that cluster. When a Spark job is submitted to the cluster, the YARN
ResourceManager instantiates an ApplicationMaster that will act as the Spark master process. The Spark driver
provides its resource requirements to the ApplicationMaster. The ApplicationMaster subsequently requests YARN
containers from the ResourceManager to host the Spark executors. The ApplicationMaster will then be responsible
for the YARN containers running the Spark executors for duration of the application. Beyond that, it is the Spark
driver that is responsible for coordinating the actual Spark application processing.
The cluster executes the Spark job steps on the worker nodes. Each worker node has its own Executor, Cache and
list of (job) tasks.
Understanding Spark Job Steps
Spark uses an abstraction called a RDD (resiliant distributed dataset) to hold the data that it processes during a
Spark job. The Spark API has evolved and there are now higher level objects, such as DataFrames and DataSets that
operate on top of RDDs and provide more functionality for developers, i.e. strongly-typed objects, etc...
After data is loaded into RDDs on the worker nodes, then the DAG (Directed Acyclic Graph) scheduler coordinates
the set of tasks that the Spark job requires and sends that list to the Task Scheduler on the Cluster Manager. Tasks
are then distributed to Executors (on various nodes) and run on resources on those nodes. This process is
illustrated below.
You can monitor the progress of Spark Jobs via several monitoring UIs that are available for HDInsight. Most
commonly, you'd first start by taking a look at the YARN UI to locate the job status and tracking URL for the Spark
job(s) of interest. This is shown below.
Clicking on the Tracking URL (shown above), opens the Spark UI. There are a number of views here that allow you
to track and monitor the status of your job(s) at a very granular level. This UI opens to the Jobs tab. As shown
below, here you can see a list of jobs run with Job Ids, Descriptions, Time Submitted, Job Duration, Job Steps and
Job Tasks. Here also you can click on a link in the Description column to open a new UI with detailed information
about Job step execution overhead.
In the Spark (Job) Stages UI, you have access to highly detailed information about the process and overhead
associated with each task in a Spark job. Shown below is an expanded view of the Spark Stages UI. This includes the
DAG Visualization , Event Timeline , Summary Metrics and Aggregated Metrics by Executor for a single job stage of
a Spark job. These detailed views are quite useful in determining whether and exactly where Spark job performance
bottlenecks are occuring on your HDInsight Spark cluster.
After Spark jobs complete, then job execution information is available in the Spark History Server view. This view is
available via a link in the Azure Portal for HDInsight.
Next steps
This article provided an architectural overview of Hadoop on HDInsight.
To further explore the architecture of HDInsight, see HDInsight Architecture.
For further details on MapReduce, see What is MapReduce.
To run a sample MapReduce application on HDInsight, see Use MapReduce with Hadoop in HDInsight.
HDInsight Dynamic Lifecycle
8/16/2017 • 3 min to read • Edit Online
You can create HDInsight clusters that are either temporary, permanant, or scheduled scale.
Temporary Clusters
Since you only pay for HDInsight when a cluster is up and running, deleting a cluster when it is not in use provides
a big opportunity for cost savings. In order to stop the charges, you have to delete the cluster. There is no concept
of pausing a cluster.
HDInsight can be primarily used for executing scripts and using compute resources. Storage of all data can be done
in less expensive products like Azure SQL Database, Azure Blob Storage, or Azure Data Lake Store.
Most Hadoop jobs are batch jobs. Batch jobs can be used to do a wide variety of things including data aggregation,
data cleaning, data organization, or batch analytics that run at night and automatically populate Power BI
visualizations or Excel spreadsheets. When implementing a workload like this you would create an HDInsight
cluster, run some jobs, save the data, and then completly delete the HDInsight cluster. The process usually
resembles the following steps:
1. Create the HDInsight cluster. Clusters that are temporary are typically created in HDInsight using an Azure
Resource Manager template. Clusters can be created using PowerShell. If jobs will be running on a reguar basis,
you would want to schedule cluster creation using PowerShell or Azure CLI. PowerShell scripts and Azure CLI can
be scheduled using Azure Automation.
2. Schedule the batch jobs. Batch jobs in HDInsight are popularly run in Apache Hive, but they can be created
using several different tools. If you choose to use Apache Hive, there are many ways to run those jobs in HDInsight.
There are several ways to schedule a hive job including using Azure Scheduler with PowerShell, using Oozie, or
using an HDInsight Hive activity in Azure Data Factory.
3. Pipe your data to a permanant storage location. Costs of storage in Azure are significantly cheaper than the
cost of keeping an HDInsight cluster up and running. After you have completed a Hive job, you can export the
results to permenant location like Azure SQL database, Azure SQL Data Warehouse, Azure Blob Storage, or Azure
Data Lake Store.
Hadoop supports a notion of the default file system. The default file system implies a default scheme and authority.
It can also be used to resolve relative paths. During step 1, you can specify a blob container in Azure Storage as the
default file system, or with HDInsight 3.5, you can select either Azure Storage or Azure Data Lake Store as the
default files system with a few exceptions. For the supportability of using Data Lake Store as both the default and
linked storage, see Availabilities for HDInsight cluster.
Since the charges for the cluster are many times more than the charges for storage, it makes economic sense to
delete clusters when they are not in use.
4. Tear down the cluster. This can be done automatically using the methods mentioned above, or it can be done
manually in the morning after confirmation that the jobs have all completed successfully. See examples using Azure
PowerShell, Azure CLI, or the .NET SDK.
Orchestrating the cluster lifecycle using Azure Data Factory
A popular option for automating the creation of and deleting HDInsight clusters, is Azure Data Factory (ADF). ADF
includes its own scheduler you can use to apply various schedules in which your cluster's lifecycle is managed. This
can result in significant IT cost-savings, as you have a simple and effective way to ensure your cluster is only up and
running when it is needed. The term for temporary clusters in Azure Data Factory is "on-demand clusters".
Azure Data Factory includes a linked service type for HDInsight, and pipeline activities for Hive, MapReduce, Pig,
Hadoop Streaming, and Spark.
Long-Running Clusters
If HDInsight will be used in a more interactive fashion, then it makes sense to keep the HDInsight cluster up and
running permanently. Some of these workloads include:
1) Using Spark, Kafka or Storm for stream analytics.
2) Using Apache Hive, Storm, and Pig for interactive querying and analytics.
3) Using ETL and data cleaning tools permanently for real-time data processing.
![NOTE]
When you create an HDInsight cluster, the processing can begin as soon as the nodes become available. You
do not need to wait for all nodes in the cluster to be ready before using it to process jobs.
Scheduled Scale
The cost of HDInsight clusters is determined by the number of nodes and the virtual machines sizes for the nodes.
You can use PowerShell to select the number of nodes and virtual machine sizes for those nodes. You can scale
them up during heavy usage and scale them down for light usage. Scheduling the scaling of nodes and virtual
machine size can represent a significant cost savings.
Availability and reliability of Hadoop clusters in
HDInsight
8/16/2017 • 9 min to read • Edit Online
HDInsight clusters provide two head nodes to increase the availability and reliability of Hadoop services and jobs
running.
Hadoop achieves high availability and reliability by replicating services and data across multiple nodes in a cluster.
However standard distributions of Hadoop typically have only a single head node. Any outage of the single head
node can cause the cluster to stop working. HDInsight provides two headnodes to improve Hadoop's availability
and reliability.
IMPORTANT
Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight retirement
on Windows.
NOTE
Not all node types are used for a cluster type. For example, a Hadoop cluster type does not have any Nimbus nodes. For
more information on nodes used by HDInsight cluster types, see the Cluster types section of the Create Linux-based Hadoop
clusters in HDInsight document.
Head nodes
To ensure high availability of Hadoop services, HDInsight provides two head nodes. Both head nodes are active and
running within the HDInsight cluster simultaneously. Some services, such as HDFS or YARN, are only 'active' on
one head node at any given time. Other services such as HiveServer2 or Hive MetaStore are active on both head
nodes at the same time.
Head nodes (and other nodes in HDInsight) have a numeric value as part of the hostname of the node. For example,
hn0-CLUSTERNAME or hn4-CLUSTERNAME .
IMPORTANT
Do not associate the numeric value with whether a node is primary or secondary. The numeric value is only present to
provide a unique name for each node.
Nimbus Nodes
Nimbus nodes are available with Storm clusters. The Nimbus nodes provide similar functionality to the Hadoop
JobTracker by distributing and monitoring processing across worker nodes. HDInsight provides two Nimbus nodes
for Storm clusters
Zookeeper nodes
ZooKeeper nodes are used for leader election of master services on head nodes. They are also used to insure that
services, data (worker) nodes, and gateways know which head node a master service is active on. By default,
HDInsight provides three ZooKeeper nodes.
Worker nodes
Worker nodes perform the actual data analysis when a job is submitted to the cluster. If a worker node fails, the
task that it was performing is submitted to another worker node. By default, HDInsight creates four worker nodes.
You can change this number to suit your needs both during and after cluster creation.
Edge node
An edge node does not actively participate in data analysis within the cluster. It is used by developers or data
scientists when working with Hadoop. The edge node lives in the same Azure Virtual Network as the other nodes in
the cluster, and can directly access all other nodes. The edge node can be used without taking resources away from
critical Hadoop services or analysis jobs.
Currently, R Server on HDInsight is the only cluster type that provides an edge node by default. For R Server on
HDInsight, the edge node is used test R code locally on the node before submitting it to the cluster for distributed
processing.
For information on using an edge node with cluster types other than R Server, see the Use edge nodes in HDInsight
document.
This command returns a value similar to the following command, which contains the internal URL to use with the
oozie command:
"[Link]": "[Link]
For more information on working with the Ambari REST API, see Monitor and Manage HDInsight using the Ambari
REST API.
Accessing other node types
You can connect to nodes that are not directly accessible over the internet by using the following methods:
SSH: Once connected to a head node using SSH, you can then use SSH from the head node to connect to
other nodes in the cluster. For more information, see the Use SSH with HDInsight document.
SSH Tunnel: If you need to access a web service hosted on one of the nodes that is not exposed to the
internet, you must use an SSH tunnel. For more information, see the Use an SSH tunnel with HDInsight
document.
Azure Virtual Network: If your HDInsight cluster is part of an Azure Virtual Network, any resource on the
same Virtual Network can directly access all nodes in the cluster. For more information, see the Extend
HDInsight using Azure Virtual Network document.
There are a series of icons that may appear next to a service to indicate status. Any alerts related to a service can be
viewed using the Alerts link at the top of the page. You can select each service to view more information on it.
While the service page provides information on the status and configuration of each service, it does not provide
information on which head node the service is running on. To view this information, use the Hosts link at the top of
the page. This page displays hosts within the cluster, including the head nodes.
Selecting the link for one of the head nodes displays the services and components running on that node.
For more information on using Ambari, see Monitor and manage HDInsight using the Ambari Web UI.
Ambari REST API
The Ambari REST API is available over the internet. The HDInsight public gateway handles routing requests to the
head node that is currently hosting the REST API.
You can use the following command to check the state of a service through the Ambari REST API:
{
"href" : "[Link]
[Link]/api/v1/clusters/mycluster/services/HDFS?
fields=ServiceInfo/state",
"ServiceInfo" : {
"cluster_name" : "mycluster",
"service_name" : "HDFS",
"state" : "STARTED"
}
}
The URL tells us that the service is currently running on a head node named hn0-CLUSTERNAME.
The state tells us that the service is currently running, or STARTED.
If you do not know what services are installed on the cluster, you can use the following command to retrieve a list:
For more information on working with the Ambari REST API, see Monitor and Manage HDInsight using the Ambari
REST API.
Service components
Services may contain components that you wish to check the status of individually. For example, HDFS contains the
NameNode component. To view information on a component, the command would be:
curl -u admin:PASSWORD
[Link]
If you do not know what components are provided by a service, you can use the following command to retrieve a
list:
curl -u admin:PASSWORD
[Link]
cd /var/log/hadoop/hdfs
get *
NOTE
There are also graphical interfaces that allow you to visualize the file system when connected using SFTP. For example,
MobaXTerm allows you to browse the file system using an interface similar to Windows Explorer.
Ambari
NOTE
To access log files using Ambari, you must use an SSH tunnel. The web interfaces for the individual services are not exposed
publicly on the Internet. For information on using an SSH tunnel, see the Use SSH Tunneling document.
From the Ambari Web UI, select the service you wish to view logs for (for example, YARN). Then use Quick Links to
select which head node to view the logs for.
Next steps
Use the following links to learn more about things mentioned in this document.
Ambari REST Reference
Install and configure the Azure CLI
Install and configure Azure PowerShell
Manage HDInsight using Ambari
Provision Linux-based HDInsight clusters
Capacity Planning
8/16/2017 • 5 min to read • Edit Online
Capacity planning is an important first step in deploying your HDInsight cluster. A good plan can help you optimize
your costs while delivering high performance and usability to the users of your cluster. In addition, when
provisioning your cluster there are a series of decisions you need to make that are either difficult or impossible to
change later- thinking thru these decisions can save you from having to tear down your cluster and setup a new
one to address the issue.
The key questions to ask when doing your capacity planning are:
In which geographic region should you deploy your cluster?
What cluster type should you deploy?
What size and type of virtual machine should your cluster nodes use?
How many worker nodes should your cluster have?
The sections that follow provide guidance on each of these topics.
Choosing a region
The region determines where your cluster is actually provisioned. The primary consideration in selecting a region is
data locality- you want your cluster physically near the data it will process to minimize latency of reads and writes.
There are a few scenarios to consider.
Availability of HDInsight in the region desired
HDInsight is available in most Azure regions, but not all. Be sure to check the HDInsight Linux entry in Azure
Products Available by Region when selecting the location for your cluster deployment.
Location of default storage
When provisioning your cluster, the default storage selected (e.g., the Azure Storage Account or Data Lake Store)
must be in the same location as your cluster. This means your storage choice dictates the location you must select
for your cluster. When using Data Lake Store for default storage, this may further narrow the locations available to
your cluster as the Data Lake Store is currently only available in three locations globally (Central US, East US 2 and
North Europe). Azure Storage is available in all location, so this same consideration does not apply.
Location of existing data
If you already have a Storage Account or Data Lake Store deployed and loaded with data and intend to use this
storage as your cluster's default storage, then you will need to deploy your cluster into the same location as where
the data is stored. Once you have an HDInsight cluster deployed, you can attach additional Azure Storage Accounts
or access other Data Lake Stores. When using a Storage Account as an additional storage location, this account
must reside in the same location as your cluster. When using a Data Lake Store, however, the cluster and the Data
Lake Store can reside in different locations (although consider the latency consequences of doing so as the data has
further to travel in reaching your cluster).
Quotas
A very important consideration when planning your deployment, after you have identified your target cluster VM
size, scale and type is to confirm your subscription has enough quota capacity remaining. When you reach a quota
limit, you may be blocked from deploying new clusters or from scaling out existing clusters by adding more worker
nodes. The most common quota limit reached is the CPU Cores quota which exists at the subscription, region and
VM series levels. For example, your subscription may have a 200 core limit and you may have a 30 core limit in
West US 2 and a 30 core limit on Dv2 instances. These quota limits are soft in that you can contact support to
request a quota increase. However, there are some hard limits that cannot be changed with a call to support. When
it comes to CPU cores, a single Azure subscription can have at most 10,000 cores, and this is a hard limit. For
details on these limits, see Azure subscription and service limits, quotas, and constraints.
Next steps
Set up clusters in HDInsight with Hadoop, Spark, Kafka, and more: Learn how to set up and configure clusters in
HDInsight with Hadoop, Spark, Kafka, Interactive Hive, HBase, R Server, or Storm.
Key Scenarios to monitor in HDInsight: Learn about key scenarios to monitor for your HDInsight cluster that
might affect your cluster's capacity.
Connect to HDInsight (Hadoop) using SSH
8/16/2017 • 9 min to read • Edit Online
Learn how to use Secure Shell (SSH) to securely connect to Hadoop on Azure HDInsight.
HDInsight can use Linux (Ubuntu) as the operating system for nodes within the Hadoop cluster. The following
table contains the address and port information needed when connecting to Linux-based HDInsight using an
SSH client:
NOTE
Replace <edgenodename> with the name of the edge node.
Replace <clustername> with the name of your cluster.
If your cluster contains an edge node, we recommend that you always connect to the edge node using SSH. The head
nodes host services that are critical to the health of Hadoop. The edge node runs only what you put on it.
For more information on using edge nodes, see Use edge nodes in HDInsight.
SSH clients
Linux, Unix, and macOS systems provide the ssh and scp commands. The ssh client is commonly used to
create a remote command-line session with a Linux or Unix-based system. The scp client is used to securely
copy files between your client and the remote system.
Microsoft Windows does not provide any SSH clients by default. The ssh and scp clients are available for
Windows through the following packages:
Azure Cloud Shell: The Cloud Shell provides a Bash environment in your browser, and provides the ssh ,
scp , and other common Linux commands.
Bash on Ubuntu on Windows 10: The ssh and scp commands are available through the Bash on
Windows command line.
Git ([Link] The ssh and scp commands are available through the GitBash command
line.
GitHub Desktop ([Link] The ssh and scp commands are available through the
GitHub Shell command line. GitHub Desktop can be configured to use Bash, the Windows Command
Prompt, or PowerShell as the command line for the Git Shell.
OpenSSH ([Link] The
PowerShell team is porting OpenSSH to Windows, and provides test releases.
WARNING
The OpenSSH package includes the SSH server component, sshd . This component starts an SSH server on your
system, allowing others to connect to it. Do not configure this component or open port 22 unless you want to
host an SSH server on your system. It is not required to communicate with HDInsight.
IMPORTANT
If you secure your private key with a passphrase, you must enter the passphrase when using the key. Utilities such as
ssh-agent can cache the password for your convenience.
You are prompted for information during the key creation process. For example, where the keys are stored or
whether to use a passphrase. After the process completes, two files are created; a public key and a private key.
The public key is used to create an HDInsight cluster. The public key has an extension of .pub .
The private key is used to authenticate your client to the HDInsight cluster.
IMPORTANT
You can secure your keys using a passphrase. A passphrase is effectively a password on your private key. Even if
someone obtains your private key, they must have the passphrase to use the key.
Azure portal Uncheck Use same password as cluster login, and then
select Public Key as the SSH authentication type. Finally,
select the public key file or paste the text contents of the file
in the SSH public key field.
Resource Manager Template For an example of using SSH keys with a template, see
Deploy HDInsight on Linux with SSH key. The publicKeys
element in the [Link] file is used to pass the keys
to Azure when creating the cluster.
Authentication: Password
SSH accounts can be secured using a password. When you connect to HDInsight using SSH, you are prompted
to enter the password.
WARNING
We do not recommend using password authentication for SSH. Passwords can be guessed and are vulnerable to brute
force attacks. Instead, we recommend that you use SSH keys for authentication.
Azure portal By default, the SSH user account has the same password as
the cluster login account. To use a different password,
uncheck Use same password as cluster login, and then
enter the password in the SSH password field.
Resource Manager Template For an example of using a password with a template, see
Deploy HDInsight on Linux with SSH password. The
linuxOperatingSystemProfile element in the
[Link] file is used to pass the SSH account name
and password to Azure when creating the cluster.
Connect to nodes
The head nodes and edge node (if there is one) can be accessed over the internet on ports 22 and 23.
When connecting to the head nodes, use port 22 to connect to the primary head node and port 23 to
connect to the secondary head node. The fully qualified domain name to use is
[Link] , where clustername is the name of your cluster.
# Connect to primary head node
# port not specified since 22 is the default
ssh sshuser@[Link]
When connectiung to the edge node, use port 22. The fully qualified domain name is
[Link] , where edgenodename is a name you provided when
creating the edge node. clustername is the name of the cluster.
IMPORTANT
The previous examples assume that you are using password authentication, or that certificate authentication is occuring
automatically. If you use an SSH key-pair for authentication, and the certificate is not used automatically, use the -i
parameter to specify the private key. For example,
ssh -i ~/.ssh/mykey sshuser@[Link] .
Once connected, the prompt changes to indicate the SSH user name and the node you are connected to. For
example, when connected to the primary head node as sshuser , the prompt is sshuser@hn0-clustername:~$ .
Connect to worker and Zookeeper nodes
The worker nodes and Zookeeper nodes are not directly accessible from the internet. They can be accessed
from the cluster head nodes or edge nodes. The following are the general steps to connect to other nodes:
1. Use SSH to connect to a head or edge node:
ssh sshuser@[Link]
2. From the SSH connection to the head or edge node, use the ssh command to connect to a worker node
in the cluster:
ssh sshuser@wn0-myhdi
To retrieve a list of the domain names of the nodes in the cluster, see the Manage HDInsight by using the
Ambari REST API document.
If the SSH account is secured using a password, enter the password when connecting.
If the SSH account is secured using SSH keys, make sure that SSH forwarding is enabled on the client.
NOTE
Another way to directly access all nodes in the cluster is to install HDInsight into an Azure Virtual Network. Then, you can
join your remote machine to the same virtual network and directly access all nodes in the cluster.
For more information, see Use a virtual network with HDInsight.
1. Using a text editor, open ~/.ssh/config . If this file doesn't exist, you can create it by entering
touch ~/.ssh/config at a command line.
Host <edgenodename>.<clustername>-[Link]
ForwardAgent yes
Replace the Host information with the address of the node you connect to using SSH. The previous
example uses the edge node. This entry configures SSH agent forwarding for the specified node.
3. Test SSH agent forwarding by using the following command from the terminal:
echo "$SSH_AUTH_SOCK"
/tmp/ssh-rfSUL1ldCldQ/agent.1792
If nothing is returned, then ssh-agent is not running. For more information, see the agent startup scripts
information at Using ssh-agent with ssh ([Link] or consult your SSH client
documentation.
4. Once you have verified that ssh-agent is running, use the following to add your SSH private key to the
agent:
ssh-add ~/.ssh/id_rsa
If your private key is stored in a different file, replace ~/.ssh/id_rsa with the path to the file.
5. Connect to the cluster edge node or head nodes using SSH. Then use the SSH command to connect to a
worker or zookeeper node. The connection is established using the forwarded key.
Copy files
The scp utility can be used to copy files to and from individual nodes in the cluster. For example, the following
command copies the [Link] directory from the local system to the primary head node:
Since no path is specified after the : , the file is placed in the sshuser home directory.
The following example copies the [Link] file from the sshuser home directory on the primary head node to
the local system:
scp sshuser@[Link]:[Link] .
IMPORTANT
scp can only access the file system of individual nodes within the cluster. It cannot be used to access data in the HDFS-
compatible storage for the cluster.
Use scp when you need to upload a resource for use from an SSH session. For example, upload a Python script and
then run the script from an SSH session.
For information on directly loading data into the HDFS-compatible storage, see the following documents:
HDInsight using Azure Storage.
HDInsight using Azure Data Lake Store.
Next steps
Use SSH tunneling with HDInsight
Use a virtual network with HDInsight
Use edge nodes in HDInsight
Use SSH Tunneling to access Ambari web UI,
JobHistory, NameNode, Oozie, and other web UIs
8/15/2017 • 5 min to read • Edit Online
Linux-based HDInsight clusters provide access to Ambari web UI over the Internet, but some features of the UI are
not. For example, the web UI for other services that are surfaced through Ambari. For full functionality of the
Ambari web UI, you must use an SSH tunnel to the cluster head.
Prerequisites
An SSH client. For more information, see Use SSH with HDInsight.
A web browser that can be configured to use a SOCKS5 proxy.
WARNING
The SOCKS proxy support built into Windows does not support SOCKS5, and does not work with the steps in this
document. The following browsers rely on Windows proxy settings, and do not currently work with the steps in this
document:
Microsoft Edge
Microsoft Internet Explorer
Google Chrome also relies on the Windows proxy settings. However, you can install extensions that support
SOCKS5. We recommend FoxyProxy Standard.
Create a tunnel using the SSH command
Use the following command to create an SSH tunnel using the ssh command. Replace USERNAME with an SSH
user for your HDInsight cluster, and replace CLUSTERNAME with the name of your HDInsight cluster:
This command creates a connection that routes traffic to local port 9876 to the cluster over SSH. The options are:
D 9876 - The local port that routes traffic through the tunnel.
C - Compress all data, because web traffic is mostly text.
2 - Force SSH to try protocol version 2 only.
q - Quiet mode.
T - Disable pseudo-tty allocation, since we are just forwarding a port.
n - Prevent reading of STDIN, since we are just forwarding a port.
N - Do not execute a remote command, since we are just forwarding a port.
f - Run in the background.
Once the command finishes, traffic sent to port 9876 on the local computer is routed to the cluster head node.
1. Configure the browser to use localhost and the port you used when creating the tunnel as a SOCKS v5
proxy. Here's what the Firefox settings look like. If you used a different port than 9876, change the port to
the one you used:
NOTE
Selecting Remote DNS resolves Domain Name System (DNS) requests by using the HDInsight cluster. This setting
resolves DNS using the head node of the cluster.
2. Verify that the tunnel works by visiting a site such as [Link] If the proxy is correctly
configured, the IP address returned is from a machine in the Microsoft Azure datacenter.
NOTE
When using the [Link] address to connect to the cluster, you are connecting through the
tunnel. Communication is secured using the SSH tunnel instead of HTTPS. To connect over the internet using HTTPS,
use [Link] where CLUSTERNAME is the name of the cluster.
2. From the Ambari Web UI, select HDFS from the list on the left of the page.
3. When the HDFS service information is displayed, select Quick Links. A list of the cluster head nodes
appears. Select one of the head nodes, and then select NameNode UI.
NOTE
When you select Quick Links, you may get a wait indicator. This can happen if you have a slow internet connection.
Wait a minute or two for the data to be received from the server, then try the list again.
Some entries in the Quick Links menu may be cut off by the right side of the screen. If so, expand the menu using
your mouse and use the right arrow key to scroll the screen to the right to see the rest of the menu.
Next steps
Now that you have learned how to create and use an SSH tunnel, see the following document for other ways to
use Ambari:
Manage HDInsight clusters by using Ambari
For more information on using SSH with HDInsight, see Use SSH with HDInsight.
Extend HDInsight capabilities by using Azure Virtual
Network
8/16/2017 • 14 min to read • Edit Online
Learn how to use Azure Virtual Networks with HDInsight to enable the following scenarios:
Restrict access to HDInsight. For example, prevent inbound traffic from the internet.
Directly access services on HDInsight that aren't exposed over the Internet. For example, directly work with
Kafka brokers or use the HBase Java API.
Directly connect services to HDInsight. For example, use Oozie to import or export data to a SQL Server
within your data center.
Create solutions that involve multiple HDInsight clusters. For example, use Spark or Storm to analyze data
stored in Kafka.
Prerequisites
Azure CLI 2.0: For more information, see Install and Configure Azure CLI 2.0.
Azure PowerShell: For more information, see Install and Configure Azure PowerShell.
NOTE
The steps in this document require the latest version of the Azure CLI and Azure PowerShell. If you are using an older
version, the commands may be different. For best results, use the previous links to install the latest versions.
Using Virtual Network to link Azure services with Azure HDInsight enables the following scenarios:
Invoking HDInsight services or jobs from Azure websites or services running in Azure virtual machines.
Directly transferring data between HDInsight and Azure SQL Database, SQL Server, or another data
storage solution running on a virtual machine.
Combining multiple HDInsight servers into a single solution. There are several types of HDInsight
clusters, which correspond to the workload or technology that the cluster is tuned for. There is no
supported method to create a cluster that combines multiple types, such as Storm and HBase on one
cluster. Using a virtual network allows multiple clusters to directly communicate with each other.
Connect cloud resources to a local datacenter network
Site-to-site configuration allows you to connect multiple resources in your datacenter to the Azure virtual network.
The connection can be made using a hardware VPN device or the Routing and Remote Access service.
Point-to-site configuration allows you to connect a specific resource to the Azure virtual network by using
software VPN.
Using Virtual Network to link the cloud and your datacenter enables similar scenarios to the cloud-only
configuration. But instead of being limited to working with resources in the cloud, you can also work with
resources in your datacenter.
Directly transferring data between HDInsight and your datacenter. An example is using Sqoop to transfer
data to or from SQL Server or reading data generated by a line-of-business (LOB) application.
Invoking HDInsight services or jobs from an LOB application. An example is using HBase Java APIs to
store and retrieve data from an HDInsight HBase cluster.
For more information on Virtual Network features, benefits, and capabilities, see the Azure Virtual Network
overview.
NOTE
Create the Azure Virtual Network before provisioning an HDInsight cluster, then specify the network when creating the
cluster. If you plan on using a custom DNS server, it must be added to the virtual network before HDInsight. For more
information, see Virtual Network configuration tasks.
Required IP addresses
The HDInsight service is a managed service, and requires access to Azure management services during
provisioning and while running. Azure management performs the following services:
Monitor the health of the cluster
Initiate failover of cluster resources
Change the number of nodes in the cluster through scaling operations
Other management tasks
NOTE
These operations do not require full access to the internet. When restricting internet access, allow inbound access on port
443 for the following IP addresses. This allows Azure to manage HDInsight:
If you restrict access to the virtual network you must allow access to the managment IP addresses. The IP
addresses that should be allowed are specific to the region that the HDInsight cluster and Virtual Network reside
in. Use the following table to find the IP addresses for the region you are using.
NOTE
The appropriate region IP addresses listed below should be set as the source IP when defining inbound Network Security
Group rules for the subnet that contains HDInsight.
If your region is not listed in the table, allow traffic to port 443 on the following IP addresses:
[Link]
[Link]
[Link]
[Link]
IMPORTANT
HDInsight doesn't support restricting outbound traffic, only inbound traffic. When defining Network Security Group rules for
the subnet that contains HDInsight, only use inbound rules.
NOTE
If you use a custom DNS server with your virtual network, you must also allow access from [Link]. This is the
address of Azure's recursive resolver. For more information, see the Name resolution for VMs and Role instances document.
IMPORTANT
These addresses are for regions that do not have specific IP addresses listed. To find the IP addresses for your region, use
the information in the Secured Virtual Networks section.
These steps assume that you have already created a Virtual Network and subnet that you want to install HDInsight
into. See Create a virtual network using the Azure portal.
WARNING
Rules are tested against network traffic in order by priority. Once a rule matches the test criteria, it is applied and no more
rules are tested for that request. If you have a rule that broadly blocks inbound traffic (such as a deny all rule), it must
come after the rules that allow traffic.
For more information on Network Security Group rules, see the What is a Network Security Group document.
Once the group has been created, you receive information on the new group.
2. Use the following to add rules to the new network security group that allow inbound communication on
port 443 from the Azure HDInsight health and management service. Replace RESOURCEGROUPNAME
with the name of the resource group that contains the Azure Virtual Network.
az network nsg rule create -g RESOURCEGROUPNAME --nsg-name hdisecure -n hdirule1 --protocol "*" --
source-port-range "*" --destination-port-range "443" --source-address-prefix "[Link]/24" --
destination-address-prefix "VirtualNetwork" --access "Allow" --priority 300 --direction "Inbound"
az network nsg rule create -g RESOURCEGROUPNAME --nsg-name hdisecure -n hdirule2 --protocol "*" --
source-port-range "*" --destination-port-range "443" --source-address-prefix "[Link]/24" --
destination-address-prefix "VirtualNetwork" --access "Allow" --priority 301 --direction "Inbound"
az network nsg rule create -g RESOURCEGROUPNAME --nsg-name hdisecure -n hdirule3 --protocol "*" --
source-port-range "*" --destination-port-range "443" --source-address-prefix "[Link]/24" --
destination-address-prefix "VirtualNetwork" --access "Allow" --priority 302 --direction "Inbound"
az network nsg rule create -g RESOURCEGROUPNAME --nsg-name hdisecure -n hdirule4 --protocol "*" --
source-port-range "*" --destination-port-range "443" --source-address-prefix "[Link]/24" --
destination-address-prefix "VirtualNetwork" --access "Allow" --priority 303 --direction "Inbound"
3. Once the rules have been created, use the following to retrieve the unique identifier for this network
security group:
"/subscriptions/SUBSCRIPTIONID/resourceGroups/RESOURCEGROUPNAME/providers/[Link]/networkSec
urityGroups/hdisecure"
Use double-quotes around id in the command if you don't get the expected results.
4. Using the following command to apply the network security group to a subnet. Replace the GUID and
RESOURCEGROUPNAME values with the ones returned from the previous step. Replace VNETNAME and
SUBNETNAME with the virtual network name and subnet name that you want to use when creating an
HDInsight cluster.
az network vnet subnet update -g RESOURCEGROUPNAME --vnet-name VNETNAME --name SUBNETNAME --set
[Link]="/subscriptions/GUID/resourceGroups/RESOURCEGROUPNAME/providers/[Link]
rk/networkSecurityGroups/hdisecure"
Once this command completes, you can successfully install HDInsight into the secured Virtual Network on
the subnet used in these steps.
IMPORTANT
Using the preceding steps only open access to the HDInsight health and management service on the Azure cloud. Any
other access to the HDInsight cluster from outside the Virtual Network is blocked. To enable access from outside the virtual
network, you must add additional Network Security Group rules.
The following example demonstrates how to enable SSH access from the Internet:
az network nsg rule create -g RESOURCEGROUPNAME --nsg-name hdisecure -n hdirule5 --protocol "*" --source-
port-range "*" --destination-port-range "22" --source-address-prefix "*" --destination-address-prefix
"VirtualNetwork" --access "Allow" --priority 304 --direction "Inbound"
For more information on Network Security Groups, see Network Security Groups overview. For information on
controlling routing in an Azure Virtual Network, see User-defined Routes and IP forwarding.
User-defined routes
If you use user-defined routes (UDR) to secure the virtual network, you must add routes for the HDInsight
management IP addresses for your region. For a list of IP addresses by region, see the Required IP addresses
section.
The routes to the required IP addresses must set the Next Hop type to Internet. The following image is an
example of how the routes appear in the Azure portal:
For more information on user-defined routes, see the user-defined routes and IP forwarding document.
Forced tunneling
Forced tunneling is not supported with HDInsight.
$resourceGroupName = Read-Input -Prompt "Enter the resource group that contains the virtual network used with
HDInsight"
$nodes = @()
foreach($nic in $clusterNICs) {
$node = new-object [Link]
$node | add-member -MemberType NoteProperty -name "Type" -value $[Link]('-')[1]
$node | add-member -MemberType NoteProperty -name "InternalIP" -value
$[Link]
$node | add-member -MemberType NoteProperty -name "InternalFQDN" -value $[Link]
$nodes += $node
}
$nodes | sort-object Type
Azure CLI
IMPORTANT
In the Azure CLI 2.0 example, replace <resourcegroupname> with the name of the resource group that contains the virtual
network.
The scripts work by querying the virtual network interface cards (NICs) for the cluster. The NICs exist in the
resource group that contains the virtual network used by HDInsight.
8. Repeat these steps to set the static IP address for each of the cluster nodes as required.
Configure static IP addresses using PowerShell
PowerShell can be used to mark a DIP as "static" while creating a new Network Interface, by setting the
PrivateIpAddress parameter:
When you specify an explicit IP value as in the example above, Azure will consider that address as static and will
never change.
Next steps
The following examples demonstrate how to use HDInsight with Azure Virtual Network:
HBase clusters in Azure Virtual Network
Analyze sensor data with Storm and HBase in HDInsight
Provision Hadoop clusters in HDInsight
Use Sqoop with Hadoop in HDInsight
To learn more about Azure virtual networks, see the Azure Virtual Network overview.
Scaling - Best Practices
8/16/2017 • 12 min to read • Edit Online
HDInsight offers elasticity by giving administrators the option to scale up and scale down the number of Worker
Nodes in the clusters. This allows you to shrink a cluster during after hours or on weekends, and grow it during
peak business demands.
For example, if you have some batch processing that happens once a week or once a month, the HDInsight cluster
can be scaled up a few minutes prior to that scheduled event so that there is plenty of memory and CPU compute
power. You can automate that with the PowerShell cmdlet Set–AzureRmHDInsightClusterSize . Later, after the
processing is done, and usage is expected to go down again, the administrator can scale down the HDInsight
cluster to fewer worker nodes.
Scaling your cluster through PowerShell:
To scale your cluster through the Azure Portal, open your HDInsight cluster blade, select Scale cluster on the left-
hand menu, then on the Scale cluster blade, type in the number of worker nodes, and click save.
Using any of these methods, you can scale your HDInsight cluster up or down within minutes.
Scaling impacts on running jobs
When you add nodes to your running HDInsight cluster, any pending or running jobs will not be impacted. In
addition, new jobs can be safely submitted while the scaling process is running. If the scaling operations fails for
any reason, the failure is gracefully handled, leaving the cluster in a functional state.
However, if you are scaling down your cluster by removing nodes, any pending or running jobs will fail when the
scaling operation completes. This is due to some of the services restarting during the process.
To address this, you can wait for the jobs to complete before scaling down your cluster, manually terminate them,
or simply resubmit the jobs after the scaling operation has concluded.
To see a list of pending and running jobs, you can use the YARN ResourceManager UI, following these steps:
1. Sign in to Azure portal.
2. On the left menu, click Browse, click HDInsight Clusters, select your cluster.
3. From your HDInsight cluster blade, click Dashboard on the top menu to open the Ambari UI. You'll be
prompted for your cluster login credentials.
4. Click YARN on the list of services on the left-hand menu. On the YARN page, click Quick Links hover over the
active head node, then click ResourceManager UI.
You will see a list of jobs, along with their current State. In the screenshot below, we can see that we have one job
currently running:
We can manually kill that running application by executing the following command from the SSH shell:
yarn application -kill "application_1499348398273_0003"
hbase shell
3. Once the HBase shell has loaded, use the following to manually balance the region servers:
balancer
If you shrink your cluster down to the minimum of 1 worker node, as shown above, from several nodes, it is
possible for HDFS to become stuck in safe mode when worker nodes are rebooted due to patching, or immediately
after the scaling operation.
The primary cause of this is that Hive uses a few scratchdir files, and by default, expects 3 replicas of each block,
but there is only 1 replica possible if you scale down to the minimum 1 worker node. As a consequence, the files in
the scratchdir become under replicated. This could cause HDFS to stay in Safe mode when the services are
restarted after the scale operation.
When a scale down attempt happens, HDInsight relies upon the Ambari management interfaces to first
decommission the extra unwanted worker nodes, which replicates the HDFS blocks to other online worker nodes,
and then safely scale the cluster down. HDFS goes into a safe mode during the maintenance window, and is
supposed to come out once the scaling is finished. It is at this point that HDFS can become stuck in safe mode.
HDFS is configured with the [Link] setting of 3. Thus, the blocks of the scratch files are under
replicated whenever there are fewer than 3 worker nodes online, because there are not the expected 3 copies of
each file block available.
One way to bring HDFS out of safe mode is to execute a command to leave safe mode (ignoring the cause,
assuming it is benign). For example, if you know that the only reason safe mode is on is because the temporary
files are under replicated (discussed in detail below), then you can safely leave safe mode. This is primarily because
the under-replicated files are Hive temporary scratch files.
After leaving safe mode, you may remove the problematic temp files or wait for Hive to eventually clean them up
automatically.
Example errors when safe mode is turned on
ERROR 1
H070 Unable to open Hive session.
[Link]([Link]):
[Link]: Cannot create directory
/tmp/hive/hive/819c215c-6d87-4311-97c8-4f0b9d2adcf0. Name node is in safe mode. The reported blocks 75
needs additional 12 blocks to reach the threshold 0.9900 of total blocks 87. The number of live datanodes 10 has
reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been
reached.
ERROR 2
H100 Unable to submit statement show databases: [Link]:
[Link]: Connect to hn0-
[Link] [[Link]. [Link]/[Link]]
failed: Connection refused
ERROR 3
H020 Could not establish connecton to [Link]:
[Link]: Could not create http connection to [Link]
[Link]/. [Link]: Connect to
[Link] [[Link]/[Link]]
failed: Connection refused: [Link]: Could not create http connection to
[Link] [Link]:
Connect to [Link] [hn0-
[Link]/[Link]] failed: Connection refused
ERROR 4 – from the Hive logs
WARN [main]: server.HiveServer2 ([Link]:startHiveServer2(442)) – Error starting HiveServer2 on
attempt 21, will retry in 60 seconds [Link]: Error applying authorization policy on hive
configuration: [Link]([Link]):
[Link]: Cannot create directory
/tmp/hive/hive/70a42b8a-9437-466e-acbe-da90b1614374. Name node is in safe mode. The reported blocks 0
needs additional 9 blocks to reach the threshold 0.9900 of total blocks 9. The number of live datanodes 10 has
reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been
reached. at
[Link]([Link])
You can review the Name Node logs from the /var/log/hadoop/hdfs/ folder, near the time when the cluster was
scaled to see when it entered safe mode. The log files are named after the following pattern:
Hadoop-hdfs-namenode-hn0-clustername.*
The gist of the above errors is that Hive depends on temporary files in HDFS while running queries. When HDFS
enters "Safe Mode", Hive cannot run queries since it cannot write to HDFS. The temp files in HDFS are located in the
local drive mounted to the individual worker node VMs, and replicated amongst the worker nodes at 3 replicas,
minumum.
The [Link] parameter in Hive is configured within /etc/hive/conf/[Link] as shown:
<property>
<name>[Link]</name>
<value>hdfs://mycluster/tmp/hive</value>
</property>
Next, you can view a report that shows the details of the HDFS state:
The above command will result in the following on a healthy cluster where all blocks are replicated to the expected
degree:
Note: The -D switch is used in these queries, because the default file system in HDInsight is either Azure
Storage or Azure Data Lake Store. The switch specifies that the commands need to execute against the local
HDFS file system.
HDFS supports the fsck command to check for various inconsistencies with various files, for example, missing
blocks for a file or under-replicated blocks. To run the fsck command against the scratchdir (temporary scratch
disk) files, execute the following:
When executed on a healthy HDFS file system with no under-replicated blocks, you will see an output similar to the
following:
In contrast, when the command is executed on an HDFS file system with some under-replicated blocks, the output
will be similar to the following:
Connecting to namenode via [Link]
ugi=sshuser&path=%2Ftmp%2Fhive%2Fhive
FSCK started by sshuser (auth:SIMPLE) from /[Link] for path /tmp/hive/hive at Thu Jul 06 20:13:58 UTC 2017
.
/tmp/hive/hive/4f3f4253-e6d0-42ac-88bc-90f0ea03602c/[Link]: Under replicated BP-1867508080-[Link]-
1499348422953:blk_1073741826_1002. Target Replicas is 3 but found 1 live replica(s), 0 decommissioned
replica(s) and 0 decommissioning replica(s).
.
/tmp/hive/hive/e7c03964-ff3a-4ee1-aa3c-90637a1f4591/[Link]: CORRUPT blockpool BP-1867508080-[Link]-
1499348422953 block blk_1073741825
You can also view the HDFS status in Ambari UI by selecting the HDFS service on the left (direct link:
[Link] )
You may also see one or more critical errors on the active or standby NameNodes. Click the NameNode link next to
the alert to view the NameNode Blocks Health.
To clean up the scratch files, removing the block replication errors, SSH into each head node to run the following
command:
hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/
Warning: This can break Hive if some jobs are still running.
How to Prevent HDInsight from getting stuck in safe mode due to under-replicated blocks
There are some ways in which you can prevent HDInsight from being left in safe mode. A few options are:
Stop all Hive jobs before scaling HDInsight down. Alternately, schedule the scale down process to avoid
conflicting with running Hive jobs.
Manually clean up Hive's scratch Tmp directory files in HDFS before scaling down.
Only scale down HDInsight to 3 worker nodes, minimum. Avoid going as low as 1 worker node.
Run the command to leave safe mode, if needed.
Let’s go through these possibilities in more detail:
Stop all Hive jobs
Stop all Hive jobs before scaling down to 1 worker node. If you know your workload is scheduled, then execute
your scale down after Hive work is done.
This will help minimize the number of scratch files in the tmp folder (if any).
Manually clean up Hive's scratch files
If Hive has left behind temporary files before you scale down, then you can manually clean up the tmp files before
scaling down to avoid safe mode.
You should stop Hive services to be safe, and at a minimum, make sure all queries and jobs are completed.
You can list the contents of the hdfs://mycluster/tmp/hive/ directory to see if it contains any files:
If you know Hive is done with these files, you can remove them. You should stop Hive services beforehand.
As stated earlier, this can break Hive if some jobs are still running, so refrain from cleaning up the scratch files
unless all Hive jobs are done. Be sure that Hive does not have any queries running by looking in the Yarn
ResourceManager UI page before doing so, as detailed at the beginning of the article.
Example command line to remove files from HDFS:
hadoop fs -rm -r -skipTrash hdfs://mycluster/tmp/hive/
HDInsight on Windows:
Next steps
In this article, we covered the various ways in which you can scale the number of nodes in your HDInsight cluster,
as well as some potential impacts scaling down can have, particularly while executing jobs. These issues may not
occur often, but following the exercise of scaling down when there are no running jobs is a practice that should
prevent issues during the process, as well as further down the road. Learn more about the HDInsight cluster
architecture, using Ambari, and scaling your cluster by following the links below.
HDInsight Architecture
Scale clusters
Manage HDInsight clusters by using the Ambari Web UI
Using External Metadata Stores
8/16/2017 • 3 min to read • Edit Online
Hive Metastore is critical part of Hadoop architecture as it acts as a central schema repository which can be used
by other access tools like Spark, Interactive Hive (LLAP), Presto, Pig, and many other Big Data engines.
Oozie Metastore
Apache Oozie is a workflow/coordination system that manages Hadoop jobs. It supports Hadoop jobs for Apache
MapReduce, Pig, Hive and others. Oozie uses a Metastore to store details about current and completed worklflows.
To increase performance when using Oozie, you can use Azure SQL Database as a custom metastore. The
metastore can also provide access to Oozie job data after you delete your cluster.
For instructions on creating an Oozie metastore with Azure SQL Database, see Use Oozie for workflows.
See Next
Operationalize Data Pipelines with Oozie: Learn how to build a data pipeline that uses Hive to summarize CSV
flight delay data, stage the prepared data in Azure Storage blobs and then use Sqoop to load the summarized
data into Azure SQL Database. A Metastore is created for both Hive and Oozie.
Manage Ambari - Authorize Users to Ambari
8/16/2017 • 5 min to read • Edit Online
Domain-joined HDInsight clusters provide enterprise-grade capabilities, including Azure Active Directory-based
authentication. You can synchronize new users added to Azure AD groups that have been provided access to the
cluster, allowing those specific users to perform certain actions. Currently, working with users, groups, and
permissions in Ambari is only supported when using a domain-joined HDInsight cluster.
Active Directory users can log on to the cluster nodes using their domain credentials. They can also use their
domain credentials to authenticate with other approved endpoints like Hue, Ambari Views, ODBC, JDBC,
PowerShell and REST APIs to interact with the cluster.
WARNING
Do not change the password of the Ambari watchdog (hdinsightwatchdog) on your Linux-based HDInsight cluster. Changing
the password breaks the ability to use script actions or perform scaling operations with your cluster.
If you have not already done so, follow these instructions to provision a new domain-joined cluster.
Most of the actions in this article will be performed from the Ambari Management Page on the Ambari Web UI.
To get there, browse to [Link] CLUSTER NAME>.[Link] , substituting <YOUR CLUSTER NAME> . Enter
your cluster administrator username and password that you defined when creating your cluster, when prompted.
Then, from the Ambari dashboard, select Manage Ambari underneath the admin menu.
1. On the Views page, expand the HIVE row. By default, you will see a Hive view that is auto-created when the Hive
services is added to the cluster. Select the listed Hive view. Notice that you have the option to create more Hive
view instances if desired.
1. Scroll toward the bottom of the View page. Under the Permissions section, you have two options for granting
domain users permissions to the view:
Grant permission to these users
Select, or finish typing, the user name. There's a box named New next to the user's name you added.
This is to add additional users, if desired. When finished, click the blue checkbox to save your
changes.
2. To add a group, click the Add Group button.
Start typing the group name. As with adding a user, when you start to type, you will see a dropdown
list of matching names.
The process of selecting a suggested group name, or typing the whole name, as well as adding more
than one group, is the same as for adding users. Click the blue checkbox to save your changes
when done.
Adding users directly to a view is useful when you want to assign permissions to a user to use that view, but do not
necessarily want them to be a member of a group that has other permissions the user should not have. In practice,
however, it is preferable to assign permissions to groups, as it reduces the amount of administrative overhead
managing user access.
To see the list of permissions provided by each role, click on the blue question mark next to the Roles table header
on the Roles page.
On this page, there are two different views you can use to manage roles for users and groups: Block and List.
Block displays each role in its own role, providing the familiar Assign roles to these users and Assign roles to
these groups options.
List provides quick editing capabilities in two categories: Users and Groups.
The Users category of the List view displays a list of all users, allowing you to select a role for each user in the
dropdown list.
The Groups category of the List view displays all of the groups, and the role assigned to each group. In our
example, the list of groups are syncrhonized from our Azure AD groups that were specified in the Access user
group property of the Domain settings during cluster creation. Please see the Create HDInsight cluster section of
the Configure Domain-joined HDInsight clusters article for reference.
In the screenshot above, the hiveusers group is assigned the Cluster User role. This is essentially a read-only role
that allows the users of that group to view service configurations and cluster metrics, without being able to alter
any related settings.
Next steps
In this article, we learned how to assign domain users to Views and Roles in Ambari. Please use the links below to
find out more about Domain-joined HDInsight clusters, and operations available to domain users.
Configure Hive policies in Domain-joined HDInsight
Manage Domain-joined HDInsight clusters
Synchronize Azure AD users to the cluster
Use the Hive View with Hadoop in HDInsight
Manage Domain-joined HDInsight clusters (Preview)
8/16/2017 • 3 min to read • Edit Online
Learn the users and the roles in Domain-joined HDInsight, and how to manage domain-joined HDInsight clusters.
Next steps
For configuring a Domain-joined HDInsight cluster, see Configure Domain-joined HDInsight clusters.
For configuring Hive policies and run Hive queries, see Configure Hive policies for Domain-joined HDInsight
clusters.
For running Hive queries using SSH on Domain-joined HDInsight clusters, see Use SSH with HDInsight.
Add ACLs for Users at the File and Folder Levels
8/16/2017 • 4 min to read • Edit Online
Domain-joined HDInsight clusters take advantage of strong authentication with Azure Active Directory (Azure AD)
users, as well as use role-based access control (RBAC) policies for various services, such as YARN and Hive. If your
default data store for your cluster is Azure Storage, or WASB (Windows Azure Storage Blobs), you can enforce file
and folder-level permissions as well. Doing so allows you to control access to the cluster's files by assigning your
synchronized Azure AD users and groups through Apache Ranger.
HDInsight domain-joined clusters' Apache Ranger instance comes preconfigured with the Ranger-WASB service.
This service is a policy management engine that is similar to Ranger-HDFS from a user interface standpoint, but
varies in its application and enforcement of Ranger's policy specifications. Namely, if the resource request does not
have a matching Ranger policy, the default response is DENY. In other words, Ranger does not hand off permission
checking to WASB.
DENY rules are evaluated first, followed by ALLOW rules. At the end of matching, a DENY is returned if no policies
are matched.
USER variable
When assigning policies for each user to access a corresponding /user/{username} directory, you may use the
{USER} variable. For example:
resource: path=/app-logs/{USER}, user: {USER}, recursive=true, permissions: all, delegateAdmin=true
The above policy grants users access to their own subfolder underneath the /app-logs/ directory. This is what the
policy looks like in the Ranger user interface:
/data/finance/, bob, WRITE /data bob, Create file ALLOW - Intermediate folder
/data/finance/[Link] ‘finance’ is created, because
of ancestor check
/data/finance/, bob, WRITE /data alice, Create file DENY - No matching policy
/data/finance/[Link]
/data/finance*, bob, WRITE /data bob, Create file ALLOW - Missing / after
/data/finance/[Link] 'finance' in policy; recursive
policy not required, but it will
work because of the
recursive policy in this case
Permissions are required at different levels (at the folder level or at the file level), based on the type of operation.
For example, a "read/open" call requires read-access at the file level, whereas a "create" call requires permissions at
the ancestor folder level.
Wildcards (*)
When wildcards ("*") are present in the path for a policy, it doesn't only apply to one directory, it also applies to the
entire subtree. This is known as "recursion", which some may be familiar with implementing via a recurse-flag . In
Ranger-WASB, the wildcard implicitly means recursion as well as a partial name match.
To view current file and folder permissions for your cluster's associated Azure Storage account, click the
CLUSTERNAME_wasb link located within the WASB panel.
This will take you to your list of policies. As you can see, several policies are added out-of-the-box. Here you can see
whether the policy is enabled, if audit logging is configured, what the assigned groups and users are, as well as the
policy name and id. In the right-hand Action colum are two buttons for each policy: Edit and Delete.
Adding a new policy
1. On the top-right section of the WASB policies page, click Add New Policy.
2. Enter a descriptive Policy Name. Specify the Azure Storage Account for your cluster
(ACCOUNT_NAME.[Link]). Enter the Storage Account Container specified when you
created your cluster. Type in the Relative Path (relative to the cluster) for your folder or file.
1. Below the form, specify your Allow Conditions for this new resource. You may select groups and/or users, and
their permissions. In this case, we're allowing all users in the sales group to have read/write access.
1. Allow all sales users, deny all interns, except for an intern whose user name is "hiveuser3", who should have
Read access:
Next steps
In this article, we covered the steps necessary to add and edit user and group access policies to Azure Storage
(WASB) files and folders. Because domain-joined clusters come preconfigured with many policies out-of-the-box,
feel free to look at the details of those policies to learn different ways policies can be expressed in Apache Ranger.
Configure Hive policies in Domain-joined HDInsight
Manage Domain-joined HDInsight clusters
Manage Ambari - Authorize Users to Ambari
Synchronized Azure AD users and groups
Sync Other Users from Azure AD to Cluster
8/16/2017 • 4 min to read • Edit Online
When you provision a domain-joined HDInsight cluster, you are able to take advantage of strong authentication
with Azure Active Directory (Azure AD) users, as well as use role-based access control (RBAC) policies. As you add
more users and groups to Azure AD, you will need to synchronize those users who you want to have access to
your cluster.
1. Complete the new user form. Select groups you created for assigning cluster-based permissions. In our
example, we created a group named "HiveUsers", to which we will assign our new users. If you followed the
step-by-step instructions for provisioning your domain-joined cluster, you will have added two groups:
"HiveUsers" and "AAD DC Administrators".
1. Click Create.
1. Copy the ssh command and paste into your SSH client. Enter the ssh user password when prompted.
2. After authenticating, enter the following command, replacing the <YOUR PASSWORD> and
<YOUR CLUSTER NAME> values:
To see the status of the synchronization, execute a new curl command, using the href value returned from the
previous command, replacing the <YOUR PASSWORD> and <YOUR DOMAIN> values:
{
"href" : "[Link]
"Event" : {
"id" : 1,
"specs" : [
{
"sync_type" : "existing",
"principal_type" : "groups"
}
],
"status" : "COMPLETE",
"status_detail" : "Completed LDAP sync.",
"summary" : {
"groups" : {
"created" : 0,
"removed" : 0,
"updated" : 0
},
"memberships" : {
"created" : 1,
"removed" : 0
},
"users" : {
"created" : 1,
"removed" : 0,
"skipped" : 0,
"updated" : 0
}
},
"sync_time" : {
"end" : 1497994072182,
"start" : 1497994071100
}
}
}
From our result, we can see that the status is COMPLETE, and one new user was created, and the user was
assigned a membership. This means that the user was assigned to the synchronized LDAP group (HiveUsers in this
example) in Ambari, since the user was added to the same group in Azure AD.
Please note, only the Azure AD groups that were specified in the Access user group property of the Domain
settings during cluster creation will be synchronized using this method. Please see the Create HDInsight
cluster section of the Configure Domain-joined HDInsight clusters article for reference.
Verify that the new Azure AD user was added
Open the Ambari Web UI to verify that the new Azure AD user was added. You can access the Ambari Web UI by
browsing to [Link] CLUSTER NAME>.[Link] , substituting <YOUR CLUSTER NAME> . Enter your cluster
administrator username and password that you defined when creating your cluster, when prompted.
1. From the Ambari dashboard, select Manage Ambari underneath the admin menu.
1. Select Users underneath the User + Group Management menu group on the left-hand side of the page.
1. You should see your new user listed within the Users table. Note that the Type is set to LDAP, instead of Local.
Next steps
This article focused on the steps required to synchronize users from your Azure AD tenant to your HDInsight
cluster. Use the links below to learn more about domain-joined HDInsight and assigning your new users to Hive
policies.
Configure Hive policies in Domain-joined HDInsight
Manage Domain-joined HDInsight clusters
Manage Ambari - Authorize Users to Ambari
Create on-demand Hadoop clusters in HDInsight
using Azure Data Factory
8/16/2017 • 17 min to read • Edit Online
Azure Data Factory is a cloud-based data integration service that orchestrates and automates the movement and
transformation of data. It can create a HDInsight Hadoop cluster just-in-time to process an input data slice and
delete the cluster when the processing is complete. Some of the benefits of using an on-demand HDInsight
Hadoop cluster are:
You only pay for the time a job is running on the HDInsight Hadoop cluster (plus a brief configurable idle time).
The billing for HDInsight clusters is pro-rated per minute, whether you are using them or not. When you use an
on-demand HDInsight linked service in Data Factory, the clusters are created on-demand, and the clusters are
deleted automatically when the jobs are completed. Therefore, you only pay for the job running time and the
brief idle time (time-to-live setting).
You can create a workflow using a Data Factory pipeline. For example, you can have the pipeline to copy data
from an on-premises SQL Server to an Azure blob storage, process the data by running a Hive script and a Pig
script on an on-demand HDInsight Hadoop cluster. Then, copy the result data to an Azure SQL Data Warehouse
for BI applications to consume.
You can schedule the workflow to run periodically (hourly, daily, weekly, monthly, etc.).
In Azure Data Factory, a data factory can have one or more data pipelines. A data pipeline has one or more
activities. There are two types of activities: Data Movement Activities and Data Transformation Activities. You use
data movement activities (currently, only Copy Activity) to move data from a source data store to a destination data
store. You use data transformation activities to transform/process data. HDInsight Hive Activity is one of the
transformation activities supported by Data Factory. You use the Hive transformation activity in this tutorial.
You can configure a hive activity to use your own HDInsight Hadoop cluster or an on-demand HDInsight Hadoop
cluster. In this tutorial, the Hive activity in the data factory pipeline is configured to use an on-demand HDInsight
cluster. Therefore, when the activity runs to process a data slice, here is what happens:
1. An HDInsight Hadoop cluster is automatically created for you just-in-time to process the slice.
2. The input data is processed by running a HiveQL script on the cluster.
3. The HDInsight Hadoop cluster is deleted after the processing is complete and the cluster is idle for the
configured amount of time ( timeToLive setting). If the next data slice is available for processing within this
timeToLive idle time, the same cluster is used to process the slice.
In this tutorial, the HiveQL script associated with the hive activity performs the following actions:
1. Creates an external table that references the raw web log data stored in an Azure Blob Storage container.
2. Partitions the raw data by year and month.
3. Stores the partitioned data in the Azure Blob Storage container.
In this tutorial, the HiveQL script associated with the hive activity creates an external table that references the raw
web log data stored in the Azure Blob Storage container. Here are the sample rows for each month in the input file.
2014-01-01,02:01:09,SAMPLEWEBSITE,GET,/blogposts/mvc4/[Link],X-ARR-LOG-ID=2ec4b8ad-3cf0-4442-93ab-
837317ece6a1,80,-,[Link],Mozilla/5.0+(Windows+NT+6.3;+WOW64)+AppleWebKit/537.36+
(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36,-,[Link]
[Link],\N,200,0,0,53175,871
2014-02-01,02:01:10,SAMPLEWEBSITE,GET,/blogposts/mvc4/[Link],X-ARR-LOG-ID=d7472a26-431a-4a4d-99eb-
c7b4fda2cf4c,80,-,[Link],Mozilla/5.0+(Windows+NT+6.3;+WOW64)+AppleWebKit/537.36+
(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36,-,[Link]
[Link],\N,200,0,0,30184,871
2014-03-01,02:01:10,SAMPLEWEBSITE,GET,/blogposts/mvc4/[Link],X-ARR-LOG-ID=d7472a26-431a-4a4d-99eb-
c7b4fda2cf4c,80,-,[Link],Mozilla/5.0+(Windows+NT+6.3;+WOW64)+AppleWebKit/537.36+
(KHTML,+like+Gecko)+Chrome/31.0.1650.63+Safari/537.36,-,[Link]
[Link],\N,200,0,0,30184,871
The HiveQL script partitions the raw data by year and month. It creates three output folders based on the previous
input. Each folder contains a file with entries from each month.
adfgetstarted/partitioneddata/year=2014/month=1/000000_0
adfgetstarted/partitioneddata/year=2014/month=2/000000_0
adfgetstarted/partitioneddata/year=2014/month=3/000000_0
For a list of Data Factory data transformation activities in addition to Hive activity, see Transform and analyze using
Azure Data Factory.
Prerequisites
Before you begin the instructions in this article, you must have the following items:
Azure subscription
Azure PowerShell
IMPORTANT
Azure PowerShell support for managing HDInsight resources using Azure Service Manager is deprecated, and was removed
on January 1, 2017. The steps in this document use the new HDInsight cmdlets that work with Azure Resource Manager.
Please follow the steps in Install and configure Azure PowerShell to install the latest version of Azure PowerShell. If you have
scripts that need to be modified to use the new cmdlets that work with Azure Resource Manager, see Migrating to Azure
Resource Manager-based development tools for HDInsight clusters for more information.
IMPORTANT
Specify names for the Azure resource group and the Azure storage account that will be created by the script (
$resourceGroupName and $storageAccountName variables). Write down resource group name, storage account name,
and storage account key output by the script. You need them in the next section.
$sourceStorageAccountName = "hditutorialdata"
$sourceContainerName = "adfhiveactivity"
$destStorageAccountName = $storageAccountName
$destContainerName = "adfgetstarted" # don't change this value.
####################################
# Connect to Azure
####################################
#region - Connect to Azure subscription
Write-Host "`nConnecting to your Azure subscription ..." -ForegroundColor Green
Login-AzureRmAccount
Get-AzureRmContext
#endregion
####################################
# Create a resource group, storage, and container
####################################
$destStorageAccountKey = (Get-AzureRmStorageAccountKey `
-ResourceGroupName $resourceGroupName `
-Name $destStorageAccountName)[0].Value
$sourceContext = New-AzureStorageContext `
-StorageAccountName $sourceStorageAccountName `
-Anonymous
$destContext = New-AzureStorageContext `
-StorageAccountName $destStorageAccountName `
-StorageAccountKey $destStorageAccountKey
####################################
# Copy files
####################################
#region - copy files
Write-Host "`nCopying files ..." -ForegroundColor Green
Write-Host "`nCopying files ..." -ForegroundColor Green
$blobs = Get-AzureStorageBlob `
-Context $sourceContext `
-Container $sourceContainerName
$blobs|Start-AzureStorageBlobCopy `
-DestContext $destContext `
-DestContainer $destContainerName
If you need help with the PowerShell script, see Using the Azure PowerShell with Azure Storage. If you like to use
Azure CLI instead, see the Appendix section for the Azure CLI script.
To examine the storage account and the contents
1. Sign on to the Azure portal.
2. Click Resource groups on the left pane.
3. Click the resource group name you created in your PowerShell script. Use the filter if you have too many
resource groups listed.
4. On the Resources tile, you should have one resource listed unless you share the resource group with other
projects. That resource is the storage account with the name you specified earlier. Click the storage account
name.
5. Click the Blobs tiles.
6. Click the adfgetstarted container. You see two folders: inputdata and script.
7. Open the folder and check the files in the folders. The inputdata folder contains the [Link] file with input data,
and the script folder contains the HiveQL script file.
2. Select Use existing option for the Resource group setting, and select the name of the resource group you
created in the previous step (using PowerShell script).
3. Make sure you select the same location as your provisioned storage account (from the previous step), if
available.
4. Enter a name for the data factory (Data Factory Name). This name must be globally unique.
5. Enter the storage account name and storage account key you wrote down in the previous step.
6. Select I agree to the terms and conditions stated above after reading through terms and conditions.
7. Select Pin to dashboard option.
8. Click Purchase. You will see a tile on the Dashboard called Deploying Template deployment. Wait until the
Resource group blade for your resource group opens. You can also click the tile titled after your resource
group name to open the resource group blade.
9. Click the tile to open the resource group if the resource group blade is not already open. Now you should see
the data factory resource listed in addition to the storage account resource.
10. Click the name of your data factory (value you specified for the Data Factory Name parameter).
11. In the Data Factory blade, click the Diagram tile. The diagram shows one activity with an input dataset, and
an output dataset:
If you drill down the list, you will see three folders for January, February, and March, with a log for each
month.
Data Factory entities in the template
Here is what the top-level Resource Manager template for a data factory looks like:
{
"contentVersion": "[Link]",
"$schema": "[Link]
"parameters": { ...
},
"variables": { ...
},
"resources": [
{
"name": "[parameters('dataFactoryName')]",
"apiVersion": "[variables('apiVersion')]",
"type": "[Link]/datafactories",
"location": "westus",
"resources": [
{ ... },
{ ... },
{ ... },
{ ... }
]
}
]
}
"resources": [
{
"name": "[parameters('dataFactoryName')]",
"apiVersion": "[variables('apiVersion')]",
"type": "[Link]/datafactories",
"location": "westus",
}
The dataFactoryName is the name of the data factory you specify when you deploy the template. Data factory is
currently only supported in the East US, West US, and North Europe regions.
Defining entities within the data factory
The following Data Factory entities are defined in the JSON template:
Azure Storage linked service
HDInsight on-demand linked service
Azure blob input dataset
Azure blob output dataset
Data pipeline with a copy activity
Azure Storage linked service
The Azure Storage linked service links your Azure storage account to the data factory. In this tutorial, the same
storage account is used as the default HDInsight storage account, input data storage, and output data storage.
Therefore, you define only one Azure Storage linked service. In the linked service definition, you specify the name
and key of your Azure storage account. See Azure Storage linked service for details about JSON properties used to
define an Azure Storage linked service.
{
"name": "[variables('storageLinkedServiceName')]",
"type": "linkedservices",
"dependsOn": [ "[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]" ],
"apiVersion": "[variables('apiVersion')]",
"properties": {
"type": "AzureStorage",
"typeProperties": {
"connectionString": "
[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',paramete
rs('storageAccountKey'))]"
}
}
}
The connectionString uses the storageAccountName and storageAccountKey parameters. You specify values for
these parameters while deploying the template.
HDInsight on-demand linked service
In the on-demand HDInsight linked service definition, you specify values for configuration parameters that are
used by the Data Factory service to create a HDInsight Hadoop cluster at runtime. See the Compute linked services
article for details about JSON properties used to define an HDInsight on-demand linked service.
{
"type": "linkedservices",
"name": "[variables('hdInsightOnDemandLinkedServiceName')]",
"dependsOn": [
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/linkedservices/',
variables('storageLinkedServiceName'))]"
],
"apiVersion": "[variables('apiVersion')]",
"properties": {
"type": "HDInsightOnDemand",
"typeProperties": {
"osType": "linux",
"version": "3.5",
"clusterSize": 1,
"sshUserName": "myuser",
"sshPassword": "MyPassword!",
"timeToLive": "00:30:00",
"linkedServiceName": "[variables('storageLinkedServiceName')]"
}
}
}
IMPORTANT
As more slices are processed, you see many containers in your Azure blob storage. If you do not need them for
troubleshooting the jobs, you may want to delete them to reduce the storage cost. The names of these containers follow a
pattern: "adfyourdatafactoryname-linkedservicename-datetimestamp". Use tools such as Microsoft Storage Explorer to
delete containers in your Azure blob storage.
{
"type": "datasets",
"name": "[variables('blobInputDatasetName')]",
"dependsOn": [
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/linkedServices/',
variables('storageLinkedServiceName'))]"
],
"apiVersion": "[variables('apiVersion')]",
"properties": {
"type": "AzureBlob",
"linkedServiceName": "[variables('storageLinkedServiceName')]",
"typeProperties": {
"fileName": "[Link]",
"folderPath": "adfgetstarted/inputdata",
"format": {
"type": "TextFormat",
"columnDelimiter": ","
}
},
"availability": {
"frequency": "Month",
"interval": 1
},
"external": true,
"policy": {}
}
}
"fileName": "[Link]",
"folderPath": "adfgetstarted/inputdata",
{
"type": "datasets",
"name": "[variables('blobOutputDatasetName')]",
"dependsOn": [
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/linkedServices/',
variables('storageLinkedServiceName'))]"
],
"apiVersion": "[variables('apiVersion')]",
"properties": {
"type": "AzureBlob",
"linkedServiceName": "[variables('storageLinkedServiceName')]",
"typeProperties": {
"folderPath": "adfgetstarted/partitioneddata",
"format": {
"type": "TextFormat",
"columnDelimiter": ","
}
},
"availability": {
"frequency": "Month",
"interval": 1,
"style": "EndOfInterval"
}
}
}
The folderPath specifies the path to the folder that holds the output data:
"folderPath": "adfgetstarted/partitioneddata",
"availability": {
"frequency": "Month",
"interval": 1,
"style": "EndOfInterval"
},
In Azure Data Factory, the output dataset availability drives the pipeline. In this example, the slice is produced
monthly on the last day of month ( EndOfInterval ). For more information, see Data Factory Scheduling and
Execution.
Data pipeline
You define a pipeline that transforms data by running a Hive script on an on-demand Azure HDInsight cluster. See
Pipeline JSON for descriptions of JSON elements used to define a pipeline in this example.
{
"type": "datapipelines",
"name": "[parameters('dataFactoryName')]",
"dependsOn": [
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/linkedServices/',
variables('storageLinkedServiceName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/linkedServices/',
variables('hdInsightOnDemandLinkedServiceName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/datasets/',
variables('blobInputDatasetName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'), '/datasets/',
variables('blobOutputDatasetName'))]"
],
"apiVersion": "[variables('apiVersion')]",
"properties": {
"description": "Azure Data Factory pipeline with an Hadoop Hive activity",
"activities": [
{
"type": "HDInsightHive",
"typeProperties": {
"scriptPath": "adfgetstarted/script/[Link]",
"scriptLinkedService": "[variables('storageLinkedServiceName')]",
"defines": {
"inputtable": "[concat('wasb://adfgetstarted@', parameters('storageAccountName'),
'.[Link]/inputdata')]",
"partitionedtable": "[concat('wasb://adfgetstarted@',
parameters('storageAccountName'), '.[Link]/partitioneddata')]"
}
},
"inputs": [
{
"name": "AzureBlobInput"
}
],
"outputs": [
{
"name": "AzureBlobOutput"
}
],
"policy": {
"concurrency": 1,
"retry": 3
},
"name": "RunSampleHiveActivity",
"linkedServiceName": "HDInsightOnDemandLinkedService"
}
],
"start": "2017-01-01T00:00:00Z",
"end": "2017-01-31T00:00:00Z",
"isPaused": false
}
}
The pipeline contains one activity, HDInsightHive activity. As both start and end dates are in January 2017, data for
only one month (a slice) is processed. Both start and end of the activity have a past date, so the Data Factory
processes data for the month immediately. If the end is a future date, the data factory creates another slice when
the time comes. For more information, see Data Factory Scheduling and Execution.
{
"name": "[parameters('defaultStorageAccountName')]",
"type": "[Link]/storageAccounts",
"location": "[parameters('location')]",
"apiVersion": "[variables('defaultApiVersion')]",
"dependsOn": [ ],
"tags": {
},
"properties": {
"accountType": "Standard_LRS"
}
},
Add a new linked service that points to the new storage account:
{
"dependsOn": [ "[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]" ],
"type": "linkedservices",
"name": "[variables('defaultStorageLinkedServiceName')]",
"apiVersion": "[variables('apiVersion')]",
"properties": {
"type": "AzureStorage",
"typeProperties": {
"connectionString": "
[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('defaultStorageAccountName'),';AccountK
ey=',listKeys(resourceId('[Link]/storageAccounts', variables('defaultStorageAccountName')),
variables('defaultApiVersion')).key1)]"
}
}
},
Configure the HDInsight on-demand linked service with an additional dependsOn and an
additionalLinkedServiceNames :
{
"dependsOn": [
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'),
'/linkedservices/', variables('defaultStorageLinkedServiceName'))]",
"[concat('[Link]/dataFactories/', parameters('dataFactoryName'),
'/linkedservices/', variables('storageLinkedServiceName'))]"
],
"type": "linkedservices",
"name": "[variables('hdInsightOnDemandLinkedServiceName')]",
"apiVersion": "[variables('apiVersion')]",
"properties": {
"type": "HDInsightOnDemand",
"typeProperties": {
"osType": "linux",
"version": "3.2",
"clusterSize": 1,
"sshUserName": "myuser",
"sshPassword": "MyPassword!",
"timeToLive": "00:30:00",
"linkedServiceName": "[variables('storageLinkedServiceName')]",
"additionalLinkedServiceNames": "[variables('defaultStorageLinkedServiceName')]"
}
}
},
Next steps
In this article, you have learned how to use Azure Data Factory to create on-demand HDInsight cluster to
process Hive jobs. To read more:
Hadoop tutorial: Get started using Linux-based Hadoop in HDInsight
Create Linux-based Hadoop clusters in HDInsight
HDInsight documentation
Data factory documentation
Appendix
Azure CLI script
You can use Azure CLI instead of using Azure PowerShell to do the tutorial. To use Azure CLI, first install Azure CLI
as per the following instructions:
[! IMPORTANT] Azure CLI support for managing HDInsight resources using Azure Service Manager (ASM) is
deprecated, and was removed on January 1, 2017. The steps in this document use the new Azure CLI commands
that work with Azure Resource Manager.
Please follow the steps in Install and configure Azure CLI to install the latest version of the Azure CLI. If you have
scripts that need to be modified to use the new commands that work with Azure Resource Manager, see Migrating
to Azure Resource Manager-based development tools for HDInsight clusters for more information.
Use Azure CLI to prepare the storage and copy the files
Run these commands one-by-one:
azure login
azure group create --name "<Azure Resource Group Name>" --location "East US 2"
azure storage account create --resource-group "<Azure Resource Group Name>" --location "East US 2" --sku-name
"LRS" "<Azure Storage Account Name>"
azure storage account keys list --resource-group "<Azure Resource Group Name>" "<Azure Storage Account Name>"
azure storage container create "adfgetstarted" --account-name "<Azure Storage AccountName>" --account-key "
<Azure Storage Account Key>"
The container name is adfgetstarted. Keep it as it is. Otherwise you need to update the Resource Manager template.
If you need help with this CLI script, see Using the Azure CLI with Azure Storage.
Key Scenarios to Monitor
8/16/2017 • 5 min to read • Edit Online
Overview
Monitoring the health of your HDInsight cluster, from resource utilization, to storage bottlenecks, to whether your
jobs are successfully running, is an important process for organizations of any size. Even when your code is well-
written and works well under the most stringent testing conditions, issues may surface only when that code is
executed under production-scale loads or when working with real world data. Other factors could be introduced,
such as human error; someone executed the wrong command or made an incorrect configuration change.
How much effort you put into making cluster monitoring a routine practice depends on how much downtime you
can afford, or whether the time to execute tasks is important to you. Outages or degraded performance can be very
costly to organizations, in the form of revenue loss or not meeting SLAs, or any number of consequences that can
have a negative impact on your business.
This article will go over some of the key scenarios to consider monitoring, linking to more information about steps
to conduct the monitoring, where appropriate.
COLOR DESCRIPTION
Yellow Ambari Server has not received a heartbeat from that host for
more than 3 minutes.
You'll also see columns showing the number of cores and amount of RAM for each host. Plus, there are cores that
show disk usage and the load average.
Click on any of the host names for a detailed look at components running on that host, as well as its metrics with a
selectable timeline of CPU usage, load, disk usage, memory usage, network usage, and processes.
Read Manage HDInsight clusters by using the Ambari Web UI for details on setting alerts and viewing metrics.
When there are multiple tenants who share a large cluster, there can be a lot of competition for that cluster's
resources. The CapacityScheduler is a pluggable scheduler which helps facilitate resource sharing through the
concept of queues. The CapacityScheduler also supports hierarchical queues to ensure that resources are shared
amongst the sub-queues of an organization before other queues are granted to use free resources. This provides
affinity for sharing free resources among the applications of a given organization.
YARN allows us to allocate resources to these queues, and it shows you whether all of your available resources
have been assigned. To view information about your queues, login to the Ambari Web UI, then select YARN
Queue Manager from the top menu.
On the YARN Queue Manager page, you will see a list of your queues on the left, along with the percentage of
capacity assigned to each.
For a more detailed look at your queues, from the Ambari dashboard, select the YARN service from the list on the
left. Then under the Quick Links dropdown menu, select ResourceManager UI underneath your active node.
On the ResourceManager UI, select Scheduler from the left-hand menu. You will see a list of your queues
underneath Application Queues. Here you can see the capacity used for each of your queues, how well the jobs are
distributed between them, and whether any are resource-constrained.
Next steps
This article introduced a few key scenarios to watch out for when monitoring your HDInsight cluster. Visit the links
below to find out more about troubleshooting and monitoring your clusters:
Analyze HDInsight logs
Debug apps with YARN logs
Enable heap dumps for Hadoop services on Linux-based HDInsight
Manage HDInsight clusters by using the Ambari
Web UI
8/16/2017 • 7 min to read • Edit Online
Apache Ambari simplifies the management and monitoring of a Hadoop cluster by providing an easy to use
web UI and REST API. Ambari is included on Linux-based HDInsight clusters, and is used to monitor the cluster
and make configuration changes.
In this document, you learn how to use the Ambari Web UI with an HDInsight cluster.
What is Ambari?
Apache Ambari simplifies Hadoop management by providing an easy-to-use web UI. You can use Ambari
create, manage, and monitor Hadoop clusters. Developers can integrate these capabilities into their
applications by using the Ambari REST APIs.
The Ambari Web UI is provided by default with HDInsight clusters that use the Linux operating system.
IMPORTANT
Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight
retirement on Windows.
Connectivity
The Ambari Web UI is available on your HDInsight cluster at HTTPS://[Link],
where CLUSTERNAME is the name of your cluster.
IMPORTANT
Connecting to Ambari on HDInsight requires HTTPS. When prompted for authentication, use the admin account name
and password you provided when the cluster was created.
Ambari Web UI
When connecting to the Ambari Web UI, you are prompted to authenticate to the page. Use the cluster admin
user (default Admin) and password you used during cluster creation.
When the page opens, note the bar at the top. This bar contains the following information and controls:
Ambari logo - Opens the dashboard, which can be used to monitor the cluster.
Cluster name # ops - Displays the number of ongoing Ambari operations. Selecting the cluster name
or # ops displays a list of background operations.
# alerts - Displays warnings or critical alerts, if any, for the cluster.
Dashboard - Displays the dashboard.
Services - Information and configuration settings for the services in the cluster.
Hosts - Information and configuration settings for the nodes in the cluster.
Alerts - A log of information, warnings, and critical alerts.
Admin - Software stack/services that are installed on the cluster, service account information, and
Kerberos security.
Admin button - Ambari management, user settings, and logout.
Monitoring
Alerts
The following list contains the common alert statuses used by Ambari:
OK
Warning
CRITICAL
UNKNOWN
Alerts other than OK cause the # alerts entry at the top of the page to display the number of alerts. Selecting
this entry displays the alerts and their status.
Alerts are organized into several default groups, which can be viewed from the Alerts page.
You can manage the groups by using the Actions menu and selecting Manage Alert Groups.
You can also manage alerting methods, and create alert notifications from the Actions menu by selecting
Manage Alert Notifications. Any current notifications are displayed. You can also create notifications from
here. Notifications can be sent via EMAIL or SNMP when specific alert/severity combinations occur. For
example, you can send an email message when any of the alerts in the YARN Default group is set to Critical.
Finally, selecting Manage Alert Settings from the Actions menu allows you to set the number of times an
alert must occur before a notification is sent. This setting can be used to prevent notifications for transient
errors.
Cluster
The Metrics tab of the dashboard contains a series of widgets that make it easy to monitor the status of your
cluster at a glance. Several widgets, such as CPU Usage, provide additional information when clicked.
The Heatmaps tab displays metrics as colored heatmaps, going from green to red.
For more information on the nodes within the cluster, select Hosts. Then select the specific node you are
interested in.
Services
The Services sidebar on the dashboard provides quick insight into the status of the services running on the
cluster. Various icons are used to indicate status or actions that should be taken. For example, a yellow recycle
symbol is displayed if a service needs to be recycled.
NOTE
The services displayed differ between HDInsight cluster types and versions. The services displayed here may be different
than the services displayed for your cluster.
Quick links
Some services display a Quick Links link at the top of the page. This can be used to access service-specific web
UIs, such as:
Job History - MapReduce job history.
Resource Manager - YARN ResourceManager UI.
NameNode - Hadoop Distributed File System (HDFS) NameNode UI.
Oozie Web UI - Oozie UI.
Selecting any of these links opens a new tab in your browser, which displays the selected page.
NOTE
Selecting the Quick Links entry for a service may return a "server not found" error. If you encounter this error, you must
use an SSH tunnel when using the Quick Links entry for this service. For information, see Use SSH Tunneling with
HDInsight
Management
Ambari users, groups, and permissions
Working with users, groups, and permissions are supported when using a domain joined HDInsight cluster. For
information on using the Ambari Management UI on a domain-joined cluster, see Manage domain-joined
HDInsight clusters.
WARNING
Do not change the password of the Ambari watchdog (hdinsightwatchdog) on your Linux-based HDInsight cluster.
Changing the password breaks the ability to use script actions or perform scaling operations with your cluster.
Hosts
The Hosts page lists all hosts in the cluster. To manage hosts, follow these steps.
NOTE
Adding, decommissioning, and recommissioning a host should not be used with HDInsight clusters.
NOTE
Do not use this action on HDInsight clusters.
NOTE
Do not use this action on HDInsight clusters.
Services
From the Dashboard or Services page, use the Actions button at the bottom of the list of services to stop and
start all services.
WARNING
While Add Service is listed in this menu, it should not be used to add services to the HDInsight cluster. New services
should be added using a Script Action during cluster provisioning. For more information on using Script Actions, see
Customize HDInsight clusters using Script Actions.
While the Actions button can restart all services, often you want to start, stop, or restart a specific service. Use
the following steps to perform actions on an individual service:
1. From the Dashboard or Services page, select a service.
2. From the top of the Summary tab, use the Service Actions button and select the action to take. This
restarts the service on all nodes.
NOTE
Restarting some services while the cluster is running may generate alerts. To avoid alerts, you can use the
Service Actions button to enable Maintenance mode for the service before performing the restart.
3. Once an action has been selected, the # op entry at the top of the page increments to show that a
background operation is occurring. If configured to display, the list of background operations is
displayed.
NOTE
If you enabled Maintenance mode for the service, remember to disable it by using the Service Actions button
once the operation has finished.
Ambari views
Ambari Views allow developers to plug UI elements into the Ambari Web UI using the Ambari Views
Framework. HDInsight provides the following views with Hadoop cluster types:
Yarn Queue Manager: The queue manager provides a simple UI for viewing and modifying YARN
queues.
Hive View: The Hive View allows you to run Hive queries directly from your web browser. You can save
queries, view results, save results to the cluster storage, or download results to your local system. For
more information on using Hive Views, see Use Hive Views with HDInsight.
Tez View: The Tez View allows you to better understand and optimize jobs. You can view information on
how Tez jobs are executed and what resources are used.
Manage HDInsight clusters by using the Ambari
REST API
8/16/2017 • 12 min to read • Edit Online
Learn how to use the Ambari REST API to manage and monitor Hadoop clusters in Azure HDInsight.
Apache Ambari simplifies the management and monitoring of a Hadoop cluster by providing an easy to use web
UI and REST API. Ambari is included on HDInsight clusters that use the Linux operating system. You can use
Ambari to monitor the cluster and make configuration changes.
What is Ambari
Apache Ambari provides web UI that can be used to provision, manage, and monitor Hadoop clusters. Developers
can integrate these capabilities into their applications by using the Ambari REST APIs.
Ambari is provided by default with Linux-based HDInsight clusters.
The examples in this document are provided for both the Bourne shell (bash) and PowerShell. The bash examples
were tested with GNU bash 4.3.11, but should work with other Unix shells. The PowerShell examples were tested
with PowerShell 5.0, but should work with PowerShell 3.0 or higher.
If using the Bourne shell (Bash), you must have the following installed:
cURL: cURL is a utility that can be used to work with REST APIs from the command line. In this document, it is
used to communicate with the Ambari REST API.
Whether using Bash or PowerShell, you must also have jq installed. Jq is a utility for working with JSON
documents. It is used in all the Bash examples, and one of the PowerShell examples.
Base URI for Ambari Rest API
The base URI for the Ambari REST API on HDInsight is
[Link] where CLUSTERNAME is the name of
your cluster.
IMPORTANT
While the cluster name in the fully qualified domain name (FQDN) part of the URI ([Link]) is
case-insensitive, other occurrences in the URI are case-sensitive. For example, if your cluster is named MyCluster , the
following are valid URIs:
[Link]
[Link]
The following URIs return an error because the second occurrence of the name is not the correct case.
[Link]
[Link]
Authentication
Connecting to Ambari on HDInsight requires HTTPS. Use the admin account name (the default is admin) and
password you provided during cluster creation.
IMPORTANT
The Bash examples in this document make the following assumptions:
The login name for the cluster is the default value of admin .
$PASSWORD contains the password for the HDInsight login command. You can set this value by using
PASSWORD='mypassword' .
$CLUSTERNAME contains the name of the cluster. You can set this value by using set CLUSTERNAME='clustername'
IMPORTANT
The PowerShell examples in this document make the following assumptions:
$creds is a credential object that contains the admin login and password for the cluster. You can set this value by
using $creds = Get-Credential -UserName "admin" -Message "Enter the HDInsight login" and providing the
credentials when prompted.
$clusterName is a string that contains the name of the cluster. You can set this value by using
$clusterName="clustername" .
Both examples return a JSON document that begins with information similar to the following example:
{
"href" : "[Link]
"Clusters" : {
"cluster_id" : 2,
"cluster_name" : "CLUSTERNAME",
"health_report" : {
"Host/stale_config" : 0,
"Host/maintenance_state" : 0,
"Host/host_state/HEALTHY" : 7,
"Host/host_state/UNHEALTHY" : 0,
"Host/host_state/HEARTBEAT_LOST" : 0,
"Host/host_state/INIT" : 0,
"Host/host_status/HEALTHY" : 7,
"Host/host_status/UNHEALTHY" : 0,
"Host/host_status/UNKNOWN" : 0,
"Host/host_status/ALERT" : 0
...
PowerShell 3.0 and higher provides the ConvertFrom-Json cmdlet, which converts the JSON document into an
object that is easier to work with from PowerShell. The following example uses ConvertFrom-Json to display only
the health_report information from the results.
NOTE
While most examples in this document use ConvertFrom-Json to display elements from the response document, the
Update Ambari configuration example uses jq. Jq is used in this example to construct a new template from the JSON
response document.
For a complete reference of the REST API, see Ambari API Reference V1.
Head nodes
Worker nodes
Zookeeper nodes
To find the IP address, you must know the internal fully qualified domain name (FQDN) of the cluster nodes. Once
you have the FQDN, you can then get the IP address of the host. The following examples first query Ambari for the
FQDN of all the host nodes, then query Ambari for the IP address of each host.
$uri = "[Link]
$resp = Invoke-WebRequest -Uri $uri -Credential $creds
$respObj = ConvertFrom-Json $[Link]
foreach($item in $[Link]) {
$hostName = [string]$[Link].host_name
$hostInfoResp = Invoke-WebRequest -Uri "$uri/$hostName" `
-Credential $creds
$hostInfoObj = ConvertFrom-Json $hostInfoResp
$hostIp = $[Link]
"$hostName <--> $hostIp"
}
The return value is similar to [Link] , where ACCOUNTNAME is the name of the
Data Lake Store account.
To find the directory within Data Lake Store that contains the storage for the cluster, use the following
examples:
The return value is similar to /clusters/CLUSTERNAME/ . This value is a path within the Data Lake Store
account. This path is the root of the HDFS compatible file system for the cluster.
NOTE
The Get-AzureRmHDInsightCluster cmdlet provided by Azure PowerShell also returns the storage information for the
cluster.
Example: Get configuration
1. Get the configurations that are available for your cluster.
This example returns a JSON document containing the current configuration (identified by the tag value)
for the components installed on the cluster. The following example is an excerpt from the data returned
from a Spark cluster type.
"spark-metrics-properties" : {
"tag" : "INITIAL",
"user" : "admin",
"version" : 1
},
"spark-thrift-fairscheduler" : {
"tag" : "INITIAL",
"user" : "admin",
"version" : 1
},
"spark-thrift-sparkconf" : {
"tag" : "INITIAL",
"user" : "admin",
"version" : 1
}
2. Get the configuration for the component that you are interested in. In the following example, replace
INITIAL with the tag value returned from the previous request.
This example returns a JSON document containing the current configuration for the core-site component.
This example returns a JSON document containing the current configuration (identified by the tag value)
for the components installed on the cluster. The following example is an excerpt from the data returned
from a Spark cluster type.
"spark-metrics-properties" : {
"tag" : "INITIAL",
"user" : "admin",
"version" : 1
},
"spark-thrift-fairscheduler" : {
"tag" : "INITIAL",
"user" : "admin",
"version" : 1
},
"spark-thrift-sparkconf" : {
"tag" : "INITIAL",
"user" : "admin",
"version" : 1
}
From this list, you need to copy the name of the component (for example, spark_thrift_sparkconf and the
tag value.
2. Retrieve the configuration for the component and tag by using the following commands:
NOTE
Replace spark-thrift-sparkconf and INITIAL with the component and tag that you want to retrieve the
configuration for.
Jq is used to turn the data retrieved from HDInsight into a new configuration template. Specifically, these
examples perform the following actions:
Creates a unique value containing the string "version" and the date, which is stored in newtag .
Creates a root document for the new desired configuration.
Gets the contents of the .items[] array and adds it under the desired_config element.
Deletes the href , version , and Config elements, as these elements aren't needed to submit a new
configuration.
Adds a tag element with a value of version################# . The numeric portion is based on the
current date. Each configuration must have a unique tag.
Finally, the data is saved to the [Link] document. The document structure should appear
similar to the following example:
{
"Clusters": {
"desired_config": {
"tag": "version1459260185774265400",
"type": "spark-thrift-sparkconf",
"properties": {
....
},
"properties_attributes": {
....
}
}
}
3. Open the [Link] document and modify/add values in the properties object. The following
example changes the value of "[Link]" from "1g" to "3g" . It also adds
"[Link]" with a value of "256m" .
"[Link]": "3g",
"[Link]": "256m",
These commands submit the contents of the [Link] file to the cluster as the new desired
configuration. The request returns a JSON document. The versionTag element in this document should
match the version you submitted, and the configs object contains the configuration changes you
requested.
Example: Restart a service component
At this point, if you look at the Ambari web UI, the Spark service indicates that it needs to be restarted before the
new configuration can take effect. Use the following steps to restart the service.
1. Use the following to enable maintenance mode for the Spark service:
curl -u admin:$PASSWORD -sS -H "X-Requested-By: ambari" \
-X PUT -d '{"RequestInfo": {"context": "turning on maintenance mode for SPARK"},"Body": {"ServiceInfo":
{"maintenance_state":"ON"}}}' \
"[Link]
These commands send a JSON document to the server that turns on maintenance mode. You can verify
that the service is now in maintenance mode using the following request:
IMPORTANT
The href value returned by this URI is using the internal IP address of the cluster node. To use it from outside the
cluster, replace the `[Link]:8080' portion with the FQDN of the cluster.
Next steps
For a complete reference of the REST API, see Ambari API Reference V1.
Manage Hadoop clusters in HDInsight by using the
Azure portal
8/16/2017 • 12 min to read • Edit Online
Using the Azure portal, you can manage Hadoop clusters in Azure HDInsight. Use the tab selector for information
on managing Hadoop clusters in HDInsight using other tools.
Now let's review your options for managing and administering your HDInsight clusters in the Azure portal.
Prerequisites
Before you begin this article, you must have the following:
An Azure subscription. See Get Azure free trial.
Create clusters
WARNING
Billing for HDInsight clusters is prorated per minute, whether you are using them or not. Be sure to delete your cluster after
you have finished using it. For more information, see How to delete an HDInsight cluster.
HDInsight works with a wide range of Hadoop components. For the list of the components that have been verified
and supported, see What version of Hadoop is in Azure HDInsight. For the detailed steps to create a cluster using
the Azure Portal, see Create Hadoop clusters in HDInsight.
Access control requirements
You must specify an Azure subscription when you create an HDInsight cluster. This cluster can be created in either a
new Azure Resource group or an existing Resource group. You can use the following steps to verify your
permissions for creating HDInsight clusters:
To use an existing resource group.
1. Sign in to the Azure portal.
2. Select Resource groups from the left menu to list the resource groups.
3. Select the resource group you want to use for creating your HDInsight cluster.
4. Select Access control (IAM), and verify that you (or a group that you belong to) have at least the
Contributor access to the resource group.
To create a new resource group
1. Sign in to the Azure portal.
2. Select Subscription from the left menu. It has a yellow key icon. You shall see a list of subscriptions.
3. Select the subscription that you use to create clusters.
4. Select My permissions. It shows your role on the subscription. You need at least Contributor access to
create HDInsight cluster.
If you recieve the NoRegisteredProviderFound error or the MissingSubscriptionRegistration error, see
Troubleshoot common Azure deployment errors with Azure Resource Manager.
Overview menu:
Dashboard: Opens the cluster dashboard, which is Ambari Web for Linux-based clusters.
Secure Shell: Shows the instructions to connect to the cluster using Secure Shell (SSH) connection.
Scale Cluster: Allows you to change the number of worker nodes for this cluster.
Delete: Deletes the cluster.
Left menu:
Activity logs: Show and query logs of Azure Resource Manager activity.
Access control (IAM): Use role assignments. See Use role assignments to manage access to your Azure
subscription resources.
Tags: Allows you to set key/value pairs to define a custom taxonomy of your cloud services. For example,
you may create a key named project, and then use a common value for all services associated with a
specific project.
Diagnose and solve problems: Display troubleshooting information.
Locks: Add lock to prevent the cluster being modified or deleted.
Automation script: Display and export the Azure Resource Manager template for the cluster. Currently,
you can only export the dependent Azure storage account. See Create Linux-based Hadoop clusters in
HDInsight using Azure Resource Manager templates.
Quick Start: Displays information that will help you get started using HDInsight.
Tools for HDInsight: Help information for HDInsight related tools.
Cluster Login: Display the cluster login information.
Subscription Core Usage: Display the used and available cores for your subscription.
Scale Cluster: Increase and decrease the number of cluster worker nodes. SeeScale clusters.
Secure Shell: Shows the instructions to connect to the cluster using Secure Shell (SSH) connection. For
more information, see Use SSH with HDInsight.
HDInsight Partner: Add/remove the current HDInsight Partner.
External Metastores: View the Hive and Oozie metastores. The metastores can only be configured
during the cluster creation process. See use Hive/Oozie metastore.
Script Actions: Run Bash scripts on the cluster. See Customize Linux-based HDInsight clusters using
Script Action.
Applications: Add/remove HDInsight applications. See Install custom HDInsight applications.
Properties: View the cluster properties.
Storage accounts: View the Azure Storage account or Azure Data Lake Store accounts configured
during the cluster creation process.
Data lake store access: View the configured Azure Active Directory principal used to represent the
cluster when accessing Azure Data Lake Store.
New support request: Allows you to create a support ticket with Microsoft support.
6. Click Properties:
The properties are:
Hostname: Cluster name.
Cluster URL: The URL for the Ambari web interface.
Secure shell (SSH): The username and host name to use in accessing the cluster via SSH.
Status: Include Aborted, Accepted, ClusterStorageProvisioned, AzureVMConfiguration,
HDInsightConfiguration, Operational, Running, Error, Deleting, Deleted, Timedout, DeleteQueued,
DeleteTimedout, DeleteError, PatchQueued, CertRolloverQueued, ResizeQueued, ClusterCustomization
Region: Azure location. For a list of supported Azure locations, see the Region dropdown list box on
HDInsight pricing.
Date created: The date the cluster was deployed.
Operating system: Either Windows or Linux.
Type: Hadoop, HBase, Storm, Spark.
Version. See HDInsight versions
Subscription: Subscription name.
Default data source: The default cluster file system.
Worker nodes size: The selected VM size of the worker nodes.
Head node size: The selected VM size of the head nodes.
Virtual network: The name of the Virtual Network and subnet to which the cluster is deployed, if one
was selected at deployment time.
Delete clusters
Delete a cluster will not delete the default storage account or any linked storage accounts. You can re-create the
cluster by using the same storage accounts and the same metastores. It is recommended to use a new default Blob
container when you re-create the cluster.
1. Sign in to the Portal.
2. Click HDInsight Clusters from the left menu. If you don't see HDInsight Clusters, click More services first.
3. Click the cluster that you want to delete.
4. Click Delete from the top menu, and then follow the instructions.
See also Pause/shut down clusters.
Scale clusters
The cluster scaling feature allows you to change the number of worker nodes used by a cluster that is running in
Azure HDInsight without having to re-create the cluster.
NOTE
Only clusters with HDInsight version 3.1.3 or higher are supported. If you are unsure of the version of your cluster, you can
check the Properties page. See List and show clusters.
The impact of changing the number of data nodes for each type of cluster supported by HDInsight:
Hadoop
You can seamlessly increase the number of worker nodes in a Hadoop cluster that is running without
impacting any pending or running jobs. New jobs can also be submitted while the operation is in progress.
Failures in a scaling operation are gracefully handled so that the cluster is always left in a functional state.
When a Hadoop cluster is scaled down by reducing the number of data nodes, some of the services in the
cluster are restarted. This causes all running and pending jobs to fail at the completion of the scaling
operation. You can, however, resubmit the jobs once the operation is complete.
HBase
You can seamlessly add or remove nodes to your HBase cluster while it is running. Regional Servers are
automatically balanced within a few minutes of completing the scaling operation. However, you can also
manually balance the regional servers by logging into the headnode of cluster and running the following
commands from a command prompt window:
>pushd %HBASE_HOME%\bin
>hbase shell
>balancer
Here is an example how to use the CLI command to rebalance the Storm topology:
## Reconfigure the topology "mytopology" to use 5 worker processes,
## the spout "blue-spout" to use 3 executors, and
## the bolt "yellow-bolt" to use 10 executors
$ storm rebalance mytopology -n 5 -e blue-spout=3 -e yellow-bolt=10
To scale clusters
1. Sign in to the Portal.
2. Click HDInsight Clusters from the left menu.
3. Click the cluster you want to scale.
4. Click Scale Cluster.
5. Enter Number of Worker nodes. The limit on the number of cluster node varies among Azure
subscriptions. You can contact billing support to increase the limit. The cost information will reflect the
changes you have made to the number of nodes.
Change passwords
An HDInsight cluster can have two user accounts. The HDInsight cluster user account (A.K.A. HTTP user account)
and the SSH user account are created during the creation process. You can the Ambari web UI to change the cluster
user account username and password, and script actions to change the SSH user account
Change the cluster user password
You can use the Ambari Web UI to change the Cluster user password. To log into Ambari, you must use the existing
cluster username and password.
NOTE
If you change the cluster user (admin) password, this may cause script actions run against this cluster to fail. If you have any
persisted script actions that target worker nodes, these may fail when you add nodes to the cluster through resize
operations. For more information on script actions, see Customize HDInsight clusters using script actions.
1. Sign in to the Ambari Web UI using the HDInsight cluster user credentials. The default username is admin. The
URL is [Link] Cluster Name>[Link].
2. Click Admin from the top menu, and then click "Manage Ambari".
3. From the left menu, click Users.
4. Click Admin.
5. Click Change Password.
Ambari then changes the password on all nodes in the cluster.
Change the SSH user password
1. Using a text editor, save the following text as a file named [Link].
IMPORTANT
You must use an editor that uses LF as the line ending. If the editor uses CRLF, then the script will not work.
#! /bin/bash
USER=$1
PASS=$2
2. Upload the file to a storage location that can be accessed from HDInsight using an HTTP or HTTPS address. For
example, a public file store such as OneDrive or Azure Blob storage. Save the URI (HTTP or HTTPS address,) to
the file, as this is needed in the next step.
3. From the Azure portal, click HDInsight Clusters.
4. Click your HDInsight cluster.
5. Click Script Actions.
6. From the Script Actions blade, select Submit New. When the Submit script action blade appears, enter
the following information.
FIELD VALUE
Nodes (Head, Worker, Nimbus, Supervisor, Zookeeper, ✓ for all node types listed
etc.)
Parameters Enter the SSH user name and then the new password.
There should be one space between the user name and
the password.
7. Select Create to apply the script. Once the script finishes, you will be able to connect to the cluster using SSH
with the new password.
Grant/revoke access
HDInsight clusters have the following HTTP web services (all of these services have RESTful endpoints):
ODBC
JDBC
Ambari
Oozie
Templeton
By default, these services are granted for access. You can revoke/grant the access using Azure CLI and Azure
PowerShell.
Monitor jobs
See Manage HDInsight clusters by using the Ambari Web UI.
Browse files
Using the Azure portal, you can browse the content of the default container.
1. Sign in to [Link]
2. Click HDInsight Clusters from the left menu to list the existing clusters.
3. Click the cluster name. If the cluster list is long, you can use filter on the top of the page.
4. Click Storage Accounts from the cluster left menu.
5. click a storage account.
6. Click the Blobs tile.
7. Click the default container name.
IMPORTANT
To monitor the services provided by the HDInsight cluster, you must use Ambari Web or the Ambari REST API. For more
information on using Ambari, see Manage HDInsight clusters using Ambari
Connect to a cluster
Use Hive with HDInsight
Use SSH with HDInsight
Next steps
In this article, you have learned how to create an HDInsight cluster by using the Portal, and how to open the
Hadoop command-line tool. To learn more, see the following articles:
Administer HDInsight Using Azure PowerShell
Administer HDInsight Using Azure CLI
Create HDInsight clusters
Use Hive in HDInsight
Use Pig in HDInsight
Use Sqoop in HDInsight
Get Started with Azure HDInsight
What version of Hadoop is in Azure HDInsight?
Read more about using the Ambari Web UI
Details on using the Ambari REST API
Changing and Optimizing Configs via Ambari
8/16/2017 • 16 min to read • Edit Online
Overview
HDInsight allows for the creation of Apache Hadoop clusters for large-scale data processing applications.
Managing and monitoring multinode complex clusters is a tedious job. Apache Ambari is a web interface to easily
manage and monitor HDInsight Linux clusters. The Ambari web interface is only available with Linux clusters. For
Windows clusters, the Ambari REST API can be used.
In this article, you’ll learn how to use the Ambari web user interface to manage and optimize configurations of an
HDInsight Linux cluster.
For an introduction to using the Ambari Web UI, take a look at Manage HDInsight clusters by using the Ambari
Web UI
When you log in to its web interface (HTTPS://[Link]), Ambari displays a useful
dashboard that gives you a great overview of your cluster at-a-glance.
The Ambari web UI can be used to manage hosts, services, alerts, configurations, and views. It can’t be used to
create an HDInsight cluster, upgrade services, manage stacks and versions, decommission or recommission hosts,
or add services to the cluster.
1. Find the setting NameNode Java heap size. You can also use the filter text box to type and find a particular
setting. Click the pen icon beside the setting name.
1. Type the new value in the text box, and then press Enter to save the change.
1. Note that the NameNode Java heap size is changed to 2 GB from 1 GB.
Note: The NameNode Java heap size depends on many factors such as load on the cluster, number of files, and
number of blocks. The default size of 1 GB works well with most clusters, although certain workloads may
require modification.
1. Save your changes by clicking on the green Save button on the top of the configuration screen.
Hive optimization
As mentioned earlier, each service has certain configuration parameters that can be easily modified using the
Ambari web UI. In this section, we’ll learn about important configuration options to optimize overall Hive
performance.
1. To modify Hive configuration parameters, select Hive from the Services sidebar.
2. Navigate to the Configs tab.
Set the Hive execution engine
There are two execution engines: MapReduce and Tez. Tez is faster than MapReduce. HDInsight Linux clusters have
Tez as the default execution engine. To change the execution engine, follow these steps.
1. In the Hive Configs tab, type execution engine in the filter box.
Tune mappers
Hadoop tries to split a single file into multiple files and process the resulting files in parallel. The number of
mappers depends on the number of splits. The following two configuration parameters drive the number of splits
for the Tez execution engine:
[Link]-size : Lower limit on the size of a grouped split (default value of 16,777,216 bytes).
[Link]-size : Upper limit on the size of a grouped split (default value of 1,073,741,824 bytes).
As a performance rule of thumb, decrease both of these parameters to improve latency, increase for more
throughput.
For example, to set four mapper tasks for a data size of 128 MB, you would set both parameters to 32 MB each
(33,554,432 bytes).
1. Modify the above configuration parameters by navigating to the Configs tab of the Tez service. Expand the
General panel, and then locate the [Link]-size and [Link]-size parameters.
2. Set both parameters to 33,554,432 bytes (32 MB).
Note: The changes made here will affect all Tez jobs across the server. The parameter values should be
carefully modified in order to get the optimal result.
Tune reducers
ORC and Snappy both offer high performance. However, Hive may choose too few reducers by default, causing
bottlenecks.
For example, say you have an input data size of 50GB. That data in ORC format with Snappy compression is 1GB.
Hive estimates the number of reducers needed as:
(number of bytes input to mappers / [Link] )
With the default settings, this means 4 reducers in our scenario.
Thus, the [Link] parameter specifies the number of bytes processed per reducer.
The default value is 64 MB. Tuning this value down will increase parallelism and may improve performance.
Tuning it too low could also cause too many reducers, potentially adversely affecting performance. You will need
to adjust this setting based on your particular data requirements, compression settings, and other environmental
factors.
1. To modify the parameter, navigate to the Hive Configs tab and find the Data per Reducer parameter on the
Settings page.
1. Select Edit to modify the value to 128 MB (134217728 bytes), and then press Enter to save.
Given an input size of 1,024 MB, with 128 MB of data per reducer, there will be 1024/128, or 8 reducers.
1. An invalid or wrong value for the Data per Reducer parameter may result in a large number of reducers,
adversely affecting query performance. To limit the maximum number of reducers, set [Link]
to an appropriate value. The default value is 1009.
Enable parallel execution
A Hive query is executed in one or more stages. If the independent stages can be run in parallel, this will increase
query performance.
1. To enable parallel query execution, navigate to the Hive Config tab and search the [Link]
property. The default value is false. Change the value to true, and then press Enter to save the value.
2. To limit the number of jobs to be run in parallel, modify the [Link] property. The
default value is 8.
Enable vectorization
Hive processes data row by row. Vectorization enables Hive to process data in blocks of 1,024 rows instead of one
row at a time.
1. To enable a vectorized query execution, navigate to the Hive Configs tab and search for the
[Link] parameter. The default value is true for Hive 0.13.0 or later.
2. To enable vectorized execution for the reduce side of the query, set the
[Link] parameter to true. The default value is false.
The following additional configuration parameters increase Hive query performance when CBO is enabled:
[Link]
When set to true, Hive uses stats stored in metastore to answer simple queries like count(*) .
[Link]
Column statistics are created when CBO is enabled. Hive uses column statistics, which are stored in metastore, to
optimize queries. Fetching column statistics for each column takes longer when the number of columns is high.
When set to false, this setting disables fetching column statistics from the metastore.
[Link]
Basic partition statistics such as number of rows, data size, and file size are stored in metastore. When set to true,
the partition stats are fetched from metastore. When false, the file size is fetched from the file system, and the
number of rows is fetched from row schema.
As a general rule, having the compression method splittable is important, otherwise very few mappers will be
created. If the input data is text, bzip2 is the best option since it's splittable. For ORC format, Snappy is the fastest
compression option.
1. To enable intermediate compression, navigate to the Hive Configs tab, and then set the
[Link] parameter to true. The default value is false.
Note: To compress intermediate files, choose a compression codec with lower CPU cost, even if it doesn’t have
a high compression output.
1. To set the intermediate compression codec, add the custom property [Link]
to the [Link] or [Link] file.
2. To add a custom setting:
a. Navigate to the Hive Configs tab and select the Advanced tab.
b. Under the Advanced tab, find and expand the Custom hive-site pane.
c. Click the link Add Property at the bottom of the Custom hive-site pane.
d. In the Add Property window, enter [Link] as the key and
[Link] as the value.
e. Click Add.
This will compress the intermediate file using Snappy compression. Once the property is added, it will appear in
the Custom hive-site pane.
2. To choose the output compression codec, add the [Link] custom property to the
Custom hive-site pane, as explained above.
Note: Speculative execution shouldn’t be turned on for long-running MapReduce tasks with large amounts of
input.
Shuffle Join Default choice Reads from No significant Hive Works every time
Always works part of one of setting needed
the tables
Buckets and
sorts on Join
key
Sends one
bucket to each
reduce
Join is done
on the Reduce
side
Map Join One table can Reads small Very fast, but limited
[Link]=true
fit in memory table into
memory hash
table
Streams
through part
of the big file
Joins each
record from
hash table
Joins will be
performed by
the mapper
alone
Sort Merge Bucket If both tables are: Each process: Very efficient
[Link]=true
Sorted the Reads a
same bucket from
Bucketed the each table
same Processes the
Joining on the row with the
sorted/bucket lowest value
ed column
Pig optimization
Pig properties can be easily modified from the Ambari web UI to tune Pig queries. Modifying Pig properties from
Ambari directly modifies the Pig properties in the /etc/pig/[Link]-258.0/[Link] file.
1. To modify Pig properties, navigate to the Pig Configs tab, and then expand the Advanced pig-properties
pane.
2. Find, uncomment, and change the value of the property you wish to modify.
3. Select Save on the top right side of the window to save the new value. Some properties may require a
service restart.
Note: The session-level settings override property values in the [Link] file.
Note: The recommended compression codecs are LZO and Snappy because of lower CPU utilization.
Note: Do not set the values such that the time between invocation of the next method on a scanner is greater
than the scanner timeout. The scanner timeout is defined by the [Link] property.
The larger the region file size, the fewer number of splits. Ideally, you can increase the value and settle for the one
that gets you the maximum write performance.
Avoid update blocking
The property [Link] defines the size at which Memstore will be flushed to disk. The
default size is 128 MB.
The Hbase region block multiplier is defined by [Link] . The default value is 4.
The maximum allowed is 8.
HBase blocks update if the Memstore is ( [Link] *
[Link] ) bytes.
Considering the default values, updates are blocked when Memstore is of 128 * 4 = 512 MB in size. To reduce the
update blocking count, increase the value of [Link] .
This article provides guidance on management of the myriad log files that a HDInsight cluster produces. Apache
Hadoop and related services, such as Apache Spark, produce detailed job execution logs. Properly managing these
log files is an important aspect of maintaining a healthy HDInsight cluster. The management of these files can also
be dictated by regulatory requirements. Also, due to number and size of logs, you want to optimize log storage and
archival for service cost management.
There are a set of general steps to take when managing HDInsight cluster logs. They include retaining information
about all aspects of the environment. This includes, but is not limited to, all associated Azure Services, cluster
configuration, job execution information and any error states. The most common steps taken in this process are
listed below.
Managing HDInsight Cluster Log Steps
Step 1: Determine log retention policies
Step 2: Manage cluster service versions configuration logs
Step 3: Manage cluster Job Execution Log Files
Step 4: Forcast log volume storage sizes and costs
Step 5: Determine log archive policies and processes
Or, you can use powershell to view this type of information. See Manage Hadoop clusters in HDInsight by using
Azure PowerShell for details.
Understand the Workloads running on your clusters
It's important to understand workload types running on your HDInsight cluster(s) so that you can design
appropriate associated logging strategies for each type of workload.
Listed below are some of the questions you can use to capture the needed information for planning.
Are the workloads experimental (i.e. dev or test) or production-quality?
How often do the production-quality workloads normally run?
Are any of the workloads resource-intensive and/or particularly long-running?
Do any of the workloads utilize a complex set of Hadoop services for which multiple types of logs would be
produced?
Do any of the workloads have associated regulatory execution lineage requirements?
Your expected output after you complete the information-gathering in this step is a written list of cluster(s)
information, workload types and log retention requirements.
Example log retention patterns and practices
Consider maintaining data lineage tracking by adding an identifier to each log entry, or through other
techniques. This allows you to trace back the original source of the data and the operation, and follow it through
each stage to understand its consistency and validity.
Consider how you can collect logs from the cluster, or from more than one cluster, and collate them for
purposes such as auditing, monitoring, planning, and alerting. You might use a custom solution to access and
download the log files on a regular basis, and combine and analyze them to provide a dashboard-like display
with additional capabilities for alerting for security or failure detection. Such utilities could be created using
PowerShell, the HDInsight SDKs, or code that accesses the Azure Service Management API.
Consider if a monitoring solution or service would be a useful benefit. A management pack for HDInsight is
available for use with Microsoft System Center (see the Microsoft Download Center for more details). In
addition, you can use third-party tools such as Chukwa and Ganglia to collect and centralize logs. Many
companies offer services to monitor Hadoop-based big data solutions—some examples are Centerity,
Compuware APM, Sematext SPM, and Zettaset Orchestrator.
Step 2: Manage cluster service versions and view Script Action logs
A typical HDInsight cluster uses a number of services and open-source software packages (such as Apache HBase,
Apache Spark, etc...). For some workloads, such as bioinformatics, you may be required to retain service
configuration log history in addition to job execution logs.
Viewing Cluster Configuration Settings with the Ambari UI
Apache Ambari simplifies the management and monitoring of a HDInsight cluster by providing an easy to use web
UI and REST API. Ambari is included on Linux-based HDInsight clusters, and is used to monitor the cluster and
make configuration changes. Click on the 'Cluster Dashboard' blade on the Azure Portal HDInsight page to open
the 'Cluster Dashboards' link page. Next, click on the 'HDInsight cluster dashboard' blade to open the Ambari UI.
You'll be prompted for your cluster login credentials.
Also, you can click the blade named 'Ambari Views' on the Azure portal page for HDInsight to open a list of service
views. This list will vary, depending on which libraries you've installed. For example, you may see YARN Queue
Manager, Hive View and Tez View, if you've installed these services. Click any service link of interest to drill down to
see configuration and service information. The Ambari UI 'Stack and Version' page provides information about the
cluster services configuration and service version history. In the Ambari UI, click on the 'Admin' menu and then on
'Stacks and Versions' to navigate to this section. Then click on the 'Versions' tab on the page to see service version
information. An example is shown below.
Additionally, using the Ambari UI, you can capture (by downloading) the configuration for any (or all) services
running on a particular host (or node) in the cluster.
Do this by clicking on the 'Hosts' menu, then on link for the host of interest and then in that host's page, on the
'Host Actions' button and then on 'Download Client Configs'. An example screenshot is shown below.
/app-logs/<user>/logs/<applicationId>
The aggregated logs are not directly readable, as they are written in a TFile, binary format indexed by container. Use
the YARN ResourceManager logs or CLI tools to view these logs as plain text for applications or containers of
interest.
YA RN CLI tools
To use the YARN CLI tools, you must first connect to the HDInsight cluster using SSH. Specify the <applicationId> ,
<user-who-started-the-application> , <containerId> , and <worker-node-address> information when running these
commands. You can view these logs as plain text by running one of the following commands:
Y A R N R e so u r c e M a n a g e r U I
The YARN ResourceManager UI runs on the cluster headnode. It is accessed through the Ambari web UI. Use the
following steps to view the YARN logs:
1. In your web browser, navigate to [Link] Replace CLUSTERNAME with the
name of your HDInsight cluster.
2. From the list of services on the left, select YARN. Yarn service selected
3. From the Quick Links dropdown, select one of the cluster head nodes and then select ResourceManager logs.
You are presented with a list of links to YARN logs.
Alternatively, you can script log archiving by using powershell. A Sample powershell script to Archive Azure
Automation logs to Azure BLOB Storage can be found at the link referenced.
Accessing Azure storage metrics
Azure storage can be configured to log storage operations and access. You can use these logs, which contain a
wealth of information, for capacity monitoring and planning, and for auditing requests to storage. The information
includes latency details, enabling you to monitor and fine tune performance of your solutions. You can use the .NET
SDK for Hadoop to examine the log files generated for the Azure storage that holds the data for an HDInsight
cluster.
Control the Size and Number of backup index of old log files
Do this by using the following properties of the RollingFileAppender to efficiently control the Size and the number
of log files retained.
maxFileSize:This is the critical size of the file above which the file will be rolled. Default value is 10
MB.
maxBackupIndex: This property denotes the number of backup files to be created. Default value is 1.
Conclusion
There are a number of considerations you need to take into account when creating and implementing your
HDInsight cluster log management policies. You should focus on using the best HDInsight log policy for each of
your particular workload types running your cluster. Along with that, you'll need to monitor the size of key log files
for the execution of long-running job executions to make sure that they don't exceed the expected size. This is not
only so that you have predictable costs, but also for performance and service availability. It's also critically
important to manage your cluster configuration files over time as part of your log management strategy, so that
you can revert to working state should the need arise.
See also
Monitoring and Logging Practice for HDInsight
Access YARN application log on Linux-based HDInsight
How to control size of log files for various Hadoop components
Add additional storage accounts to HDInsight
8/16/2017 • 5 min to read • Edit Online
Learn how to use script actions to add additional Azure storage accounts to HDInsight. The steps in this document
add a storage account to an existing Linux-based HDInsight cluster.
IMPORTANT
The information in this document is about adding additional storage to a cluster after it has been created. For information on
adding storage accounts during cluster creation, see Set up clusters in HDInsight with Hadoop, Spark, Kafka, and more.
How it works
This script takes the following parameters:
Azure storage account name: The name of the storage account to add to the HDInsight cluster. After
running the script, HDInsight can read and write data stored in this storage account.
Azure storage account key: A key that grants access to the storage account.
-p (optional): If specified, the key is not encrypted and is stored in the [Link] file as plain text.
During processing, the script performs the following actions:
If the storage account already exists in the [Link] configuration for the cluster, the script exits and no
further actions are performed.
Verifies that the storage account exists and can be accessed using the key.
Encrypts the key using the cluster credential.
Adds the storage account to the [Link] file.
Stops and restarts the Oozie, YARN, MapReduce2, and HDFS services. Stopping and starting these services
allows them to use the new storage account.
WARNING
Using a storage account in a different location than the HDInsight cluster is not supported.
The script
Script location: [Link]
[Link]
Requirements:
The script must be applied on the Head nodes.
Known issues
Storage accounts not displayed in Azure portal or tools
When viewing the HDInsight cluster in the Azure portal, selecting the Storage Accounts entry under Properties
does not display storage accounts added through this script action. Azure PowerShell and Azure CLI do not display
the additional storage account either.
The storage information isn't displayed because the script only modifies the [Link] configuration for the
cluster. This information is not used when retrieving the cluster information using Azure management APIs.
To view storage account information added to the cluster using this script, use the Ambari REST API. Use the
following commands to retrieve this information for your cluster:
$creds = Get-Credential -UserName "admin" -Message "Enter the cluster login credentials"
$resp = Invoke-WebRequest -Uri
"[Link]
service_name=HDFS&service_config_version=1" `
-Credential $creds
$respObj = ConvertFrom-Json $[Link]
$[Link]."[Link].$[Link]"
NOTE
Set $clusterName to the name of the HDInsight cluster. Set $storageAccountName to the name of the storage account.
When prompted, enter the cluster login (admin) and password.
curl -u admin:PASSWORD -G
"[Link]
service_name=HDFS&service_config_version=1" | jq
'.items[].configurations[].properties["[Link].$[Link]"] |
select(. != null)'
NOTE
Set $PASSWORD to the cluster login (admin) account password. Set $CLUSTERNAME to the name of the HDInsight cluster. Set
$STORAGEACCOUNTNAME to the name of the storage account.
This example uses curl ([Link] and jq ([Link] to retrieve and parse JSON data.
When using this command, replace CLUSTERNAME with the name of the HDInsight cluster. Replace PASSWORD
with the HTTP login password for the cluster. Replace STORAGEACCOUNT with the name of the storage account
added using script action. Information returned from this command appears similar to the following text:
"MIIB+gYJKoZIhvcNAQcDoIIB6zCCAecCAQAxggFaMIIBVgIBADA+MCoxKDAmBgNVBAMTH2RiZW5jcnlwdGlvbi5henVyZWhkaW5zaWdodC5uZ
XQCEA6GDZMW1oiESKFHFOOEgjcwDQYJKoZIhvcNAQEBBQAEggEATIuO8MJ45KEQAYBQld7WaRkJOWqaCLwFub9zNpscrquA2f3o0emy9Vr6vu5
cD3GTt7PmaAF0pvssbKVMf/Z8yRpHmeezSco2y7e9Qd7xJKRLYtRHm80fsjiBHSW9CYkQwxHaOqdR7DBhZyhnj+DHhODsIO2FGM8MxWk4fgBRV
O6CZ5eTmZ6KVR8wYbFLi8YZXb7GkUEeSn2PsjrKGiQjtpXw1RAyanCagr5vlg8CicZg1HuhCHWf/RYFWM3EBbVz+uFZPR3BqTgbvBhWYXRJaIS
wssvxotppe0ikevnEgaBYrflB2P+PVrwPTZ7f36HQcn4ifY1WRJQ4qRaUxdYEfzCBgwYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAhRdscgRV3wm
YBg3j/T1aEnO3wLWCRpgZa16MWqmfQPuansKHjLwbZjTpeirqUAQpZVyXdK/w4gKlK+t1heNsNo1Wwqu+Y47bSAX1k9Ud7+Ed2oETDI7724IJ2
13YeGxvu4Ngcf2eHW+FRK"
This text is an example of an encrypted key, which is used to access the storage account.
Unable to access storage after changing key
If you change the key for a storage account, HDInsight can no longer access the storage account. HDInsight uses a
cached copy of key in the [Link] for the cluster. This cached copy must be updated to match the new key.
Running the script action again does not update the key, as the script checks to see if an entry for the storage
account already exists. If an entry already exists, it does not make any changes.
To work around this problem, you must remove the existing entry for the storage account. Use the following steps
to remove the existing entry:
1. In a web browser, open the Ambari Web UI for your HDInsight cluster. The URI is
[Link] Replace CLUSTERNAME with the name of your cluster.
When prompted, enter the HTTP login user and password for your cluster.
2. From the list of services on the left of the page, select HDFS. Then select the Configs tab in the center of the
page.
3. In the Filter... field, enter a value of [Link]. This returns entries for any additional storage
accounts that have been added to the cluster. There are two types of entries; keyprovider and key. Both
contain the name of the storage account as part of the key name.
The following are example entries for a storage account named mystorage:
[Link]
[Link]
4. After you have identified the keys for the storage account you need to remove, use the red '-' icon to the
right of the entry to delete it. Then use the Save button to save your changes.
5. After changes have been saved, use the script action to add the storage account and new key value to the
cluster.
Poor performance
If the storage account is in a different region than the HDInsight cluster, you may experience poor performance.
Accessing data in a different region sends network traffic outside the regional Azure data center and across the
public internet, which can introduce latency.
WARNING
Using a storage account in a different region than the HDInsight cluster is not supported.
Additional charges
If the storage account is in a different region than the HDInsight cluster, you may notice additional egress charges
on your Azure billing. An egress charge is applied when data leaves a regional data center. This charge is applied
even if the traffic is destined for another Azure data center in a different region.
WARNING
Using a storage account in a different region than the HDInsight cluster is not supported.
Next steps
You have learned how to add additional storage accounts to an existing HDInsight cluster. For more information
on script actions, see Customize Linux-based HDInsight clusters using script action
Customize Linux-based HDInsight clusters using
Script Action
8/16/2017 • 25 min to read • Edit Online
HDInsight provides a configuration option called Script Action that invokes custom scripts that customize the
cluster. These scripts are used to install additional components and change configuration settings. Script actions
can be used during or after cluster creation.
IMPORTANT
The ability to use script actions on an already running cluster is only available for Linux-based HDInsight clusters.
Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight
retirement on Windows.
Script actions can also be published to the Azure Marketplace as an HDInsight application. Some of the
examples in this document show how you can install an HDInsight application using script action commands
from PowerShell and the .NET SDK. For more information on HDInsight applications, see Publish HDInsight
applications into the Azure Marketplace.
Permissions
If you are using a domain-joined HDInsight cluster, there are two Ambari permissions that are required when
using script actions with the cluster:
AMBARI.RUN_CUSTOM_COMMAND: The Ambari Administrator role has this permission by default.
CLUSTER.RUN_CUSTOM_COMMAND: Both the HDInsight Cluster Administrator and Ambari Administrator
have this permission by default.
For more information on working with permissions with domain-joined HDInsight, see Manage domain-joined
HDInsight clusters.
Access control
If you are not the administrator/owner of your Azure subscription, your account must have at least Contributor
access to the resource group that contains the HDInsight cluster.
Additionally, if you are creating an HDInsight cluster, someone with at least Contributor access to the Azure
subscription must have previously registered the provider for HDInsight. Provider registration happens when a
user with Contributor access to the subscription creates a resource for the first time on the subscription. It can
also be accomplished without creating a resource by registering a provider using REST.
For more information on working with access management, see the following documents:
Get started with access management in the Azure portal
Use role assignments to manage access to your Azure subscription resources
NOTE
The service principal HDInsight uses to access Data Lake Store must have read access to the script.
A blob in an Azure Storage account that is either the primary or additional storage account for
the HDInsight cluster. HDInsight is granted access to both of these types of storage accounts
during cluster creation.
A public file sharing service such as Azure Blob, GitHub, OneDrive, Dropbox, etc.
For example URIs, see the Example script action scripts section.
WARNING
HDInsight only supports General purpose Azure Storage accounts. It does not currently support the
Blob storage account type.
Can be restricted to run on only certain node types, for example head nodes or worker nodes.
NOTE
When used with HDInsight Premium, you can specify that the script should be used on the edge node.
IMPORTANT
Persisted script actions must have a unique name.
Ad hoc scripts are not persisted. They are not applied to worker nodes added to the cluster after the
script has ran. You can subsequently promote an ad hoc script to a persisted script, or demote a persisted
script to an ad hoc script.
IMPORTANT
Script actions used during cluster creation are automatically persisted.
Scripts that fail are not persisted, even if you specifically indicate that they should be.
Can accept parameters that are used by the script during execution.
Run with root level privileges on the cluster nodes.
Can be used through the Azure portal, Azure PowerShell, Azure CLI, or HDInsight .NET SDK
The cluster keeps a history of all scripts that have been ran. The history is useful when you need to find the ID of
a script for promotion or demotion operations.
IMPORTANT
There is no automatic way to undo the changes made by a script action. Either manually reverse the changes or provide a
script that reverses them.
The script runs while HDInsight is being configured. At this stage, the script runs in parallel on all the specified
nodes in the cluster, and runs with root privileges on the nodes.
NOTE
Because the script runs with root level privilege on the cluster nodes, you can perform operations like stopping and
starting services, including Hadoop-related services. If you stop services, you must ensure that the Ambari service and
other Hadoop-related services are up and running before the script finishes running. These services are required to
successfully determine the health and state of the cluster while it is being created.
During cluster creation, you can use multiple script actions at once. These scripts are invoked in the order in
which they were specified.
IMPORTANT
Script actions must complete within 60 minutes, or timeout. During cluster provisioning, the script runs concurrently with
other setup and configuration processes. Competition for resources such as CPU time or network bandwidth may cause
the script to take longer to finish than it does in your development environment.
To minimize the time it takes to run the script, avoid tasks such as downloading and compiling applications from source.
Pre-compile applications and store the binary in Azure Storage. This allows the script to quickly download the application
to the cluster.
IMPORTANT
This does not mean that your running cluster is immune to scripts that do bad things. For example, a script could delete
files needed by the cluster.
Scripts actions run with root privileges, so you should make sure that you understand what a script does before applying
it to your cluster.
When applying a script to a cluster, the cluster state changes to from Running to Accepted, then HDInsight
configuration, and finally back to Running for successful scripts. The script status is logged in the script action
history, and you can use this information to determine whether the script succeeded or failed. For example, the
Get-AzureRmHDInsightScriptActionHistory PowerShell cmdlet can be used to view the status of a script. It returns
information similar to the following text:
ScriptExecutionId : 635918532516474303
StartTime : 2/23/2016 7:40:55 PM
EndTime : 2/23/2016 7:41:05 PM
Status : Succeeded
NOTE
If you have changed the cluster user (admin) password after the cluster was created, script actions ran against this cluster
may fail. If you have any persisted script actions that target worker nodes, these scripts may fail when you scale the
cluster.
3. From the Advanced settings blade, select Script actions. From the Script actions blade, select +
Submit new
4. Use the Select a script entry to select a pre-made script. To use a custom script, select Custom and then
provide the Name and Bash script URI for your script.
PROPERTY VALUE
Bash script URI Specify the URI to the script that is invoked to customize
the cluster.
PROPERTY VALUE
Use the Persist this script action entry to ensure that the script is applied to worker nodes when you
scale your cluster.
5. Select Create to save the script. You can then use + Submit new to add another script.
When you are done adding scripts, use the Select button, and then the Next button to return to the
Cluster summary blade.
6. To create the cluster, select Create from the Cluster summary blade.
Use a Script Action from Azure Resource Manager templates
The examples in this section demonstrate how to use script actions with Azure Resource Manager templates
when creating an HDInsight cluster.
Before you begin
For information about configuring a workstation to run HDInsight Powershell cmdlets, see Install and
configure Azure PowerShell
For instructions on how to create templates, see Authoring Azure Resource Manager templates.
If you have not previously used Azure PowerShell with Resource Manager, see Using Azure PowerShell with
Azure Resource Manager.
Create clusters using Script Action
1. Copy the following template to a location on your computer. This template installs Giraph on the
headnodes and worker nodes in the cluster. You can also verify if the JSON template is valid. Paste your
template content into JSONLint, an online JSON validation tool.
{
"$schema": "[Link]
"contentVersion": "[Link]",
"parameters": {
"clusterLocation": {
"type": "string",
"defaultValue": "West US",
"allowedValues": [ "West US" ]
},
"clusterName": {
"type": "string"
},
"clusterUserName": {
"type": "string",
"defaultValue": "admin"
},
"clusterUserPassword": {
"type": "securestring"
},
"sshUserName": {
"type": "string",
"defaultValue": "username"
},
"sshPassword": {
"type": "securestring"
},
"clusterStorageAccountName": {
"type": "string"
},
"clusterStorageAccountResourceGroup": {
"type": "string"
},
"clusterStorageType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS"
]
},
"clusterStorageAccountContainer": {
"type": "string"
},
"clusterHeadNodeCount": {
"type": "int",
"defaultValue": 1
},
"clusterWorkerNodeCount": {
"type": "int",
"defaultValue": 2
}
},
"variables": {
},
"resources": [
{
"name": "[parameters('clusterStorageAccountName')]",
"type": "[Link]/storageAccounts",
"location": "[parameters('clusterLocation')]",
"apiVersion": "2015-05-01-preview",
"dependsOn": [ ],
"tags": { },
"properties": {
"accountType": "[parameters('clusterStorageType')]"
}
},
{
"name": "[parameters('clusterName')]",
"type": "[Link]/clusters",
"location": "[parameters('clusterLocation')]",
"apiVersion": "2015-03-01-preview",
"dependsOn": [
"[concat('[Link]/storageAccounts/',
parameters('clusterStorageAccountName'))]"
],
"tags": { },
"properties": {
"clusterVersion": "3.2",
"osType": "Linux",
"clusterDefinition": {
"kind": "hadoop",
"configurations": {
"gateway": {
"[Link]": true,
"[Link]": "[parameters('clusterUserName')]",
"[Link]": "[parameters('clusterUserPassword')]"
}
}
},
"storageProfile": {
"storageaccounts": [
{
"name": "
[concat(parameters('clusterStorageAccountName'),'.[Link]')]",
"isDefault": true,
"container": "[parameters('clusterStorageAccountContainer')]",
"key": "[listKeys(resourceId('[Link]/storageAccounts',
parameters('clusterStorageAccountName')), '2015-05-01-preview').key1]"
}
]
},
"computeProfile": {
"roles": [
{
"name": "headnode",
"targetInstanceCount": "[parameters('clusterHeadNodeCount')]",
"hardwareProfile": {
"vmSize": "Large"
},
"osProfile": {
"linuxOperatingSystemProfile": {
"username": "[parameters('sshUserName')]",
"password": "[parameters('sshPassword')]"
}
},
"scriptActions": [
{
"name": "installGiraph",
"uri":
"[Link]
"parameters": ""
}
]
},
{
"name": "workernode",
"targetInstanceCount": "[parameters('clusterWorkerNodeCount')]",
"hardwareProfile": {
"vmSize": "Large"
},
"osProfile": {
"linuxOperatingSystemProfile": {
"username": "[parameters('sshUserName')]",
"password": "[parameters('sshPassword')]"
}
},
"scriptActions": [
{
"name": "installR",
"uri":
"[Link]
"parameters": ""
}
]
}
}
]
}
}
}
],
"outputs": {
"cluster":{
"type" : "object",
"value" : "
[reference(resourceId('[Link]/clusters',parameters('clusterName')))]"
}
}
}
2. Start Azure PowerShell and Log in to your Azure account. After providing your credentials, the command
returns information about your account.
Add-AzureRmAccount
Id Type ...
-- ----
someone@[Link] User ...
3. If you have multiple subscriptions, provide the subscription id you wish to use for deployment.
NOTE
You can use Get-AzureRmSubscription to get a list of all subscriptions associated with your account, which
includes the subscription Id for each one.
4. If you do not have an existing resource group, create a resource group. Provide the name of the resource
group and location that you need for your solution. A summary of the new resource group is returned.
ResourceGroupName : myresourcegroup
Location : westus
ProvisioningState : Succeeded
Tags :
Permissions :
Actions NotActions
======= ==========
*
ResourceId : /subscriptions/######/resourceGroups/ExampleResourceGroup
DeploymentName : mydeployment
ResourceGroupName : myresourcegroup
ProvisioningState : Succeeded
Timestamp : 8/17/2015 7:00:27 PM
Mode : Incremental
...
7. If your deployment fails, you can use the following cmdlets to get information about the failures.
# Create a blob container. This holds the default data store for the cluster.
New-AzureStorageContainer `
-Name $clusterName -Context $defaultStorageContext
3. From the top of the Script Actions blade, select Submit new.
4. Use the Select a script entry to select a pre-made script. To use a custom script, select Custom and then
provide the Name and Bash script URI for your script.
The following table describes the elements on the form:
PROPERTY VALUE
Bash script URI Specify the URI to the script that is invoked to customize
the cluster.
Use the Persist this script action entry to ensure that the script is applied to worker nodes when you
scale your cluster.
5. Finally, use the Create button to apply the script to the cluster.
Apply a Script Action to a running cluster from Azure PowerShell
Before proceeding, make sure you have installed and configured Azure PowerShell. For information about
configuring a workstation to run HDInsight PowerShell cmdlets, see Install and configure Azure PowerShell.
The following example demonstrates how to apply a script action to a running cluster:
# Get information for the HDInsight cluster
$clusterName = Read-Host -Prompt "Enter the name of the HDInsight cluster"
$scriptActionName = Read-Host -Prompt "Enter the name of the script action"
$scriptActionUri = Read-Host -Prompt "Enter the URI of the script action"
# The node types that the script action is applied to
$nodeTypes = "headnode", "workernode"
Once the operation completes, you receive information similar to the following:
OperationState : Succeeded
ErrorMessage :
Name : Giraph
Uri : [Link]
[Link]
Parameters :
NodeTypes : {HeadNode, WorkerNode}
azure login
If you omit parameters for this command, you are prompted for them. If the script you specify with -u
accepts parameters, you can specify them using the -p parameter.
Valid node types are headnode , workernode , and zookeeper . If the script should be applied to multiple
node types, specify the types separated by a ';'. For example, -n headnode;workernode .
To persist the script, add the --persistOnSuccess . You can also persist the script later by using
azure hdinsight script-action persisted set .
Once the job completes, you receive output similar to the following text:
NOTE
You can also select All settings and then select Script Actions from the Settings blade.
3. A history of scripts for this cluster is displayed on the Script Actions blade. This information includes a list
of persisted scripts. In the screenshot below, you can see that the Solr script has been ran on this cluster.
The screenshot does not show any persisted scripts.
4. Selecting a script from the history displays the Properties blade for this script. From the top of the blade,
you can rerun the script or promote it.
5. You can also use the ... to the right of entries on the Script Actions blade to perform actions.
IMPORTANT
Using Remove-AzureRmHDInsightPersistedScriptAction does not undo the actions performed by a script. This cmdlet
only removes the persisted flag.
The following example script demonstrates using the cmdlets to promote, then demote a script.
azure hdinsight script-action persisted list Retrieve a list of persisted script actions
<clustername>
azure hdinsight script-action persisted show Retrieve information on a specific persisted script action
<clustername> <scriptname>
azure hdinsight script-action history list Retrieve a history of script actions applied to the cluster
<clustername>
azure hdinsight script-action history show Retrieve information on a specific script action
<clustername> <scriptname>
azure hdinsight script action persisted set Promotes an ad hoc script action to a persisted script action
<clustername> <scriptexecutionid>
USE THE FOLLOWING... TO ...
azure hdinsight script-action persisted delete Demotes a persisted script action to an ad hoc action
<clustername> <scriptname>
IMPORTANT
Using azure hdinsight script-action persisted delete does not undo the actions performed by a script. This
cmdlet only removes the persisted flag.
NOTE
This example also demonstrates how to install an HDInsight application using the .NET SDK.
WARNING
Components provided with the HDInsight cluster are fully supported. Microsoft Support helps to isolate and resolve
issues related to these components.
Custom components receive commercially reasonable support to help you to further troubleshoot the issue. This might
result in resolving the issue OR asking you to engage available channels for the open source technologies where deep
expertise for that technology is found. For example, there are many community sites that can be used, like: MSDN forum
for HDInsight, [Link] Also Apache projects have project sites on [Link] for example:
Hadoop.
The HDInsight service provides several ways to use custom components. The same level of support applies,
regardless of how a component is used or installed on the cluster. The following list describes the most
common ways that custom components can be used on HDInsight clusters:
1. Job submission - Hadoop or other types of jobs that execute or use custom components can be
submitted to the cluster.
2. Cluster customization - During cluster creation, you can specify additional settings and custom
components that are installed on the cluster nodes.
3. Samples - For popular custom components, Microsoft and others may provide samples of how these
components can be used on the HDInsight clusters. These samples are provided without support.
Troubleshooting
You can use Ambari web UI to view information logged by script actions. If the script fails during cluster
creation, the logs are also available in the default storage account associated with the cluster. This section
provides information on how to retrieve the logs using both these options.
Using the Ambari Web UI
1. In your browser, navigate to [Link] Replace CLUSTERNAME with the
name of your HDInsight cluster.
When prompted, enter the admin account name (admin) and password for the cluster. You may have to
reenter the admin credentials in a web form.
2. From the bar at the top of the page, select the ops entry. A list of current and previous operations
performed on the cluster through Ambari is displayed.
3. Find the entries that have run_customscriptaction in the Operations column. These entries are created
when the Script Actions run.
To view the STDOUT and STDERR output, select the run\customscriptaction entry and drill down through
the links. This output is generated when the script runs, and may contain useful information.
Access logs from the default storage account
If the cluster creation fails due to a script action error, the logs can be accessed from the default storage account.
The storage logs are available at
\STORAGE_ACCOUNT_NAME\DEFAULT_CONTAINER_NAME\custom-scriptaction-logs\CLUSTER_NAME\DATE .
Under this directory, the logs are organized separately for headnode, workernode, and zookeeper nodes.
Some examples are:
Headnode - <uniqueidentifier>AmbariDb-hn0-<generated_value>.[Link]
All stdout and stderr of the corresponding host is uploaded to the storage account. There is one output-
*.txt and errors-*.txt for each script action. The output-*.txt file contains information about the URI of
the script that got run on the host. For example
It's possible that you repeatedly create a script action cluster with the same name. In such case, you can
distinguish the relevant logs based on the DATE folder name. For example, the folder structure for a
cluster (mycluster) created on different dates appears similar to the following log entries:
\STORAGE_ACCOUNT_NAME\DEFAULT_CONTAINER_NAME\custom-scriptaction-logs\mycluster\2015-10-04
\STORAGE_ACCOUNT_NAME\DEFAULT_CONTAINER_NAME\custom-scriptaction-logs\mycluster\2015-10-05
If you create a script action cluster with the same name on the same day, you can use the unique prefix to
identify the relevant log files.
If you create a cluster at the end of the day, it's possible that the log files span across two days. In such
cases, you see two different date folders for the same cluster.
Uploading log files to the default container can take up to 5 mins, especially for large clusters. So, if you
want to access the logs, you should not immediately delete the cluster if a script action fails.
Ambari watchdog
WARNING
Do not change the password for the Ambari Watchdog (hdinsightwatchdog) on your Linux-based HDInsight cluster.
Changing the password for this account breaks the ability to run new script actions on the HDInsight cluster.
Cause: This error occurs if you upgrade the Python Azure Storage client that is included with the HDInsight
cluster. HDInsight expects Azure Storage client 0.20.0.
Resolution: To resolve this error, manually connect to each cluster node using ssh and use the following
command to reinstall the correct storage client version:
Next steps
Develop Script Action scripts for HDInsight
Install and use Solr on HDInsight clusters
Install and use Giraph on HDInsight clusters
Add additional storage to an HDInsight cluster
Script action development with HDInsight
8/16/2017 • 13 min to read • Edit Online
Learn how to customize your HDInsight cluster using Bash scripts. Script actions are a way to customize HDInsight
during or after cluster creation.
IMPORTANT
The steps in this document require an HDInsight cluster that uses Linux. Linux is the only operating system used on
HDInsight version 3.4 or greater. For more information, see HDInsight retirement on Windows.
USE THIS METHOD TO APPLY A SCRIPT... DURING CLUSTER CREATION... ON A RUNNING CLUSTER...
Azure portal ✓ ✓
Azure PowerShell ✓ ✓
Azure CLI ✓
For more information on using these methods to apply script actions, see Customize HDInsight clusters using
script actions.
OS_VERSION=$(lsb_release -sr)
if [[ $OS_VERSION == 14* ]]; then
echo "OS verion is $OS_VERSION. Using hue-binaries-14-04."
HUE_TARFILE=[Link]
elif [[ $OS_VERSION == 16* ]]; then
echo "OS verion is $OS_VERSION. Using hue-binaries-16-04."
HUE_TARFILE=[Link]
fi
...
if [[ $OS_VERSION == 16* ]]; then
echo "Using systemd configuration"
systemctl daemon-reload
systemctl stop [Link]
systemctl start [Link]
else
echo "Using upstart configuration"
initctl reload-configuration
stop webwasb
start webwasb
fi
...
if [[ $OS_VERSION == 14* ]]; then
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
elif [[ $OS_VERSION == 16* ]]; then
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
fi
You can find the full script that contains these snippets at
[Link]
For the version of Ubuntu that is used by HDInsight, see the HDInsight component version document.
To understand the differences between Systemd and Upstart, see Systemd for Upstart users.
Provide stable links to script resources
The script and associated resources must remain available throughout the lifetime of the cluster. These resources
are required if new nodes are added to the cluster during scaling operations.
The best practice is to download and archive everything in an Azure Storage account on your subscription.
IMPORTANT
The storage account used must be the default storage account for the cluster or a public, read-only container on any other
storage account.
For example, the samples provided by Microsoft are stored in the [Link]
storage account. This is a public, read-only container maintained by the HDInsight team.
Use pre -compiled resources
To reduce the time it takes to run the script, avoid operations that compile resources from source code. For
example, pre-compile resources and store them in an Azure Storage account blob in the same data center as
HDInsight.
Ensure that the cluster customization script is idempotent
Scripts must be idempotent. If the script runs multiple times, it should return the cluster to the same state every
time.
For example, a script that modifies configuration files should not add duplicate entries if ran multiple times.
Ensure high availability of the cluster architecture
Linux-based HDInsight clusters provide two head nodes that are active within the cluster, and script actions run on
both nodes. If the components you install expect only one head node, do not install the components on both head
nodes.
IMPORTANT
Services provided as part of HDInsight are designed to fail over between the two head nodes as needed. This functionality is
not extended to custom components installed through script actions. If you need high availability for custom components,
you must implement your own failover mechanism.
In this example, the hdfs command transparently uses the default cluster storage. For some operations, you may
need to specify the URI. For example, adl:///example/jars for Data Lake Store or wasb:///example/jars for Azure
Storage.
Write information to STDOUT and STDERR
HDInsight logs script output that is written to STDOUT and STDERR. You can view this information using the
Ambari web UI.
NOTE
Ambari is only available if the cluster is successfully created. If you use a script action during cluster creation, and creation
fails, see the troubleshooting section Customize HDInsight clusters using script action for other ways of accessing logged
information.
Most utilities and installation packages already write information to STDOUT and STDERR, however you may want
to add additional logging. To send text to STDOUT, use echo . For example:
By default, echo sends the string to STDOUT. To direct it to STDERR, add >&2 before echo . For example:
This redirects information written to STDOUT to STDERR (2) instead. For more information on IO redirection, see
[Link]
For more information on viewing information logged by script actions, see Customize HDInsight clusters using
script action
Save files as ASCII with LF line endings
Bash scripts should be stored as ASCII format, with lines terminated by LF. Files that are stored as UTF-8, or use
CRLF as the line ending may fail with the following error:
retry() {
local -r CMD="$@"
local -i ATTMEPTNUM=1
local -i RETRYINTERVAL=2
until $CMD
do
if (( ATTMEPTNUM == MAXATTEMPTS ))
then
echo "Attempt $ATTMEPTNUM failed. no more attempts left."
return 1
else
echo "Attempt $ATTMEPTNUM failed! Retrying in $RETRYINTERVAL seconds..."
sleep $(( RETRYINTERVAL ))
ATTMEPTNUM=$ATTMEPTNUM+1
fi
done
}
download_file SOURCEURL DESTFILEPATH [OVERWRITE] Downloads a file from the source URI to the specified file path.
By default, it does not overwrite an existing file.
untar_file TARFILE DESTDIR Extracts a tar file (using -xf ) to the destination directory.
test_is_first_datanode If the current node is the first data (worker) node (named
workernode0) return a 1; otherwise, 0.
HELPER USAGE DESCRIPTION
VARIABLENAME=value
Where VARIABLENAME is the name of the variable. To access the variable, use $VARIABLENAME . For example, to
assign a value provided by a positional parameter as an environment variable named PASSWORD, you would use
the following statement:
PASSWORD=$1
NOTE
The service principal HDInsight uses to access Data Lake Store must have read access to the script.
NOTE
The URI format used to reference the script differs depending on the service being used. For storage accounts associated
with the HDInsight cluster, use wasb:// or wasbs:// . For publicly readable URIs, use http:// or https:// . For Data
Lake Store, use adl:// .
OS_VERSION=$(lsb_release -sr)
if [[ $OS_VERSION == 14* ]]; then
echo "OS verion is $OS_VERSION. Using hue-binaries-14-04."
HUE_TARFILE=[Link]
elif [[ $OS_VERSION == 16* ]]; then
echo "OS verion is $OS_VERSION. Using hue-binaries-16-04."
HUE_TARFILE=[Link]
fi
Troubleshooting
The following are errors you may encounter when using scripts you have developed:
Error: $'\r': command not found . Sometimes followed by syntax error: unexpected end of file .
Cause: This error is caused when the lines in a script end with CRLF. Unix systems expect only LF as the line
ending.
This problem most often occurs when the script is authored on a Windows environment, as CRLF is a common
line ending for many text editors on Windows.
Resolution: If it is an option in your text editor, select Unix format or LF for the line ending. You may also use the
following commands on a Unix system to change the CRLF to an LF:
NOTE
The following commands are roughly equivalent in that they should change the CRLF line endings to LF. Select one based
on the utilities available on your system.
COMMAND NOTES
tr -d '\r' < INFILE > OUTFILE OUTFILE contains a version with only LF endings
sed 's/$'"/`echo \\\r`/" INFILE > OUTFILE OUTFILE contains a version with only LF endings.
Replace INFILE with the file containing the BOM. OUTFILE should be a new file name, which contains the script
without the BOM.
Next steps
Learn how to Customize HDInsight clusters using script action
Use the HDInsight .NET SDK reference to learn more about creating .NET applications that manage HDInsight
Use the HDInsight REST API to learn how to use REST to perform management actions on HDInsight clusters.
OS patching for HDInsight
8/15/2017 • 3 min to read • Edit Online
As a managed Hadoop service, HDInsight takes care of patching the OS of the underlying VMs used by HDInsight
clusters. As of August 1, 2016, we have changed the guest OS patching policy for Linux-based HDInsight clusters
(version 3.4 or greater). The goal of the new policy is to significantly reduce the number of reboots due to patching.
The new policy will continue to patch virtual machines (VMs) on Linux clusters every Monday or Thursday starting
at 12AM UTC in a staggered fashion across nodes in any given cluster. However, any given VM will only reboot at
most once every 30 days due to guest OS patching. In addition, the first reboot for a newly created cluster will not
happen sooner than 30 days from the cluster creation date. Patches will be effective once the VMs are rebooted.
NOTE
This script action will only work with Linux-based HDInsight clusters created after August 1st, 2016. Patches will be effective
only when VMs are rebooted.
NOTE
You must mark this script as persisted when applying to an existing cluster. Otherwise, any new nodes created through
scaling operations will use the default patching schedule. If you apply the script as part of the cluster creation process, it is
persisted automatically.
Next steps
For specific steps on using the script action, see the following sections in the Customize Linuz-based HDInsight
clusters using script action:
Use a script action during cluster creation
Apply a script action to a running cluster
Using Apache Hive as an ETL Tool
8/15/2017 • 5 min to read • Edit Online
You will at typically need to cleanse and transform data before loading it into a destination suitable for analytics.
Extract, Transform, and Load (ETL) operations are used to prepare data and load them into a data destination. One
of the more popular uses of Hive on HDInsight is to take unstructured data and use it to process and then load data
into a relational data warehouse to support decision support systems. In this approach, data is extracted from the
source and stored in scalable storage (such as Azure Storage blobs or Azure Data Lake Store). The data is then
tranformed using a sequence of Hive queries and is ultimately staged within Hive in preparation for bulk loading
into the destination data store. This is the typical ETL process with Hive.
Hadoop is typically used in ETL processes that import either a massive amount of text files (like CSVs) or a smaller,
but frequently changing amount of text files, or both massive and frequently changing. Hive is a great tool to use to
prepare the data before loading it into the data destination. Hive allows you to create a schema over the CSV and
use a SQL-like language to generate MapReduce progams that interact with the data. This is a compelling benefit
of Hive, since SQL is an accessible language that most developers have already mastered and they can quickly get
to productive without having to learn to implement MapReduce programs in Java.
The typical steps to using Hive to perform ETL are as follows:
1) Load data into Azure Data Lake Store or Azure Blob Storage. 2) Create an HDInsight cluster and connect the data
store with HDInsight. Also, create a Metadata Store database (using Azure SQL Database) for use by Hive in storing
your schemas. 4) Define the schema to apply at read-time over data in the data store:
```
DROP TABLE IF EXISTS hvac;
--create the hvac table on comma-separated sensor data stored in Azure Storage blobs
5) Transform the data and load it into the destination. There are a few ways to use Hive during the transformation
and loading:
1) Query and prep data using Hive and save it as a CSV in Azure Data Lake Store or Blob storage. Then use a
tool like SQL Server Integration Services (SSIS) to acquire those CSVs and load the data into the destination
relational database (like SQL Server).
2) Query the data directly from Excel or C# using the Hive ODBC driver.
Data sources
Data sources are typically external data that can be matched to existing data in your data store. Some examples are:
Social media data, log files, sensors, and applications that generate data files.
Datasets obtained from data providers, like weather statistics, or vendor sales numbers.
Streaming data captured, filtered, and processed through a suitable tool or framework (see Collecting and
loading data into HDInsight).
Output targets
We can use hive to output data to a variety of targets including:
A relational database such as SQL Server or Azure SQL Database.
A data warehouse, like Azure SQL Data Warehouse.
Excel
Azure table and blob storage.
Applications or services that require data to be processed into specific formats, or as files that contain specific
types of information structure.
A JSON Document Store like CosmosDB.
Considerations
There are some important points to consider when choosing to perform ETL:
This model is typically used when you want to:
Load stream data or large volumes of semi-structured or unstructured data from external sources into an
existing database or information system.
Cleanse, transform, and validate the data before loading it; perhaps by using more than one
transformation pass through the cluster.
Generate reports and visualizations that are regularly updated. This would be great if the report takes too
long to generate during the day, so instead you schedule the report to run at night. You can use Azure
Scheduler and PowerShell to automatically run a Hive query.
If the target for the data is not a database, you can generate a file in the appropriate format within the query,
like a CSV. This can easily be imported into Excel or Power BI.
If you need to execute several operations on the data as part of the ETL process you should consider how you
manage these. If they are controlled by an external program, rather than as a workflow within the solution, you
will need to decide whether some can be executed in parallel, and you must be able to detect when each job has
completed. Using a workflow mechanism such as Oozie within Hadoop may be easier than trying to orchestrate
several operations using external scripts or custom programs. See Workflow and job orchestration for more
information about Oozie.
See Next
ETL at scale: Learn more about performing ETL at scale.
Operationalize Data Pipelines with Oozie: Learn how to build a data pipeline that uses Hive to summarize CSV
flight delay data, stage the prepared data in Azure Storage blobs and then use Sqoop to load the summarized
data into Azure SQL Database.
ETL Deep Dive: Walk thru an end-to-end ETL pipeline.
Query Hive through the JDBC driver in HDInsight
8/16/2017 • 4 min to read • Edit Online
Learn how to use the JDBC driver from a Java application to submit Hive queries to Hadoop in Azure HDInsight.
The information in this document demonstrates how to connect programmatically and from the SQuirrel SQL
client.
For more information on the Hive JDBC Interface, see HiveJDBCInterface.
Prerequisites
A Hadoop on HDInsight cluster. Either Linux-based or Windows-based clusters work.
IMPORTANT
Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight 3.3
retirement.
jdbc:hive2://[Link]/default;transportMode=http;ssl=true;httpPath=/hive2
Authentication
When establishing the connection, you must use the HDInsight cluster admin name and password to authenticate
to the cluster gateway. When connecting from JDBC clients such as SQuirreL SQL, you must enter the admin name
and password in client settings.
From a Java application, you must use the name and password when establishing a connection. For example, the
following Java code opens a new connection using the connection string, admin name, and password:
[Link](connectionString,clusterAdmin,clusterPassword);
scp USERNAME@CLUSTERNAME:/usr/hdp/current/hive-client/lib/hive-jdbc*[Link] .
scp USERNAME@CLUSTERNAME:/usr/hdp/current/hadoop-client/[Link] .
scp USERNAME@CLUSTERNAME:/usr/hdp/current/hadoop-client/[Link] .
Replace USERNAME with the SSH user account name for the cluster. Replace CLUSTERNAME with
the HDInsight cluster name.
For Windows-based HDInsight, use the following steps to download the jar files.
a. From the Azure portal, select your HDInsight cluster, and then select the Remote Desktop
icon.
b. On the Remote Desktop blade, use the Connect button to connect to the cluster. If the Remote
Desktop is not enabled, use the form to provide a user name and password, then select Enable
to enable Remote Desktop for the cluster.
After selecting Connect, a .rdp file is downloaded. Use this file to launch the Remote Desktop
client. When prompted, use the user name and password you entered for Remote Desktop
access.
c. Once connected, copy the following files from the Remote Desktop session to your local
machine. Put them in a local directory named hivedriver .
C:\apps\dist\hive-[Link].2.9.1-7\lib\[Link]
C:\apps\dist\hadoop-[Link].2.9.1-7\share\hadoop\common\hadoop-common-
[Link].[Link]
C:\apps\dist\hadoop-[Link].2.9.1-7\share\hadoop\common\lib\hadoop-auth-
[Link].[Link]
NOTE
The version numbers included in the paths and file names may be different for your cluster.
d. Disconnect the Remote Desktop session once you have finished copying the files.
2. Start the SQuirreL SQL application. From the left of the window, select Drivers.
3. From the icons at the top of the Drivers dialog, select the + icon to create a driver.
8. Once connected, enter the following query into the SQL query dialog, and then select the Run icon. The
results area should show the results of the query.
select * from hivesampletable limit 10;
Troubleshooting
Unexpected Error occurred attempting to open an SQL connection
Symptoms: When connecting to an HDInsight cluster that is version 3.3 or 3.4, you may receive an error that an
unexpected error occurred. The stack trace for this error begins with the following lines:
Cause: This error is caused by a mismatch in the version of the [Link] file used by SQuirreL and the
one required by the Hive JDBC components.
Resolution: To fix this error, use the following steps:
1. Download the commons-codec jar file from your HDInsight cluster.
2. Exit SQuirreL, and then go to the directory where SQuirreL is installed on your system. In the SquirreL
directory, under the lib directory, replace the existing [Link] with the one downloaded from
the HDInsight cluster.
3. Restart SQuirreL. The error should no longer occur when connecting to Hive on HDInsight.
Next steps
Now that you have learned how to use JDBC to work with Hive, use the following links to explore other ways to
work with Azure HDInsight.
Upload data to HDInsight
Use Hive with HDInsight
Use Pig with HDInsight
Use MapReduce jobs with HDInsight
Use a Java UDF with Hive in HDInsight
8/16/2017 • 4 min to read • Edit Online
Learn how to create a Java-based user-defined function (UDF) that works with Hive. The Java UDF in this example
converts a table of text strings to all-lowercase characters.
Requirements
An HDInsight cluster
IMPORTANT
Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight
retirement on Windows.
Most steps in this document work on both Windows- and Linux-based clusters. However, the steps used to
upload the compiled UDF to the cluster and run it are specific to Linux-based clusters. Links are provided to
information that can be used with Windows-based clusters.
Java JDK 8 or later (or an equivalent, such as OpenJDK)
Apache Maven
A text editor or Java IDE
IMPORTANT
If you create the Python files on a Windows client, you must use an editor that uses LF as a line ending. If you are not
sure whether your editor uses LF or CRLF, see the Troubleshooting section for steps on removing the CR character.
NOTE
If you are using PowerShell, you must put quotes around the parameters. For example,
mvn archetype:generate "-DgroupId=[Link]" "-DartifactId=ExampleUDF" "-
DarchetypeArtifactId=maven-archetype-quickstart" "-DinteractiveMode=false"
.
This command creates a directory named exampleudf, which contains the Maven project.
2. Once the project has been created, delete the exampleudf/src/test directory that was created as part of the
project.
3. Open the exampleudf/[Link], and replace the existing <dependencies> entry with the following XML:
<dependencies>
<dependency>
<groupId>[Link]</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>hive-exec</artifactId>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
These entries specify the version of Hadoop and Hive included with HDInsight 3.5. You can find information
on the versions of Hadoop and Hive provided with HDInsight from the HDInsight component versioning
document.
Add a <build> section before the </project> line at the end of the file. This section should contain the
following XML:
<build>
<plugins>
<!-- build for Java 1.8. This is required by HDInsight 3.5 -->
<plugin>
<groupId>[Link]</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- build an uber jar -->
<plugin>
<groupId>[Link]</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- Keep us from getting a can't overwrite file error -->
<transformers>
<transformer
implementation="[Link]">
</transformer>
<transformer
implementation="[Link]">
</transformer>
</transformers>
<!-- Keep us from getting a bad signature error -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
These entries define how to build the project. Specifically, the version of Java that the project uses and how
to build an uberjar for deployment to the cluster.
Save the file once the changes have been made.
4. Rename exampleudf/src/main/java/com/microsoft/examples/[Link] to [Link], and
then open the file in your editor.
5. Replace the contents of the [Link] file with the following, then save the file.
package [Link];
import [Link];
import [Link];
import [Link].*;
This code implements a UDF that accepts a string value, and returns a lowercase version of the string.
This command builds and packages the UDF into the exampleudf/target/[Link] file.
2. Use the scp command to copy the file to the HDInsight cluster.
Replace myuser with the SSH user account for your cluster. Replace mycluster with the cluster name. If you
used a password to secure the SSH account, you are prompted to enter the password. If you used a
certificate, you may need to use the -i parameter to specify the private key file.
3. Connect to the cluster using SSH.
ssh myuser@[Link]
This command assumes that you used the default of admin for the login account for your cluster.
2. Once you arrive at the jdbc:hive2://localhost:10001/> prompt, enter the following to add the UDF to Hive
and expose it as a function.
NOTE
This example assumes that Azure Storage is default storage for the cluster. If your cluster uses Data Lake Store
instead, change the wasb:/// value to adl:/// .
3. Use the UDF to convert values retrieved from a table to lower case strings.
This query selects the device platform (Android, Windows, iOS, etc.) from the table, convert the string to
lower case, and then display them. The output appears similar to the following text:
+----------+--+
| _c0 |
+----------+--+
| android |
| android |
| android |
| android |
| android |
| android |
| android |
| android |
| android |
| android |
+----------+--+
Next steps
For other ways to work with Hive, see Use Hive with HDInsight.
For more information on Hive User-Defined Functions, see Hive Operators and User-Defined Functions section of
the Hive wiki at [Link].
Use Python User Defined Functions (UDF) with Hive
and Pig in HDInsight
8/16/2017 • 13 min to read • Edit Online
Learn how to use Python user-defined functions (UDF) with Apache Hive and Pig in Hadoop on Azure HDInsight.
Python on HDInsight
Python2.7 is installed by default on HDInsight 3.0 and later. Apache Hive can be used with this version of Python
for stream processing. Stream processing uses STDOUT and STDIN to pass data between Hive and the UDF.
HDInsight also includes Jython, which is a Python implementation written in Java. Jython runs directly on the Java
Virtual Machine and does not use streaming. Jython is the recommended Python interpreter when using Python
with Pig.
WARNING
The steps in this document make the following assumptions:
You create the Python scripts on your local development environment.
You upload the scripts to HDInsight using either the scp command from a local Bash session or the provided
PowerShell script.
If you want to use the Azure Cloud Shell (bash) preview to work with HDInsight, then you must:
Create the scripts inside the cloud shell environment.
Use scp to upload the files from the cloud shell to HDInsight.
Use ssh from the cloud shell to connect to HDInsight and run the examples.
Hive UDF
Python can be used as a UDF from Hive through the HiveQL TRANSFORM statement. For example, the following
HiveQL invokes the [Link] file stored in the default Azure Storage account for the cluster.
Linux-based HDInsight
Windows-based HDInsight
add file wasb:///[Link];
NOTE
On Windows-based HDInsight clusters, the USING clause must specify the full path to [Link].
#!/usr/bin/env python
import sys
import string
import hashlib
while True:
line = [Link]()
if not line:
break
The script output is a concatenation of the input values for devicemake and devicemodel , and a hash of the
concatenated value.
See Running the examples for how to run this example on your HDInsight cluster.
Pig UDF
A Python script can be used as a UDF from Pig through the GENERATE statement. You can run the script using
either Jython or C Python.
Jython runs on the JVM, and can natively be called from Pig.
C Python is an external process, so the data from Pig on the JVM is sent out to the script running in a Python
process. The output of the Python script is sent back into Pig.
To specify the Python interpreter, use register when referencing the Python script. The following examples
register scripts with Pig as myfuncs :
To use Jython: register '/path/to/[Link]' using jython as myfuncs;
To use C Python: register '/path/to/[Link]' using streaming_python as myfuncs;
IMPORTANT
When using Jython, the path to the pig_jython file can be either a local path or a WASB:// path. However, when using C
Python, you must reference a file on the local file system of the node that you are using to submit the Pig job.
Once past registration, the Pig Latin for this example is the same for both:
In the Pig Latin example, we defined the LINE input as a chararray because there is no consistent schema for the
input. The Python script transforms the data into a consistent schema for output.
1. The @outputSchema statement defines the format of the data that is returned to Pig. In this case, it's a data
bag, which is a Pig data type. The bag contains the following fields, all of which are chararray (strings):
date - the date the log entry was created
time - the time the log entry was created
classname - the class name the entry was created for
level - the log level
detail - verbose details for the log entry
2. Next, the def create_structure(input) defines the function that Pig passes line items to.
3. The example data, [Link] , mostly conforms to the date, time, classname, level, and detail schema we
want to return. However, it contains a few lines that begin with *[Link]* . These lines must be
modified to match the schema. The if statement checks for those, then massages the input data to move
the *[Link]* string to the end, bringing the data in-line with our expected output schema.
4. Next, the split command is used to split the data at the first four space characters. The output is assigned
into date , time , classname , level , and detail .
5. Finally, the values are returned to Pig.
When the data is returned to Pig, it has a consistent schema as defined in the @outputSchema statement.
SSH
For more information on using SSH, see Use SSH with HDInsight.
1. Use scp to copy the files to your HDInsight cluster. For example, the following command copies the files to
a cluster named mycluster.
ssh myuser@[Link]
3. From the SSH session, add the python files uploaded previously to the WASB storage for the cluster.
After uploading the files, use the following steps to run the Hive and Pig jobs.
Use the Hive UDF
1. Use the hive command to start the hive shell. You should see a hive> prompt once the shell has loaded.
2. Enter the following query at the hive> prompt:
add file wasb:///[Link];
SELECT TRANSFORM (clientid, devicemake, devicemodel)
USING 'python [Link]' AS
(clientid string, phoneLabel string, phoneHash string)
FROM hivesampletable
ORDER BY clientid LIMIT 50;
3. After entering the last line, the job should start. Once the job completes, it returns output similar to the
following example:
3. After entering the following line, the job should start. Once the job completes, it returns output similar to the
following data:
4. Use quit to exit the Grunt shell, and then use the following to edit the [Link] file on the local file system:
nano [Link]
5. Once in the editor, uncomment the following line by removing the # character from the beginning of the
line:
Once the change has been made, use Ctrl+X to exit the editor. Select Y, and then enter to save the changes.
6. Use the pig command to start the shell again. Once you are at the grunt> prompt, use the following to
run the Python script using the C Python interpreter.
Register '[Link]' using streaming_python as myfuncs;
LOGS = LOAD 'wasb:///example/data/[Link]' as (LINE:chararray);
LOG = FILTER LOGS by LINE is not null;
DETAILS = foreach LOG generate myfuncs.create_structure(LINE);
DUMP DETAILS;
Once this job completes, you should see the same output as when you previously ran the script using
Jython.
PowerShell: Upload the files
You can use PowerShell to upload the files to the HDInsight server. Use the following script to upload the Python
files:
IMPORTANT
The steps in this section use Azure PowerShell. For more information on using Azure PowerShell, see How to install and
configure Azure PowerShell.
Set-AzureStorageBlobContent `
-File $pathToStreamingFile `
-Blob "[Link]" `
-Container $container `
-Context $context
Set-AzureStorageBlobContent `
-File $pathToJythonFile `
-Blob "[Link]" `
-Container $container `
-Context $context
IMPORTANT
Change the C:\path\to value to the path to the files on your development environment.
This script retrieves information for your HDInsight cluster, then extracts the account and key for the default
storage account, and uploads the files to the root of the container.
NOTE
For more information on uploading files, see the Upload data for Hadoop jobs in HDInsight document.
IMPORTANT
Before running, the script prompts you for the HTTPs/Admin account information for your HDInsight cluster.
# Login to your Azure subscription
# Is there an active Azure subscription?
$sub = Get-AzureRmSubscription -ErrorAction SilentlyContinue
if(-not($sub))
{
Add-AzureRmAccount
}
$jobDefinition = New-AzureRmHDInsightHiveJobDefinition `
-Query $HiveQuery
$job = Start-AzureRmHDInsightJob `
-ClusterName $clusterName `
-JobDefinition $jobDefinition `
-HttpCredential $creds
Write-Host "Wait for the Hive job to complete ..." -ForegroundColor Green
Wait-AzureRmHDInsightJob `
-JobId $[Link] `
-ClusterName $clusterName `
-HttpCredential $creds
# Uncomment the following to see stderr output
# Get-AzureRmHDInsightJobOutput `
# -Clustername $clusterName `
# -JobId $[Link] `
# -HttpCredential $creds `
# -DisplayOutputType StandardError
Write-Host "Display the standard output ..." -ForegroundColor Green
Get-AzureRmHDInsightJobOutput `
-Clustername $clusterName `
-JobId $[Link] `
-HttpCredential $creds
The output for the Hive job should appear similar to the following example:
Pig (Jython )
PowerShell can also be used to run Pig Latin jobs. To run a Pig Latin job that uses the [Link] script, use the
following PowerShell script:
NOTE
When remotely submitting a job using PowerShell, it is not possible to use C Python as the interpreter.
# Login to your Azure subscription
# Is there an active Azure subscription?
$sub = Get-AzureRmSubscription -ErrorAction SilentlyContinue
if(-not($sub))
{
Add-AzureRmAccount
}
$job = Start-AzureRmHDInsightJob `
-ClusterName $clusterName `
-JobDefinition $jobDefinition `
-HttpCredential $creds
Write-Host "Wait for the Pig job to complete ..." -ForegroundColor Green
Wait-AzureRmHDInsightJob `
-Job $[Link] `
-ClusterName $clusterName `
-HttpCredential $creds
# Uncomment the following to see stderr output
# Get-AzureRmHDInsightJobOutput `
# -Clustername $clusterName `
# -JobId $[Link] `
# -HttpCredential $creds `
# -DisplayOutputType StandardError
Write-Host "Display the standard output ..." -ForegroundColor Green
Get-AzureRmHDInsightJobOutput `
-Clustername $clusterName `
-JobId $[Link] `
-HttpCredential $creds
The output for the Pig job should appear similar to the following data:
Troubleshooting
Errors when running jobs
When running the hive job, you may encounter an error similar to the following text:
This problem may be caused by the line endings in the Python file. Many Windows editors default to using CRLF as
the line ending, but Linux applications usually expect LF.
You can use the following PowerShell statements to remove the CR characters before uploading the file to
HDInsight:
$original_file ='c:\path\to\[Link]'
$text = [[Link]]::ReadAllText($original_file) -replace "`r`n", "`n"
[[Link]]::WriteAllText($original_file, $text)
PowerShell scripts
Both of the example PowerShell scripts used to run the examples contain a commented line that displays error
output for the job. If you are not seeing the expected output for the job, uncomment the following line and see if
the error information indicates a problem.
# Get-AzureRmHDInsightJobOutput `
-Clustername $clusterName `
-JobId $[Link] `
-HttpCredential $creds `
-DisplayOutputType StandardError
The error information (STDERR) and the result of the job (STDOUT) are also logged to your HDInsight storage.
Hive /HivePython/stderr
/HivePython/stdout
Pig /PigPython/stderr
/PigPython/stdout
Next steps
If you need to load Python modules that aren't provided by default, see How to deploy a module to Azure
HDInsight.
For other ways to use Pig, Hive, and to learn about using MapReduce, see the following documents:
Use Hive with HDInsight
Use Pig with HDInsight
Use MapReduce with HDInsight
Use C# user-defined functions with Hive and Pig
streaming on Hadoop in HDInsight
8/16/2017 • 7 min to read • Edit Online
Learn how to use C# user defined functions (UDF) with Apache Hive and Pig on HDInsight.
IMPORTANT
The steps in this document work with both Linux-based and Windows-based HDInsight clusters. Linux is the only operating
system used on HDInsight version 3.4 or greater. For more information, see HDInsight component versioning.
Both Hive and Pig can pass data to external applications for processing. This process is known as streaming. When
using a .NET applciation, the data is passed to the application on STDIN, and the application returns the results on
STDOUT. To read and write from STDIN and STDOUT, you can use [Link]() and [Link]()
from a console application.
Prerequisites
A familiarity with writing and building C# code that targets .NET Framework 4.5.
Use whatever IDE you want. We recommend Visual Studio 2015, 2017, or Visual Studio Code. The steps
in this document use Visual Studio 2017.
A way to upload .exe files to the cluster and run Pig and Hive jobs. We recommend the Data Lake Tools for
Visual Studio, Azure PowerShell and Azure CLI. The steps in this document use the Data Lake Tools for Visual
Studio to upload the files and run the example Hive query.
For information on other ways to run Hive queries and Pig jobs, see the following documents:
Use Apache Hive with HDInsight
Use Apache Pig with HDInsight
A Hadoop on HDInsight cluster.
.NET on HDInsight
Linux-based HDInsight clusters using Mono ([Link] to run .NET applications. Mono
version 4.2.1 is included with HDInsight version 3.5.
For more information on Mono compatibility with .NET Framework versions, see Mono compatibility.
To use a specific version of Mono, see the Install or update Mono document.
Windows-based HDInsight clusters use the Microsoft .NET CLR to run .NET applications.
For more information on the version of the .NET framework and Mono included with HDInsight versions, see
HDInsight component versions.
IMPORTANT
Select .NET Framework 4.5 if you are using a Linux-based HDInsight cluster. For more information on Mono
compatibility with .NET Framework versions, see Mono compatibility.
using System;
using [Link];
using [Link];
using [Link];
namespace HiveCSharp
{
class Program
{
static void Main(string[] args)
{
string line;
// Read stdin in a loop
while ((line = [Link]()) != null)
{
// Parse the string, trimming line feeds
// and splitting fields at tabs
line = [Link]('\n');
string[] field = [Link]('\t');
string phoneLabel = field[1] + ' ' + field[2];
// Emit new data to stdout, delimited by tabs
[Link]("{0}\t{1}\t{2}", field[0], phoneLabel, GetMD5Hash(phoneLabel));
}
}
/// <summary>
/// Returns an MD5 hash for the given string
/// </summary>
/// <param name="input">string value</param>
/// <returns>an MD5 hash</returns>
static string GetMD5Hash(string input)
{
// Step 1, calculate MD5 hash from input
MD5 md5 = [Link]();
byte[] inputBytes = [Link](input);
byte[] hash = [Link](inputBytes);
namespace PigUDF
{
class Program
{
static void Main(string[] args)
{
string line;
// Read stdin in a loop
while ((line = [Link]()) != null)
{
// Fix formatting on lines that begin with an exception
if([Link]("[Link]"))
{
// Trim the error info off the beginning and add a note to the end of the line
line = [Link](0, 21) + " - [Link]";
}
// Split the fields apart at tab characters
string[] field = [Link]('\t');
// Put fields back together for writing
[Link]([Link]("\t",field));
}
}
}
}
This application parses the lines sent from Pig, and reformat lines that begin with [Link] .
3. Save [Link], and then build the project.
Upload to storage
1. In Visual Studio, open Server Explorer.
2. Expand Azure, and then expand HDInsight.
3. If prompted, enter your Azure subscription credentials, and then click Sign In.
4. Expand the HDInsight cluster that you wish to deploy this application to. An entry with the text (Default
Storage Account) is listed.
If this entry can be expanded, you are using an Azure Storage Account as default storage for the
cluster. To view the files on the default storage for the cluster, expand the entry and then double-click
the (Default Container).
If this entry cannot be expanded, you are using Azure Data Lake Store as the default storage for the
cluster. To view the files on the default storage for the cluster, double-click the (Default Storage
Account) entry.
5. To upload the .exe files, use one of the following methods:
If using an Azure Storage Account, click the upload icon, and then browse to the bin\debug folder
for the HiveCSharp project. Finally, select the [Link] file and click Ok.
If using Azure Data Lake Store, right-click an empty area in the file listing, and then select Upload.
Finally, select the [Link] file and click Open.
Once the [Link] upload has finished, repeat the upload process for the [Link] file.
IMPORTANT
Uncomment the add file statement that matches the type of default storage used for your cluster.
This query selects the clientid , devicemake , and devicemodel fields from hivesampletable , and passes the
fields to the [Link] application. The query expects the application to return three fields, which are
stored as clientid , phoneLabel , and phoneHash . The query also expects to find [Link] in the root
of the default storage container.
5. Click Submit to submit the job to the HDInsight cluster. The Hive Job Summary window opens.
6. Click Refresh to refresh the summary until Job Status changes to Completed. To view the job output, click
Job Output.
If you are using a Windows-based HDInsight cluster, Connect to the cluster using Remote Desktop
2. Use one the following command to start the Pig command line:
pig
IMPORTANT
If you are using a Windows-based cluster, use the following commands instead:
cd %PIG_HOME%
bin\pig
The DEFINE statement creates an alias of streamer for the [Link] applications, and CACHE loads it from
default storage for the cluster. Later, streamer is used with the STREAM operator to process the single lines
contained in LOG and return the data as a series of columns.
NOTE
The application name that is used for streaming must be surrounded by the ` (backtick) character when aliased, and '
(single quote) when used with SHIP .
4. After entering the last line, the job should start. It returns output similar to the following text:
Next steps
In this document, you have learned how to use a .NET Framework application from Hive and Pig on HDInsight. If
you would like to learn how to use Python with Hive and Pig, see Use Python with Hive and Pig in HDInsight.
For other ways to use Pig and Hive, and to learn about using MapReduce, see the following documents:
Use Hive with HDInsight
Use Pig with HDInsight
Use MapReduce with HDInsight
Process and analyze JSON documents using Hive in
HDInsight
8/16/2017 • 6 min to read • Edit Online
Learn how to process and analyze JSON files using Hive in HDInsight. The following JSON document is used in the
tutorial:
{
"StudentId": "trgfg-5454-fdfdg-4346",
"Grade": 7,
"StudentDetails": [
{
"FirstName": "Peggy",
"LastName": "Williams",
"YearJoined": 2012
}
],
"StudentClassCollection": [
{
"ClassId": "89084343",
"ClassParticipation": "Satisfied",
"ClassParticipationRank": "High",
"Score": 93,
"PerformedActivity": false
},
{
"ClassId": "78547522",
"ClassParticipation": "NotSatisfied",
"ClassParticipationRank": "None",
"Score": 74,
"PerformedActivity": false
},
{
"ClassId": "78675563",
"ClassParticipation": "Satisfied",
"ClassParticipationRank": "Low",
"Score": 83,
"PerformedActivity": true
}
]
}
WARNING
JDK 1.8 doesn't work with this SerDe.
4: Go to the folder where you have downloaded this package and then type “mvn package”. This should create the
necessary jar files that you can then copy over to the cluster.
5: Go to the target folder under the root folder where you downloaded the package. Upload the json-serde-[Link]-
[Link] file to head-node of your cluster. I usually put it under the hive binary folder:
C:\apps\dist\hive-[Link].1.11.0-2316\bin or something similar.
6: In the hive prompt, type “add jar /path/to/[Link]”. Since in my case,
the jar is in the C:\apps\dist\hive-0.13.x\bin folder, I can directly add the jar with the name as shown:
add jar [Link];
Now, you are ready to use the SerDe to run queries against the JSON document.
The following statement creates a table with a defined schema:
SELECT SUM(scores)
FROM json_table jt
lateral view explode([Link]) collection as scores;
The preceding query uses lateral view explode UDF to expand the array of scores so that they can be summed.
Here is the output from the Hive console.
To find which subjects a given student has scored more than 80 points:
SELECT
[Link]
FROM json_table jt
lateral view explode([Link]) collection as score where score > 80;
The preceding query returns a Hive array unlike get_json_object, which returns a string.
If you want to skil malformed JSON, then as explained in the wiki page of this SerDe you can achieve that by typing
the following code:
Summary
In conclusion, the type of JSON operator in Hive that you choose depends on your scenario. If you have a simple
JSON document and you only have one field to look up on – you can choose to use the Hive UDF get_json_object. If
you have more than one key to look up on, then you can use json_tuple. If you have a nested document, then you
should use the JSON SerDe.
Next steps
For other related articles, see
Use Hive and HiveQL with Hadoop in HDInsight to analyze a sample Apache log4j file
Analyze flight delay data by using Hive in HDInsight
Analyze Twitter data using Hive in HDInsight
Run a Hadoop job using Azure Cosmos DB and HDInsight
Connect Excel to Hadoop in Azure HDInsight with
the Microsoft Hive ODBC driver
8/16/2017 • 4 min to read • Edit Online
Microsoft's Big Data solution integrates Microsoft Business Intelligence (BI) components with Apache Hadoop
clusters that have been deployed by the Azure HDInsight. An example of this integration is the ability to connect
Excel to the Hive data warehouse of a Hadoop cluster in HDInsight using the Microsoft Hive Open Database
Connectivity (ODBC) Driver.
It is also possible to connect the data associated with an HDInsight cluster and other data sources, including other
(non-HDInsight) Hadoop clusters, from Excel using the Microsoft Power Query add-in for Excel. For information on
installing and using Power Query, see Connect Excel to HDInsight with Power Query.
NOTE
While the steps in this article can be used with either a Linux or Windows-based HDInsight cluster, Windows is required for
the client workstation.
Prerequisites:
Before you begin this article, you must have the following items:
An HDInsight cluster. To create one, see Get started with Azure HDInsight.
A workstation with Office 2013 Professional Plus, Office 365 Pro Plus, Excel 2013 Standalone, or Office 2010
Professional Plus.
PROPERTY DESCRIPTION
Port Use 443. (This port has been changed from 563 to 443.)
User Name Enter HDInsight cluster HTTP user username. The default
username is admin.
There are some important parameters to be aware of when you click Advanced Options:
PARAMETER DESCRIPTION
Use Native Query When it is selected, the ODBC driver will NOT try to
convert TSQL into HiveQL. You shall use it only if you are
100% sure you are submitting pure HiveQL statements.
When connecting to SQL Server or Azure SQL Database,
you should leave it unchecked.
PARAMETER DESCRIPTION
Rows fetched per block When fetching a large number of records, tuning this
parameter may be required to ensure optimal
performances.
Default string column length, Binary column length, The data type lengths and precisions may affect how data
Decimal column scale is returned. They cause incorrect information to be
returned due to loss of precision and/or truncation.
6. Click Test to test the data source. When the data source is configured correctly, it shows TESTS COMPLETED
SUCCESSFULLY!.
7. Click OK to close the Test dialog. The new data source should now be listed on the ODBC Data Source
Administrator.
8. Click OK to exit the wizard.
Next steps
In this article, you learned how to use the Microsoft Hive ODBC driver to retrieve data from the HDInsight Service
into Excel. Similarly, you can retrieve data from the HDInsight Service into SQL Database. It is also possible to
upload data into an HDInsight Service. To learn more, see:
Analyze flight delay data using HDInsight
Upload Data to HDInsight
Use Sqoop with HDInsight
Using Apache Hive and the Ambari Hive view to
Analyze Sensor Data
8/16/2017 • 5 min to read • Edit Online
In this article you will learn how to analyze sensor data by using the Hive Query Console with HDInsight (Hadoop),
then visualize the data in Microsoft Excel by using Power View.
In this example, you'll use Hive to process historical data produced by heating, ventilation, and air conditioning
(HVAC) systems to identify systems that are not able to reliably maintain a set temperature. You will learn how to:
Create HIVE tables to query data stored in comma separated value (CSV) files.
Create HIVE queries to analyze the data.
Use Microsoft Excel to connect to HDInsight (using open database connectivity (ODBC) to retrieve the analyzed
data.
Use Power View to visualize the data.
Prerequisites
An HDInsight (Hadoop) cluster: See Provision Hadoop clusters in HDInsight for information about creating a
cluster.
Microsoft Excel 2016
[[Link]] Microsoft Excel is used for data visualization with Power View.
[Link]
When prompted, authenticate by using the administrator user name and password you used when provisioning
this cluster. On the right, click on "Hive". Look for Hive View 2.0 towards the bottom of the center page, then click
on "Go to View." Stay on this page as we begin the tutorial.
1. Install the Hive ODBC Driver on Windows.
2. Install Excel 2016 on Windows.
Introduction
Many personal and commercial devices now contain sensors, which collect information from the physical world.
For example, most phones have a GPS, fitness devices track how many steps you've taken, and thermostats can
monitor the temperature of a building.
In this tutorial, you'll learn how HDInsight can be used to process historical data produced by heating, ventilation,
and air conditioning (HVAC) systems to identify systems that are not able to reliably maintain a set temperature.
You will learn how to:
Refine and enrich temperature data from buildings in several countries
Analyze the data to determine which buildings have problems maintaining comfortable temperatures (actual
recorded temperature vs. temperature the thermostat was set to)
Infer reliability of HVAC systems used in the buildings
Visualize the data in Microsoft Excel
1. If you haven't already installed Azure Storage Explorer, this will prompt you to.
2. Connect your Azure Account to Azure Storage Explorer. Look at Getting Started with Azure Storage Explorer
for more information.
3. Expand your Storage Account.
4. Expand Blob Containers.
5. Create a new blob container called "sensordata".
6. Under the "sensordata" blob container, create a new folder called "hvac".
7. Upload the [Link] file to the new hvac folder.
Creating Hive Tables to Query the Sensor Data in the Azure Storage blobs
The following Hive statement creates an external table that allows Hive to query data stored in Azure Blob Storage.
External tables preserve the data in the original file format while allowing Hive to perform queries against the data
within the file. In this case, the data is stored in the file as comma separated values (CSV).
The Hive statements below create a new table, named hvac, by describing the fields within the files, the delimiter
(comma) between fields, and the location of the file in Azure Blob Storage. This will allow you to create Hive queries
over your data. Remember to replace the path with your individual HDInsight cluster name.
1. In your Ambari console that you logged into earlier, you should be on the Hive screen.
2. Copy and paste the query below and put it in the white textbox in the middle of the screen.
1. In the Microsoft Hive ODBC Driver Connection dialog, enter the following values, and then click OK.
Host - The host name of your HDInsight cluster. For example, [Link]
User Name - The administrator name for your HDInsight cluster (usually admin)
Password - The administrator password
All other fields can be left as the default values.
1. In the Query Wizard, select the hvac_temperatures table, and then select the > button.
1. Click Next to continue through the wizard, until you reach a dialog with a Finish button. Click Finish.
2. When the Import Data dialog appears, click OK to accept the defaults. After the query completes, the data
will be displayed in Excel.
3. Click Pivot Table Report and then OK
1. In the pivot table, drag buildingid to the rows area, date to the columns area, and actualtemp to the values area.
1. Click on the dropdown arrow next ot actualtemp in the values section and click Value Field Settings.
1. Change the count to an average and click OK.
2. You should be able to see interesting trends by date for each buildings temperature. Your results should
look like the following:
See also
Connect to Hive with JDBC or ODBC
Use Hive with HDInsight
Analyze Twitter data using Hive and Hadoop on
HDInsight
8/16/2017 • 5 min to read • Edit Online
Learn how to use Apache Hive to process Twitter data. The result is a list of Twitter users who sent the most tweets
that contain a certain word.
IMPORTANT
The steps in this document were tested on HDInsight 3.6.
Linux is the only operating system used on HDInsight version 3.4 or greater. For more information, see HDInsight retirement
on Windows.
FIELD VALUE
Name MyHDInsightApp
Description MyHDInsightApp
Website [Link]
4. Check Yes, I agree, and then click Create your Twitter application.
5. Click the Permissions tab. The default permission is Read only.
6. Click the Keys and Access Tokens tab.
7. Click Create my access token.
8. Click Test OAuth in the upper-right corner of the page.
9. Write down consumer key, Consumer secret, Access token, and Access token secret.
Download tweets
The following Python code downloads 10,000 tweets from Twitter and save them to a file named [Link].
NOTE
The following steps are performed on the HDInsight cluster, since Python is already installed.
ssh USERNAME@[Link]
nano [Link]
IMPORTANT
Replace the placeholder text for the following items with the information from your twitter application:
consumer_secret
consumer_key
access_token
access_token_secret
python [Link]
NOTE
If it is taking a long time for the progress bar to advance, you should change the filter to track trending topics. When
there are many tweets about the topic in your filter, you can quickly get the 10000 tweets needed.
These commands store the data in a location that all nodes in the cluster can access.
nano [Link]
This command runs the the [Link] file. Once the query completes, you see a
jdbc:hive2//localhost:10001/> prompt.
4. From the beeline prompt, use the following query to verify that data was imported:
This query returns a maximum of 10 tweets that contain the word Azure in the message text.
Next steps
You have learned how to transform an unstructured JSON dataset into a structured Hive table. To learn more about
Hive on HDInsight, see the following documents:
Get started with HDInsight
Analyze flight delay data using HDInsight
Analyze flight delays with Hive and export to SQL
Database using Sqoop
8/16/2017 • 6 min to read • Edit Online
Learn how to analyze flight delay data using Hive on Linux-based HDInsight then export the data to Azure SQL
Database using Sqoop.
IMPORTANT
The steps in this document require an HDInsight cluster that uses Linux. Linux is the only operating system used on
HDInsight version 3.4 or greater. For more information, see HDInsight retirement on Windows.
Prerequisites
An HDInsight cluster. See Get started using Hadoop with Hive in HDInsight on Linux for steps on creating
a new Linux-based HDInsight cluster.
Azure SQL Database. You use an Azure SQL database as a destination data store. If you do not have a SQL
Database already, see SQL Database tutorial: Create a SQL database in minutes.
Azure CLI. If you have not installed the Azure CLI, see Install and Configure the Azure CLI for more steps.
NAME VALUE
3. Click Download.
Replace FILENAME with the name of the zip file. Replace USERNAME with the SSH login for the HDInsight
cluster. Replace CLUSTERNAME with the name of the HDInsight cluster.
NOTE
If you use a password to authenticate your SSH login, you are prompted for the password. If you used a public key,
you may need to use the -i parameter and specify the path to the matching private key. For example,
scp -i ~/.ssh/id_rsa [Link] USERNAME@[Link]: .
2. Once the upload has completed, connect to the cluster using SSH:
ssh USERNAME@[Link]
unzip [Link]
nano [Link]
4. Once the [Link] script finishes running, use the following command to open an interactive
Beeline session:
5. When you receive the jdbc:hive2://localhost:10001/> prompt, use the following query to retrieve data
from the imported flight delay data.
This query retrieves a list of cities that experienced weather delays, along with the average delay time, and
save it to /tutorials/flightdelays/output . Later, Sqoop reads the data from this location and export it to
Azure SQL Database.
6. To exit Beeline, enter !quit at the prompt.
1. Use SSH to connect to the Linux-based HDInsight cluster, and run the following steps from the SSH session.
2. Use the following command to install FreeTDS:
3. Once the install completes, use the following command to connect to the SQL Database server. Replace
serverName with the SQL Database server name. Replace adminLogin and adminPassword with the
login for SQL Database. Replace databaseName with the database name.
TDSVER=8.0 tsql -H <serverName>.[Link] -U <adminLogin> -P <adminPassword> -p 1433 -D
<databaseName>
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Default database being set to sqooptest
1>
When the GO statement is entered, the previous statements are evaluated. This query creates a table named
delays, with a clustered index.
Use the following query to verify that the table has been created:
This command returns a list of databases, including the database that you created the delays table in earlier.
2. Use the following command to export data from hivesampletable to the delays table:
Sqoop connects to the database containing the delays table, and exports data from the
/tutorials/flightdelays/output directory to the delays table.
3. After the command completes, use the following to connect to the database using TSQL:
TDSVER=8.0 tsql -H <serverName>.[Link] -U <adminLogin> -P <adminPassword> -p 1433 -D
<databaseName>
Once connected, use the following statements to verify that the data was exported to the delays table:
You should see a listing of data in the table. Type exit to exit the tsql utility.
Next steps
To learn more ways to work with data in HDInsight, see the following documents:
Use Hive with HDInsight
Use Oozie with HDInsight
Use Sqoop with HDInsight
Use Pig with HDInsight
Develop Java MapReduce programs for HDInsight
Develop Python Hadoop streaming programs for HDInsight
Use Hive with Windows-based HDInsight to analyze
logs from websites
8/16/2017 • 1 min to read • Edit Online
Learn how to use HiveQL with HDInsight to analyze logs from a website. Website log analysis can be used to
segment your audience based on similar activities, categorize site visitors by demographics, and to find out the
content they view, the websites they come from, and so on.
IMPORTANT
The steps in this document only work with Windows-based HDInsight clusters. HDInsight is only available on Windows for
versions lower than HDInsight 3.4. Linux is the only operating system used on HDInsight version 3.4 or greater. For more
information, see HDInsight retirement on Windows.
In this sample, you will use an HDInsight cluster to analyze website log files to get insight into the frequency of
visits to the website from external websites in a day. You'll also generate a summary of website errors that the
users experience. You will learn how to:
Connect to a Azure Blob storage, which contains website log files.
Create HIVE tables to query those logs.
Create HIVE queries to analyze the data.
Use Microsoft Excel to connect to HDInsight (by using open database connectivity (ODBC) to retrieve the
analyzed data.
Prerequisites
You must have provisioned a Hadoop cluster on Azure HDInsight. For instructions, see Provision HDInsight
Clusters.
You must have Microsoft Excel 2013 or Excel 2010 installed.
You must have Microsoft Hive ODBC Driver to import data from Hive into Excel.
[Link]
When prompted, authenticate by using the administrator user name and password you used when
provisioning the cluster.
3. From the web page that opens, click the Getting Started Gallery tab, and then under the Solutions with
Sample Data category, click the Website Log Analysis sample.
4. Follow the instructions provided on the web page to finish the sample.
Next steps
Try the following sample: Analyzing sensor data using Hive with HDInsight.
Spark Scenarios - Build high-speed scalable data
pipelines
8/16/2017 • 7 min to read • Edit Online
For even more scenarios, see Eight scenarios with Apache Spark on Azure
At the top of the new notebook, click to rename the notebook from Untitled to Log Analysis
You should see output showning that the SparkContext and HiveContext objects are not available, as shown in the
example below.
Create an RDD using the sample log data already available on the cluster. You can access the data in the default
storage account associated with the cluster at \HdiSamples\HdiSamples\WebsiteLogSampleData\SampleLog\[Link] .
logs = [Link]('wasbs:///HdiSamples/HdiSamples/WebsiteLogSampleData/SampleLog/[Link]')
Retrieve a sample log set to verify that the previous step completed successfully. You should see output similiar to
the following example shown below.
[Link](5)
[Link]('wasbs:///HdiSamples/HdiSamples/WebsiteLogSampleData/[Link]')
The iislogparser provides a function parse_log_line that returns None if a log line is a header row, and returns
an instance of the LogLine class if it encounters a log line. Use the LogLine class to extract only the log lines from
the RDD. Use the command shown below to do this.
def parse_line(l):
import iislogparser
return iislogparser.parse_log_line(l)
logLines = [Link](parse_line).filter(lambda p: p is not None).cache()
Verify successful completion using the command shown below. Your processed output should look similiar to the
image shown after the command.
[Link](2)
The LogLine class, in turn, has some useful methods, like is_error() , which returns whether a log entry has an
error code. Use this to compute the number of errors in the extracted log lines, and then log all the errors to a
different file.
You can also use Matplotlib to construct a visualization of the data. For example, if you want to isolate the cause
of requests that run for a long time, you might want to find the files that take the most time to serve on average.
The snippet below retrieves the top 25 resources that took most time to serve a request.
def avgTimeTakenByKey(rdd):
return [Link](lambda line: (line.time_taken, 1),
lambda x, line: (x[0] + line.time_taken, x[1] + 1),
lambda x, y: (x[0] + y[0], x[1] + y[1]))\
.map(lambda x: (x[0], float(x[1][0]) / float(x[1][1])))
You can also present this information in the form of plot. As a first step to create a plot, let us first create a
temporary table AverageTime. The table groups the logs by time to see if there were any unusual latency spikes at
any particular time. You can then use the %%sql command to be able to run the following SparkSQL query to get
all the records in the AverageTime table and to persist the output locally as a Pandas dataframe by adding the
-o averagetime parameter to the SQL query. Results will be as similiar to those shown in the screenshot below.
%%sql -o averagetime
SELECT * FROM AverageTime
You can now use Matplotlib , a library used to construct visualization of data, to create a plot. Because the plot
must be created from the locally persisted averagetime dataframe, the code snippet must begin with the %%local
magic. This ensures that the code is run locally on the Jupyter server. You'll see output as shown in the screenshot
below.
%%local
%matplotlib inline
import [Link] as plt
Next steps
In this article, you learned about the large number of scalable data pipeline scenario that are possible using Apache
Spark on HDInsight. You also saw a complete example running in a Jupyter PySpark notebook. The flexibility of
both HDInsight and the Spark ecosystem allow for building a wide variety of data pipelines that can address many
business needs.
For more information, see:
Introductions to Spark on HDInsight
Build Apache Spare machine learning applications on Azure HDInsight *Use Spark MlLib to build a machine
learning application and analyze a dataset
Use Spark with HDInsight
8/16/2017 • 10 min to read • Edit Online
Spark on HDInsight provides us with a unified framework for running large-scale data analytics applications that
capitalizes on an in-memory compute engine at its core, for high performance querying on big data. It leverages a
parallel data processing framework that persists data in-memory and disk if needed. This allows Spark to deliver
both 100x faster speed and a common execution model to various tasks like extract, transform, load (otherwise
known as ETL), batch, and interactive queries on data in Hadoop distributed file system (or, HDFS). One of the
advantages Spark's unified framework gives us, is the ability to use the same code for both batch processing and
realtime stream processing.
In the head node, we have the Spark master that manages the number of applications, the apps are mapped to the
Spark driver. Every app is managed by Spark master in various ways. Spark can be deployed on top of Mesos,
YARN, or the Spark cluster manager, which allocates worker node resources to an application. In HDInsight, Spark
runs using the YARN cluster manager. The resources in the cluster are managed by Spark master in HDInsight.
That means the Spark master has knowledge of which resources, like memory, are occupied or available on the
worker node.
The driver runs the user's main function and executes the various parallel operations on the worker nodes. Then,
the driver collects the results of the operations. The worker nodes read and write data from and to the Hadoop
distributed file system (HDFS). The worker nodes also cache transformed data in-memory as Resiliant Distributed
Datasets (RDDs).
Once the app is created in the Spark master, the resources are allocated to the apps by Spark master, creating an
execution called the Spark driver. The Spark driver basically creates the SparkContext. When it creates the
SparkContext, it starts creating the RDDs. The metadata of the RDDs are stored on the Spark driver.
The Spark driver connects to the Spark master and is responsible for converting an application to a directed graph
(DAG) of individual tasks that get executed within an executor process on the worker nodes. Each application gets
its own executor processes, which stay up for the duration of the whole application and run tasks in multiple
threads.
Spark provides primitives for in-memory cluster computing. A Spark job can load and cache data into memory
and query it repeatedly, much more quickly than disk-based systems. Spark also integrates into the Scala
programming language to let you manipulate distributed data sets like local collections. There's no need to
structure everything as map and reduce operations.
Data sharing between operations is faster, since data is in-memory. Hadoop shares data through HDFS, an
expensive option. It also maintains three replicas.
At its base, Spark Core is the engine that drives the distributed, large-scale parallel processing, memory
management/fault recovery, the scheduling, distribution, and monitoring of jobs on a cluster, and interaction with
the underlying storage system.
On top of Spark Core runs a compliment of higher-level libraries that can be seamlessly used in the same
application: Spark SQL, Spark Streaming, MLlib, and GraphX. This means that much of the work you perform to
execute batch processing on Spark can be reused for streaming data and other activities.
In this sample, we're using hdfs() and filter() transformations, and count() and collect() actions.
Notice that in the block of sample code, there are 4 comments:
Cache errors – Implementing the cache() method will collect all of the errors present.
Count all errors – Calling the count() action counts all the errors in the referenced data.
Count errors mentioning MySQL – When implementing this code, MySQL errors are counted with the count
action.
Fetch the MySQL errors as an array of strings – When implementing this code, MySQL errors are extracted
as an array of strings by way of the collect action.
RDD-supported transformations
TRANSFORMATION DESCRIPTION
sample(withReplacement, fraction, seed) Samples a fraction of the data, with or without replacement,
using a given random number generator seed.
union(otherDataset) Returns a new data set that contains the union of the
elements in the source data set and in the argument.
distinct(([numTasks])) Returns a new data set that contains the distinct elements of
the source data set.
groupBykey([numTasks]) When called on a data set of (K, V) pairs, returns a data set of
(K, Seq[V]) pairs.
reduceByKey(func, [numTasks]) When called on a data set of (K, V) pairs, returns a data set of
(K, V) pairs where the values for each key are aggregated
using the given reduce function.
sortByKey([ascending], [numTasks]) When called on a data set of (K, V) pairs where K implements
are ordered, returns a data set of (K, V) pairs sorted by keys in
ascending or descending order, as specified in the Boolean
ascending argument.
join(otherDataset,[numTasks]) When called on data sets of type (K, V) and (K, W), returns a
data set of (K, (V, W)) pairs with all pairs of elements for each
key.
cogroup(otherDataset, [numTasks]) When called on data sets of type (K, V) and (K, W), returns a
data set of (K, Seq[V], Seq[W]) tuples, also called groupWith.
cartesian(otherDataset) When called on data sets of types T and U, returns a data set
of (T, U) pairs (all pairs of elements).
RDD-supported actions
ACTION DESCRIPTION
saveAsTextFile(path) Writes the elements of the data set as a text file (or a set of
text files) in a given directory in either the local filesystem,
HDFS, or other Hadoop-supported file systems. Spark will call
ToString on each element to convert it to a line of text in the
file.
countByKey() Returns a “Map” of (K, Int) pairs with the count of each key.
Only available on RDDs of type (K, V).
foreach(func) Runs a function func on each element of the data set. Usually
done for side effects, such as updating an accumulator.
collect() Returns all the elements of the data set as an array at the
driver program. Usually useful after a filter or other operation
returns a sufficiently small subset of the data.
take(n) Returns an array with the first n elements of the data set.
Currently not executed in parallel, instead the driver program
computes all the elements.
takeSample (withReplacement, fraction, seed) Returns an array with a random sample of num elements of
the data set, with or without replacement, using the given
random number generator seed.
MEMORY_ONLY Stores RDD as deserialized Java objects in the JVM. If the RDD
does not fit in-memory, some partitions will not be cached
and will be recomputed on the fly each time they are needed.
This is the default level.
MEMORY_AND_DISK Stores RDD as deserialized Java objects in the JVM. If the RDD
does not fit in-memory, store the partitions that do not fit
on-disk, and read them from there when they are needed.
MEMORY_ONLY_SER Stores RDD as serialized Java objects (one byte array per
partition). This is generally more space-efficient than
deserialized objects, especially when using a fast serializer, but
it is more CPU-intensive to read.
MEMORY_ONLY_2, MEMORY_AND_DISK_2, and more Same as the levels above, but replicates each partition on two
cluster nodes.
Accumulators
Accumulators are variables that can only be added to through an associative operation. They are used to
implement counters and sums efficiently in parallel. Spark natively supports accumulators of numeric value types
and standard mutable collections. It is possible for programmers to extend for new types. One thing of note, only
the driver program can read the value of an accumulator; the tasks cannot. Tasks can only write to the
accumulator.
See also
Spark SQL with HDInsight
Spark Scenarios - Build high-speed scalable data pipelines
Optimizing and configuring Spark Jobs for performance
Configuring Spark settings
Submit remote batch jobs to an HDInsight Spark cluster.
Use Spark SQL with HDInsight
8/16/2017 • 5 min to read • Edit Online
SQL (Structured Query Language) is the most common and widely used language for querying and defining data.
Having been developed since the 1970s, and officially ANSI-standardized in 1986, SQL has had its foothold in the
industry long enough for data analysts to turn to it as a natural way think about breaking down complex problems
and define data relationships. The founders of Spark sought to harness this knowledge, opening up the well-
known data querying language to a wider audience of analysts who wish to work with data that lives on Hadoop
Distributed File System (HDFS).
Spark SQL is that offering. It functions as an extension to Apache Spark for processing structured data, using the
familiar SQL syntax. It has been part of the core distribution since Spark 1.0 (April 2014), and is a distributed SQL
query engine. It also functions as a general purpose distributed data processing API. It acn be used in conjunction
with the Spark core API within a single application.
To use Spark SQL, first create an Azure storage account, which HDInsight uses to store data within a blob
container. Alternately, you can use an Azure Data Lake Store account. Next, HDInsight will make Apache Spark
available as a service in the cloud. Using this service, we can run Spark SQL statements against our stored data by
using notebooks.
import [Link]
SparkSession is new to Spark 2.0. In earlier versions, you have the choice between a SQLContext and a
HiveContext . These two older contexts are kept for backward compatibility.
Through certain DataFrame operations, you can use SQLContext to understand the construction and
demographics of your data.
OPTION DESCRIPTION
[Link]() This operation shows the contents of the data you have
selected
[Link](“name”).show() This operation will select and display the name you have
selected for the columns you’ve specified
[Link](dr(“name”),df(“age”) + 1).show() This operation example will select all your data as well as add
one to each of the ages shown
[Link](df(“age”) > [Link]() This operation example will select all data that shows that the
data is greater than 21
OPTION DESCRIPTION
[Link](“age”).count().show() This operation example will count the data you’ve selected by
age and show you only the results that meet the criteria
you’ve presented
See also
Spark with HDInsight
Spark Scenarios - Build high-speed scalable data pipelines
Optimizing and configuring Spark Jobs for performance
Configuring Spark settings
Run Spark from the Shell
8/15/2017 • 2 min to read • Edit Online
To run Spark interactively, you can use the Spark Shell. This is useful for development and debugging. There are
shells for each language supported by Spark, but they all provide the same capability- a REPL (read, execute, print
loop) environment for running Spark commands one at a time and viewing the results.
ssh <sshusername>@<clustername>-[Link]
You can get easily retrieve the complete command for your cluster, from the Azure Portal by following these steps:
1. Log into the Azure Portal.
2. Navigate to the blade for your HDInsight Spark cluster.
3. Select Secure Shell (SSH).
4. Copy the provided SSH commmand and run it in the terminal of your choice.
For details on using SSH to connect to HDInsight, see Use SSH with HDInsight
./bin/spark-shell
./bin/pyspark
./bin/sparkR
spark
sc
Next Steps
This article covered how to run the various Spark Shells available to each language support by Spark.
See Use Spark with HDInsight for an overview of using Spark with HDInsight.
Read Use Spark SQL with HDInsight to understand how to write applications that use DataFrames from
SparkSQL.
Review What is Spark Structured Streaming? to learn how to write application to process streaming data with
Spark.
Use Zeppelin notebooks with Apache Spark cluster
on Azure HDInsight
8/16/2017 • 6 min to read • Edit Online
HDInsight Spark clusters include Zeppelin notebooks that you can use to run Spark jobs. In this article, you learn
how to use the Zeppelin notebook on an HDInsight cluster.
NOTE
Zeppelin notebooks are available only for Spark 1.6.3 on HDInsight 3.5 and Spark 2.1.0 on HDInsight 3.6.
Prerequisites:
An Azure subscription. See Get Azure free trial.
An Apache Spark cluster on HDInsight. For instructions, see Create Apache Spark clusters in Azure HDInsight.
NOTE
You may also reach the Zeppelin Notebook for your cluster by opening the following URL in your browser. Replace
CLUSTERNAME with the name of your cluster:
[Link]
2. Create a new notebook. From the header pane, click Notebook, and then click Create New Note.
Enter a name for the notebook, and then click Create Note.
3. Also, make sure the notebook header shows a connected status. It is denoted by a green dot in the top-right
corner.
4. Load sample data into a temporary table. When you create a Spark cluster in HDInsight, the sample data
file, [Link], is copied to the associated storage account under \HdiSamples\SensorSampleData\hvac.
In the empty paragraph that is created by default in the new notebook, paste the following snippet.
%[Link]
//The above magic instructs Zeppelin to use the Livy Scala interpreter
// Define a schema
case class Hvac(date: String, time: String, targettemp: Integer, actualtemp: Integer, buildingID:
String)
Press SHIFT + ENTER or click the Play button for the paragraph to run the snippet. The status on the right-
corner of the paragraph should progress from READY, PENDING, RUNNING to FINISHED. The output
shows up at the bottom of the same paragraph. The screenshot looks like the following:
You can also provide a title to each paragraph. From the right-hand corner, click the Settings icon, and
then click Show title.
5. You can now run Spark SQL statements on the hvac table. Paste the following query in a new paragraph.
The query retrieves the building ID and the difference between the target and actual temperatures for each
building on a given date. Press SHIFT + ENTER.
%sql
select buildingID, (targettemp - actualtemp) as temp_diff, date from hvac where date = "6/1/13"
The %sql statement at the beginning tells the notebook to use the Livy Scala interpreter.
The following screenshot shows the output.
Click the display options (highlighted in rectangle) to switch between different representations for the same
output. Click Settings to choose what consitutes the key and values in the output. The screen capture
above uses buildingID as the key and the average of temp_diff as the value.
6. You can also run Spark SQL statements using variables in the query. The next snippet shows how to define
a variable, Temp, in the query with the possible values you want to query with. When you first run the
query, a drop-down is automatically populated with the values you specified for the variable.
%sql
select buildingID, date, targettemp, (targettemp - actualtemp) as temp_diff from hvac where targettemp
> "${Temp = 65,65|75|85}"
Paste this snippet in a new paragraph and press SHIFT + ENTER. The following screenshot shows the
output.
For subsequent queries, you can select a new value from the drop-down and run the query again. Click
Settings to choose what consitutes the key and values in the output. The screen capture above uses
buildingID as the key, the average of temp_diff as the value, and targettemp as the group.
7. Restart the Livy interpreter to exit the application. To do so, open interpreter settings by clicking the logged
in user name from the top-right corner, and then click Interpreter.
3. Add a new key, called [Link] and set its value in the format group:id:version . So, if you
want to use the spark-csv package, you must set the value of the key to
[Link]:spark-csv_2.10:1.4.0 .
[Link]:spark-csv_2.10:1.4.0
Where are the Zeppelin notebooks saved?
The Zeppelin notebooks are saved to the cluster headnodes. So, if you delete the cluster, the notebooks will be
deleted as well. If you want to preserve your notebooks for later use on other clusters, you must export them after
you have finished running the jobs. To export a notebook, click the Export icon as shown in the image below.
3. Run a code cell from an existing Zeppelin notebook. This creates a new Livy session in the HDInsight cluster.
See also
Overview: Apache Spark on Azure HDInsight
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Website log analysis using Spark in HDInsight
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use HDInsight Tools Plugin for IntelliJ IDEA to create and submit Spark Scala applicatons
Use HDInsight Tools Plugin for IntelliJ IDEA to debug Spark applications remotely
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Use external packages with Jupyter notebooks
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Kernels for Jupyter notebook on Spark clusters in
Azure HDInsight
8/16/2017 • 8 min to read • Edit Online
HDInsight Spark clusters provide kernels that you can use with the Jupyter notebook on Spark for testing your
applications. A kernel is a program that runs and interprets your code. The three kernels are:
PySpark - for applications written in Python2
PySpark3 - for applications written in Python3
Spark - for applications written in Scala
In this article, you learn how to use these kernels and the benefits of using them.
Prerequisites
An Apache Spark cluster in HDInsight. For instructions, see Create Apache Spark clusters in Azure HDInsight.
3. Click Jupyter Notebook. If prompted, enter the admin credentials for the cluster.
NOTE
You may also reach the Jupyter notebook on Spark cluster by opening the following URL in your browser. Replace
CLUSTERNAME with the name of your cluster:
[Link]
4. Click New, and then click either Pyspark, PySpark3, or Spark to create a notebook. Use the Spark kernel
for Scala applications, PySpark kernel for Python2 applications, and PySpark3 kernel for Python3
applications.
5. A notebook opens with the kernel you selected.
NOTE
In addition to the magics added by the PySpark kernel, you can also use the built-in IPython magics, including
%%sh . You can use the %%sh magic to run scripts and block of code on the cluster headnode.
Auto visualization. The Pyspark kernel automatically visualizes the output of Hive and SQL queries. You can
choose between several different types of visualizations including Table, Pie, Line, Area, Bar.
Example:
hdfs dfs -ls /HdiNotebooks # List everything at the root directory – everything
in this directory is visible to Jupyter from the home page
hdfs dfs –copyToLocal /HdiNotebooks # Download the contents of the HdiNotebooks folder
hdfs dfs –copyFromLocal [Link] /HdiNotebooks # Upload a notebook [Link] to the root folder so
it’s visible from Jupyter
In case there are issues accessing the storage account for the cluster, the notebooks are also saved on the
headnode /var/lib/jupyter .
Supported browser
Jupyter notebooks on Spark HDInsight clusters are supported only on Google Chrome.
Feedback
The new kernels are in evolving stage and will mature over time. This could also mean that APIs could change as
these kernels mature. We would appreciate any feedback that you have while using these new kernels. This is
useful in shaping the final release of these kernels. You can leave your comments/feedback under the Comments
section at the bottom of this article.
See also
Overview: Apache Spark on Azure HDInsight
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Website log analysis using Spark in HDInsight
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use HDInsight Tools Plugin for IntelliJ IDEA to create and submit Spark Scala applications
Use HDInsight Tools Plugin for IntelliJ IDEA to debug Spark applications remotely
Use Zeppelin notebooks with a Spark cluster on HDInsight
Use external packages with Jupyter notebooks
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Use external packages with Jupyter notebooks in
Apache Spark clusters on HDInsight
8/16/2017 • 3 min to read • Edit Online
Learn how to configure a Jupyter notebook in Apache Spark cluster on HDInsight to use external, community-
contributed maven packages that are not included out-of-the-box in the cluster.
You can search the Maven repository for the complete list of packages that are available. You can also get a list of
available packages from other sources. For example, a complete list of community-contributed packages is
available at Spark Packages.
In this article, you will learn how to use the spark-csv package with the Jupyter notebook.
Prerequisites
You must have the following:
An Apache Spark cluster on HDInsight. For instructions, see Create Apache Spark clusters in Azure HDInsight.
NOTE
You may also reach the Jupyter Notebook for your cluster by opening the following URL in your browser. Replace
CLUSTERNAME with the name of your cluster:
[Link]
4. A new notebook is created and opened with the name [Link]. Click the notebook name at the top,
and enter a friendly name.
5. You will use the %%configure magic to configure the notebook to use an external package. In notebooks
that use external packages, make sure you call the %%configure magic in the first code cell. This ensures
that the kernel is configured to use the package before the session starts.
IMPORTANT
If you forget to configure the kernel in the first cell, you can use the %%configure with the -f parameter, but
that will restart the session and all progress will be lost.
6. The snippet above expects the maven coordinates for the external package in Maven Central Repository. In
this snippet, [Link]:spark-csv_2.10:1.4.0 is the maven coordinate for spark-csv package. Here's
how you construct the coordinates for a package.
a. Locate the package in the Maven Repository. For this tutorial, we use spark-csv.
b. From the repository, gather the values for GroupId, ArtifactId, and Version. Make sure that the values
you gather match your cluster. In this case, we are using a Scala 2.10 and Spark 1.4.0 package, but you may
need to select different versions for the appropriate Scala or Spark version in your cluster. You can find out
the Scala version on your cluster by running [Link] on the Spark Jupyter
kernel or on Spark submit. You can find out the Spark version on your cluster by running [Link] on
Jupyter notebooks.
[Link]:spark-csv_2.10:1.4.0
7. Run the code cell with the %%configure magic. This will configure the underlying Livy session to use the
package you provided. In the subsequent cells in the notebook, you can now use the package, as shown
below.
val df = [Link]("[Link]").
option("header", "true").
option("inferSchema", "true").
load("wasb:///HdiSamples/HdiSamples/SensorSampleData/hvac/[Link]")
8. You can then run the snippets, like shown below, to view the data from the dataframe you created in the
previous step.
[Link]()
[Link]("Time").count()
See also
Overview: Apache Spark on Azure HDInsight
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Website log analysis using Spark in HDInsight
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use external python packages with Jupyter notebooks in Apache Spark clusters on HDInsight Linux
Use HDInsight Tools Plugin for IntelliJ IDEA to create and submit Spark Scala applications
Use HDInsight Tools Plugin for IntelliJ IDEA to debug Spark applications remotely
Use Zeppelin notebooks with a Spark cluster on HDInsight
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Use Script Action to install external Python packages
for Jupyter notebooks in Apache Spark clusters on
HDInsight
8/16/2017 • 2 min to read • Edit Online
Learn how to use Script Actions to configure an Apache Spark cluster on HDInsight (Linux) to use external,
community-contributed python packages that are not included out-of-the-box in the cluster.
NOTE
You can also configure a Jupyter notebook by using %%configure magic to use external packages. For instructions, see Use
external packages with Jupyter notebooks in Apache Spark clusters on HDInsight.
You can search the package index for the complete list of packages that are available. You can also get a list of
available packages from other sources. For example, you can install packages made available through Anaconda or
conda-forge.
In this article, you will learn how to install the TensorFlow package using Script Actoin on your cluster and use it
via the Jupyter notebook.
Prerequisites
You must have the following:
An Azure subscription. See Get Azure free trial.
An Apache Spark cluster on HDInsight. For instructions, see Create Apache Spark clusters in Azure
HDInsight.
NOTE
If you do not already have a Spark cluster on HDInsight Linux, you can run script actions during cluster creation. Visit
the documentation on how to use custom script actions.
4. A new notebook is created and opened with the name [Link]. Click the notebook name at the top,
and enter a friendly name.
5. You will now import tensorflow and run a hello world example.
Code to copy:
import tensorflow as tf
hello = [Link]('Hello, TensorFlow!')
sess = [Link]()
print([Link](hello))
See also
Overview: Apache Spark on Azure HDInsight
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Website log analysis using Spark in HDInsight
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use external packages with Jupyter notebooks in Apache Spark clusters on HDInsight
Use HDInsight Tools Plugin for IntelliJ IDEA to create and submit Spark Scala applications
Use HDInsight Tools Plugin for IntelliJ IDEA to debug Spark applications remotely
Use Zeppelin notebooks with a Spark cluster on HDInsight
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Use Azure Toolkit for IntelliJ to create Spark
applications for HDInsight cluster
8/16/2017 • 10 min to read • Edit Online
Use the Azure Toolkit for IntelliJ plug-in to develop Spark applications written in Scala and submit them to an
HDInsight Spark cluster, directly from the IntelliJ IDE. You can use the plug-in in a few different ways:
To develop and submit a Scala Spark application on an HDInsight Spark cluster
To access your Azure HDInsight Spark cluster resources
To develop and run a Scala Spark application locally
You can follow a video to create your project.
IMPORTANT
This plug-in can be used to create and submit applications only for an HDInsight Spark cluster on Linux.
Prerequisites
An Apache Spark cluster on HDInsight Linux. For instructions, see Create Apache Spark clusters in Azure
HDInsight.
Oracle Java Development Kit. You can install it from the Oracle website.
IntelliJ IDEA. This article uses version 2017.1. You can install it from the JetBrains website.
4. After you're signed in, the Select Subscriptions dialog box lists all the Azure subscriptions associated with
the credentials. Click Select to close the dialog box.
5. On the Azure Explorer tab, expand HDInsight to see the HDInsight Spark clusters under your
subscription.
6. You can further expand a cluster name node to see the resources (for example, storage accounts)
associated with the cluster.
Run a Spark Scala application on an HDInsight Spark cluster
1. Start IntelliJ IDEA and create a project. In the New Project dialog box, make the following choices, and then
click Next.
3. Click OK to download the Scala plugin. Follow the instructions to restart IntelliJ.
4. In the next window, provide the following project details, and then click Finish.
b. In the Create New Scala Class dialog box, provide a name, select Object in the Kind box, and then
click OK.
c. In the [Link] file, paste the following code. This code reads the data from [Link]
(available on all HDInsight Spark clusters), retrieves the rows that have only one digit in the seventh
column in the CSV file, and writes the output to /HVACOut under the default storage container for
the cluster.
import [Link]
import [Link]
object MyClusterApp{
def main (arg: Array[String]): Unit = {
val conf = new SparkConf().setAppName("MyClusterApp")
val sc = new SparkContext(conf)
//find the rows that have only one digit in the seventh column in the CSV file
val rdd1 = [Link](s => [Link](",")(6).length() == 1)
[Link]("wasb:///HVACOut")
}
b. You are prompted to enter your Azure subscription credentials. In the Spark Submission dialog
box, provide the following values, and then click Submit.
For Spark clusters (Linux only), select the HDInsight Spark cluster on which you want to run
your application.
Select an artifact from the IntelliJ project, or select one from the hard drive.
In the Main class name box, click the ellipsis ( ), select the main class in your application
source code, and then click OK.
Because the application code in this example does not require any command-line arguments
or reference JARs or files, you can leave the remaining boxes empty. After you provide all the
inputs, the dialog box should resemble the following image.
c. The Spark Submission tab at the bottom of the window should start displaying the progress. You
can also stop the application by clicking the red button in the Spark Submission window.
In the "Access and manage HDInsight Spark clusters by using Azure Toolkit for IntelliJ" section later
in this article, you'll learn how to access the job output.
2. In the right pane, the Spark Job View tab displays all the applications that were run on the cluster. Click the
name of the application for which you want to see more details.
3. Hover on job graph, it displays basic running job info. Click on job graph, you can see the stages graph and
info which every job generates.
4. Frequently-used log including Driver Stderr, Driver Stdout, Directory Info are listed in Log tab.
5. You can also open the Spark history UI and the YARN UI (at the application level) by clicking the respective
hyperlink at the top of the window.
Access the Spark history server
1. In Azure Explorer, expand HDInsight, right-click your Spark cluster name, and then select Open Spark
History UI. When you're prompted, enter the admin credentials for the cluster. You must have specified these
while provisioning the cluster.
2. In the Spark history server dashboard, you can use the application name to look for the application that you
just finished running. In the preceding code, you set the application name by using
val conf = new SparkConf().setAppName("MyClusterApp") . Hence, your Spark application name was
MyClusterApp.
Start the Ambari portal
1. In Azure Explorer, expand HDInsight, right-click your Spark cluster name, and then select Open Cluster
Management Portal (Ambari).
2. When you're prompted, enter the admin credentials for the cluster. You specified these credentials during the
cluster provisioning process.
Manage Azure subscriptions
By default, Azure Toolkit for IntelliJ lists the Spark clusters from all your Azure subscriptions. If necessary, you can
specify the subscriptions for which you want to access the cluster.
1. In Azure Explorer, right-click the Azure root node, and then click Manage Subscriptions.
2. In the dialog box, clear the check boxes for the subscription that you don't want to access, and then click Close.
You can also click Sign Out if you want to sign out of your Azure subscription.
Run a Spark Scala application locally
You can use Azure Toolkit for IntelliJ to run Spark Scala applications locally on your workstation. Typically, these
applications don't need access to cluster resources such as a storage container, and you can run and test them
locally.
Prerequisite
While you're running the local Spark Scala application on a Windows computer, you might get an exception as
explained in SPARK-2356. This exception occurs because [Link] is missing on Windows.
To resolve this error, you must download the executable to a location like C:\WinUtils\bin. Then, add the
environment variable HADOOP_HOME and set the value of the variable to C\WinUtils.
Run a local Spark Scala application
1. Start IntelliJ IDEA and create a project. In the New Project dialog box, make the following choices, and
then click Next.
In the left pane, select HDInsight.
In the right pane, select Spark on HDInsight Local Run Sample (Scala).
Build tool: Scala project creation wizard support Maven or SBT managing the dependencies and
building for scala project. You select one according need.
2. In the next window, provide the following project details, and then click Finish.
Provide a project name and project location.
For Project SDK, make sure that you provide a Java version later than 7.
For Spark Version, select the version of Scala to use: Scala 2.11.x for Spark 2.0, and Scala 2.10.x for
Spark 1.6.
3. The template adds a sample code (LogQuery) under the src folder that you can run locally on your
computer.
4. Right-click the LogQuery application, and then click Run 'LogQuery'. On the Run tab at the bottom, you
see an output like the following.
Edit the element to add UniqueKey="HDInsightTool" so that the module element looks like the following:
3. Save the changes. Your application should now be compatible with Azure Toolkit for IntelliJ. You can test it by
right-clicking the project name in Project Explorer. The pop-up menu now has the option Submit Spark
Application to HDInsight.
Troubleshooting
"Please use a larger heap size" error in local run
In Spark 1.6, if you're using a 32-bit Java SDK during local run, you might encounter the following errors:
These errors happen because the heap size is not large enough for Spark to run. (Spark requires at least 471 MB.
You can get more details from SPARK-12081). One simple solution is to use a 64-bit Java SDK. You can also
change the JVM settings in IntelliJ by adding the following options:
See also
Overview: Apache Spark on Azure HDInsight
Demo
Create Scala Project (Video): Create Spark Scala Applications
Remote Debug (Video): Use Azure Toolkit for IntelliJ to debug Spark applications remotely on HDInsight
Cluster
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Website log analysis using Spark in HDInsight
Creating and running applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use Azure Toolkit for IntelliJ to debug Spark applications remotely through VPN
Use Azure Toolkit for IntelliJ to debug Spark applications remotely through SSH
Use HDInsight Tools for IntelliJ with Hortonworks Sandbox
Use HDInsight Tools in Azure Toolkit for Eclipse to create Spark applications
Use Zeppelin notebooks with a Spark cluster on HDInsight
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Use external packages with Jupyter notebooks
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Managing resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Use Azure Toolkit for IntelliJ to debug applications
remotely on HDInsight Spark through VPN
8/16/2017 • 9 min to read • Edit Online
We recommend the way of debugging spark applicaltion remotely through ssh. For instructions, see Remotely
debug Spark applications on an HDInsight cluster with Azure Toolkit for IntelliJ through SSH.
This article provides step-by-step guidance on how to use the HDInsight Tools in Azure Toolkit for IntelliJ to
submit a Spark job on HDInsight Spark cluster and then debug it remotely from your desktop computer. To do so,
you must perform the following high-level steps:
1. Create a site-to-site or point-to-site Azure Virtual Network. The steps in this document assume that you use a
site-to-site network.
2. Create a Spark cluster in Azure HDInsight that is part of the site-to-site Azure Virtual Network.
3. Verify the connectivity between the cluster headnode and your desktop.
4. Create a Scala application in IntelliJ IDEA and configure it for remote debugging.
5. Run and debug the application.
Prerequisites
An Azure subscription. See Get Azure free trial.
An Apache Spark cluster on HDInsight. For instructions, see Create Apache Spark clusters in Azure HDInsight.
Oracle Java Development kit. You can install it from here.
IntelliJ IDEA. This article uses version 2017.1. You can install it from here.
HDInsight Tools in Azure Toolkit for IntelliJ. HDInsight tools for IntelliJ are available as part of the Azure Toolkit
for IntelliJ. For instructions on how to install the Azure Toolkit, see Installing the Azure Toolkit for IntelliJ.
Log into your Azure Subscription from IntelliJ IDEA. Follow the instructions here.
While running Spark Scala application for remote debugging on a Windows computer, you might get an
exception as explained in SPARK-2356 that occurs due to a missing [Link] on Windows. To work around
this error, you must download the executable from here to a location like C:\WinUtils\bin. You must then add
an environment variable HADOOP_HOME and set the value of the variable to C\WinUtils.
Step 3: Verify the connectivity between the cluster headnode and your
desktop
1. Get the IP address of the headnode. Open Ambari UI for the cluster. From the cluster blade, click
Dashboard.
2. From the Ambari UI, from the top-right corner, click Hosts.
3. You should see a list of headnodes, worker nodes, and zookeeper nodes. The headnodes have the hn*
prefix. Click the first headnode.
4. At the bottom of the page that opens, from the Summary box, copy the IP address of the headnode and
the host name.
5. Include the IP address and the host name of the headnode to the hosts file on the computer from where
you want to run and remotely debug the Spark jobs. This will enable you to communicate with the
headnode using the IP address as well as the hostname.
a. Open a notepad with elevated permissions. From the file menu, click Open and then navigate to the
location of the hosts file. On a Windows computer, it is C:\Windows\System32\Drivers\etc\hosts .
b. Add the following to the hosts file.
# For headnode0
[Link] hn0-nitinp
[Link] [Link]
# For headnode1
[Link] hn1-nitinp
[Link] [Link]
6. From the computer that you connected to the Azure Virtual Network that is used by the HDInsight cluster,
verify that you can ping both the headnodes using the IP address as well as the hostname.
7. SSH into the cluster headnode using the instructions at Connect to an HDInsight cluster using SSH. From the
cluster headnode, ping the IP address of the desktop computer. You should test connectivity to both the IP
addresses assigned to the computer, one for the network connection and the other for the Azure Virtual
Network that the computer is connected to.
8. Repeat the steps for the other headnode as well.
You can also create your own artifact bly clicking on the + icon, highlighted in the image above.
4. Add libraries to your project. To add a library, right-click the project name in the project tree, and then click
Open Module Settings. In the Project Structure dialog box, from the left pane, click Libraries, click the
(+) symbol, and then click From Maven.
In the Download Library from Maven Repository dialog box, search and add the following libraries.
[Link]:scalatest_2.10:2.2.1
[Link]:hadoop-azure:2.7.1
5. Copy [Link] and [Link] from the cluster headnode and add it to the project. Use the
following commands to copy the files. You can use Cygwin to run the following scp commands to copy
the files from the cluster headnodes.
Because we already added the cluster headnode IP address and hostnames fo the hosts file on the desktop,
we can use the scp commands in the following manner.
scp sshuser@hn0-nitinp:/etc/hadoop/conf/[Link] .
scp sshuser@hn0-nitinp:/etc/hadoop/conf/[Link] .
Add these files to your project by copying them under the /src folder in your project tree, for example
<your project directory>\src .
<property>
<name>[Link]</name>
<value>access-key-associated-with-the-account</value>
</property>
<property>
<name>[Link]</name>
<value>/usr/lib/python2.7/dist-packages/hdinsight_common/[Link]</value>
</property>
<property>
<name>[Link]</name>
<value>/etc/hadoop/conf/topology_script.py</value>
</property>
8. In the Create New Scala Class dialog box, provide a name, for Kind select Object, and then click OK.
9. In the [Link] file, paste the following code. This code creates the Spark context and
launches an executeJob method from the SparkSample object.
object SparkSampleMain {
def main (arg: Array[String]): Unit = {
val conf = new SparkConf().setAppName("SparkSample")
.set("[Link]", "false")
val sc = new SparkContext(conf)
[Link](sc,
"wasb:///HdiSamples/HdiSamples/SensorSampleData/hvac/[Link]",
"wasb:///HVACOut")
}
}
10. Repeat steps 8 and 9 above to add a new Scala object called SparkSample . To this class add the following
code. This code reads the data from the [Link] (available on all HDInsight Spark clusters), retrieves the
rows that only have one digit in the seventh column in the CSV, and writes the output to /HVACOut under
the default storage container for the cluster.
import [Link]
object SparkSample {
def executeJob (sc: SparkContext, input: String, output: String): Unit = {
val rdd = [Link](input)
//find the rows which have only one digit in the 7th column in the CSV
val rdd1 = [Link](s => [Link](",")(6).length() == 1)
val s = [Link]([Link](5)).cartesian(rdd).count()
println(s)
[Link](output)
//[Link]().foreach(println)
}
}
11. Repeat steps 8 and 9 above to add a new class called RemoteClusterDebugging . This class implements the
Spark test framework that is used for debugging applications. Add the following code to the
RemoteClusterDebugging class.
test("Remote run") {
val conf = new SparkConf().setAppName("SparkSample")
.setMaster("yarn-client")
.set("[Link]", "-[Link]=2.4")
.set("[Link]", "wasb:///hdp/apps/[Link]-258/spark-assembly-
[Link].[Link]")
.setJars(Seq("""C:\workspace\IdeaProjects\MyClusterApp\out\artifacts\MyClusterApp_DefaultArtifact\defa
ult_artifact.jar"""))
.set("[Link]", "false")
val sc = new SparkContext(conf)
[Link](sc,
"wasb:///HdiSamples/HdiSamples/SensorSampleData/hvac/[Link]",
"wasb:///HVACOut")
}
}
2. Click the Debug Run button next to the Remote Run configuration drop-down to start running the
application.
3. When the program execution reaches the breakpoint, you should see a Debugger tab in the bottom pane.
4. Click the (+) icon to add a watch as shown in the image below.
Here, because the application broke before the variable rdd1 was created, using this watch we can see
what are the first 5 rows in the variable rdd . Press ENTER.
What you see in the image above is that at runtime, you could query terrabytes of data and debug how
your application progresses. For example, in the output shown in the image above, you can see that the
first row of the output is a header. Based on this, you can modify your application code to skip the header
row if required.
5. You can now click the Resume Program icon to proceed with your application run.
6. If the application completes successfully, you should see an output like the following.
See also
Overview: Apache Spark on Azure HDInsight
Demo
Create Scala Project (Video): Create Spark Scala Applications
Remote Debug (Video): Use Azure Toolkit for IntelliJ to debug Spark applications remotely on HDInsight
Cluster
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Website log analysis using Spark in HDInsight
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use HDInsight Tools in Azure Toolkit for IntelliJ to create and submit Spark Scala applicatons
Use Azure Toolkit for IntelliJ to debug Spark applications remotely through SSH
Use HDInsight Tools for IntelliJ with Hortonworks Sandbox
Use HDInsight Tools in Azure Toolkit for Eclipse to create Spark applications
Use Zeppelin notebooks with a Spark cluster on HDInsight
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Use external packages with Jupyter notebooks
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Analyze Application Insights telemetry logs with
Spark on HDInsight
8/16/2017 • 12 min to read • Edit Online
Learn how to use Spark on HDInsight to analyze Application Insight telemetry data.
Visual Studio Application Insights is an analytics service that monitors your web applications. Telemetry data
generated by Application Insights can be exported to Azure Storage. Once the data is in Azure Storage, HDInsight
can be used to analyze it.
Prerequisites
An application that is configured to use Application Insights.
Familiarity with creating a Linux-based HDInsight cluster. For more information, see Create Spark on
HDInsight.
IMPORTANT
The steps in this document require an HDInsight cluster that uses Linux. Linux is the only operating system used on
HDInsight version 3.4 or greater. For more information, see HDInsight retirement on Windows.
A web browser.
The following resources were used in developing and testing this document:
Application Insights telemetry data was generated using a [Link] web app configured to use Application
Insights.
A Linux-based Spark on HDInsight cluster version 3.5 was used to analyze the data.
Azure storage
Application Insights can be configured to continuously export telemetry information to blobs. HDInsight can then
read data stored in the blobs. However, there are some requirements that you must follow:
Location: If the Storage Account and HDInsight are in different locations, it may increase latency. It also
increases cost, as egress charges are applied to data moving between regions.
WARNING
Using a Storage Account in a different location than HDInsight is not supported.
Blob type: HDInsight only supports block blobs. Application Insights defaults to using block blobs, so should
work by default with HDInsight.
For information on adding additional storage to an existing HDInsight cluster, see the Add additional storage
accounts document.
Data schema
Application Insights provides export data model information for the telemetry data format exported to blobs. The
steps in this document use Spark SQL to work with the data. Spark SQL can automatically generate a schema for
the JSON data structure logged by Application Insights.
2. In the upper right corner of the Jupyter page, select New, and then PySpark. A new browser tab containing
a Python-based Jupyter Notebook opens.
3. In the first field (called a cell) on the page, enter the following text:
sc._jsc.hadoopConfiguration().set('[Link]', 'true')
This code configures Spark to recursively access the directory structure for the input data. Application
Insights telemetry is logged to a directory structure similar to the /{telemetry type}/YYYY-MM-DD/{##}/ .
4. Use SHIFT+ENTER to run the code. On the left side of the cell, an '*' appears between the brackets to
indicate that the code in this cell is being executed. Once it completes, the '*' changes to a number, and
output similar to the following text is displayed below the cell:
5. A new cell is created below the first one. Enter the following text in the new cell. Replace CONTAINER and
STORAGEACCOUNT with the Azure storage account name and blob container name that contains Application
Insights data.
%%bash
hdfs dfs -ls wasb://CONTAINER@[Link]/
Use SHIFT+ENTER to execute this cell. You see a result similar to the following text:
Found 1 items
drwxrwxrwx - 0 1970-01-01 00:00
wasb://appinsights@[Link]/contosoappinsights_2bededa61bc741fbdee6b556571a483
1
The wasb path returned is the location of the Application Insights telemetry data. Change the hdfs dfs -ls
line in the cell to use the wasb path returned, and then use SHIFT+ENTER to run the cell again. This time, the
results should display the directories that contain telemetry data.
NOTE
For the remainder of the steps in this section, the
wasb://appinsights@[Link]/contosoappinsights_{ID}/Requests directory was
used. Your directory structure may be different.
6. In the next cell, enter the following code: Replace WASB_PATH with the path from the previous step.
jsonFiles = [Link]('WASB_PATH')
jsonData = [Link](jsonFiles)
This code creates a dataframe from the JSON files exported by the continuous export process. Use
SHIFT+ENTER to run this cell.
7. In the next cell, enter and run the following to view the schema that Spark created for the JSON files:
[Link]()
The schema for each type of telemetry is different. The following example is the schema that is generated for
web requests (data stored in the Requests subdirectory):
root
|-- context: struct (nullable = true)
| |-- application: struct (nullable = true)
| | |-- version: string (nullable = true)
| |-- custom: struct (nullable = true)
| | |-- dimensions: array (nullable = true)
| | | |-- element: string (containsNull = true)
| | |-- metrics: array (nullable = true)
| | | |-- element: string (containsNull = true)
| |-- data: struct (nullable = true)
| | |-- eventTime: string (nullable = true)
| | |-- isSynthetic: boolean (nullable = true)
| | |-- samplingRate: double (nullable = true)
| | |-- syntheticSource: string (nullable = true)
| |-- device: struct (nullable = true)
| | |-- browser: string (nullable = true)
| | |-- browserVersion: string (nullable = true)
| | |-- deviceModel: string (nullable = true)
| | |-- deviceName: string (nullable = true)
| | |-- id: string (nullable = true)
| | |-- osVersion: string (nullable = true)
| | |-- type: string (nullable = true)
| |-- location: struct (nullable = true)
| | |-- city: string (nullable = true)
| | |-- clientip: string (nullable = true)
| | |-- continent: string (nullable = true)
| | |-- country: string (nullable = true)
| | |-- province: string (nullable = true)
| |-- operation: struct (nullable = true)
| | |-- name: string (nullable = true)
| |-- session: struct (nullable = true)
| | |-- id: string (nullable = true)
| | |-- isFirst: boolean (nullable = true)
| |-- user: struct (nullable = true)
| | |-- anonId: string (nullable = true)
| | |-- isAuthenticated: boolean (nullable = true)
|-- internal: struct (nullable = true)
| |-- data: struct (nullable = true)
| | |-- documentVersion: string (nullable = true)
| | |-- id: string (nullable = true)
|-- request: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- count: long (nullable = true)
| | |-- durationMetric: struct (nullable = true)
| | | |-- count: double (nullable = true)
| | | |-- max: double (nullable = true)
| | | |-- min: double (nullable = true)
| | | |-- sampledValue: double (nullable = true)
| | | |-- stdDev: double (nullable = true)
| | | |-- value: double (nullable = true)
| | |-- id: string (nullable = true)
| | |-- name: string (nullable = true)
| | |-- responseCode: long (nullable = true)
| | |-- success: boolean (nullable = true)
| | |-- url: string (nullable = true)
| | |-- urlData: struct (nullable = true)
| | | |-- base: string (nullable = true)
| | | |-- hashTag: string (nullable = true)
| | | |-- host: string (nullable = true)
| | | |-- protocol: string (nullable = true)
8. Use the following to register the dataframe as a temporary table and run a query against the data:
[Link]("requests")
df = [Link]("select [Link] from requests where [Link] is not
null")
[Link]()
This query returns the city information for the top 20 records where [Link] is not null.
NOTE
The context structure is present in all telemetry logged by Application Insights. The city element may not be
populated in your logs. Use the schema to identify other elements that you can query that may contain data for your
logs.
+---------+
| city|
+---------+
| Bellevue|
| Redmond|
| Seattle|
|Charlotte|
...
+---------+
2. In the upper right corner of the Jupyter page, select New, and then Scala. A new browser tab containing a
Scala-based Jupyter Notebook appears.
3. In the first field (called a cell) on the page, enter the following text:
[Link]("[Link]", "true")
This code configures Spark to recursively access the directory structure for the input data. Application
Insights telemetry is logged to a directory structure similar to /{telemetry type}/YYYY-MM-DD/{##}/ .
4. Use SHIFT+ENTER to run the code. On the left side of the cell, an '*' appears between the brackets to
indicate that the code in this cell is being executed. Once it completes, the '*' changes to a number, and
output similar to the following text is displayed below the cell:
5. A new cell is created below the first one. Enter the following text in the new cell. Replace CONTAINER and
STORAGEACCOUNT with the Azure storage account name and blob container name that contains Application
Insights logs.
%%bash
hdfs dfs -ls wasb://CONTAINER@[Link]/
Use SHIFT+ENTER to execute this cell. You see a result similar to the following text:
Found 1 items
drwxrwxrwx - 0 1970-01-01 00:00
wasb://appinsights@[Link]/contosoappinsights_2bededa61bc741fbdee6b556571a483
1
The wasb path returned is the location of the Application Insights telemetry data. Change the hdfs dfs -ls
line in the cell to use the wasb path returned, and then use SHIFT+ENTER to run the cell again. This time, the
results should display the directories that contain telemetry data.
NOTE
For the remainder of the steps in this section, the
wasb://appinsights@[Link]/contosoappinsights_{ID}/Requests directory was
used. This directory may not exist unless your telemetry data is for a web app.
6. In the next cell, enter the following code: Replace WASB\_PATH with the path from the previous step.
This code creates a dataframe from the JSON files exported by the continuous export process. Use
SHIFT+ENTER to run this cell.
7. In the next cell, enter and run the following to view the schema that Spark created for the JSON files:
[Link]
The schema for each type of telemetry is different. The following example is the schema that is generated for
web requests (data stored in the Requests subdirectory):
root
|-- context: struct (nullable = true)
| |-- application: struct (nullable = true)
| | |-- version: string (nullable = true)
| |-- custom: struct (nullable = true)
| | |-- dimensions: array (nullable = true)
| | | |-- element: string (containsNull = true)
| | |-- metrics: array (nullable = true)
| | | |-- element: string (containsNull = true)
| |-- data: struct (nullable = true)
| | |-- eventTime: string (nullable = true)
| | |-- isSynthetic: boolean (nullable = true)
| | |-- samplingRate: double (nullable = true)
| | |-- syntheticSource: string (nullable = true)
| |-- device: struct (nullable = true)
| | |-- browser: string (nullable = true)
| | |-- browserVersion: string (nullable = true)
| | |-- deviceModel: string (nullable = true)
| | |-- deviceName: string (nullable = true)
| | |-- id: string (nullable = true)
| | |-- osVersion: string (nullable = true)
| | |-- type: string (nullable = true)
| |-- location: struct (nullable = true)
| | |-- city: string (nullable = true)
| | |-- clientip: string (nullable = true)
| | |-- continent: string (nullable = true)
| | |-- country: string (nullable = true)
| | |-- province: string (nullable = true)
| |-- operation: struct (nullable = true)
| | |-- name: string (nullable = true)
| |-- session: struct (nullable = true)
| | |-- id: string (nullable = true)
| | |-- isFirst: boolean (nullable = true)
| |-- user: struct (nullable = true)
| | |-- anonId: string (nullable = true)
| | |-- isAuthenticated: boolean (nullable = true)
|-- internal: struct (nullable = true)
| |-- data: struct (nullable = true)
| | |-- documentVersion: string (nullable = true)
| | |-- id: string (nullable = true)
|-- request: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- count: long (nullable = true)
| | |-- durationMetric: struct (nullable = true)
| | | |-- count: double (nullable = true)
| | | |-- max: double (nullable = true)
| | | |-- min: double (nullable = true)
| | | |-- sampledValue: double (nullable = true)
| | | |-- stdDev: double (nullable = true)
| | | |-- value: double (nullable = true)
| | |-- id: string (nullable = true)
| | |-- name: string (nullable = true)
| | |-- responseCode: long (nullable = true)
| | |-- success: boolean (nullable = true)
| | |-- url: string (nullable = true)
| | |-- urlData: struct (nullable = true)
| | | |-- base: string (nullable = true)
| | | |-- hashTag: string (nullable = true)
| | | |-- host: string (nullable = true)
| | | |-- protocol: string (nullable = true)
8. Use the following to register the dataframe as a temporary table and run a query against the data:
[Link]("requests")
var city = [Link]("select [Link] from requests where [Link] is not
null limit 10").show()
This query returns the city information for the top 20 records where [Link] is not null.
NOTE
The context structure is present in all telemetry logged by Application Insights. The city element may not be
populated in your logs. Use the schema to identify other elements that you can query that may contain data for your
logs.
+---------+
| city|
+---------+
| Bellevue|
| Redmond|
| Seattle|
|Charlotte|
...
+---------+
Next steps
For more examples of using Spark to work with data and services in Azure, see the following documents:
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building streaming applications
Website log analysis using Spark in HDInsight
For information on creating and running Spark applications, see the following documents:
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Analyze website logs using a custom Python library
with Spark cluster on HDInsight
8/16/2017 • 7 min to read • Edit Online
This notebook demonstrates how to analyze log data using a custom library with Spark on HDInsight. The custom
library we use is a Python library called [Link].
TIP
This tutorial is also available as a Jupyter notebook on a Spark (Linux) cluster that you create in HDInsight. The notebook
experience lets you run the Python snippets from the notebook itself. To perform the tutorial from within a notebook,
create a Spark cluster, launch a Jupyter notebook ( [Link] ), and then run
the notebook Analyze logs with Spark using a custom [Link] under the PySpark folder.
Prerequisites:
You must have the following:
An Azure subscription. See Get Azure free trial.
An Apache Spark cluster on HDInsight. For instructions, see Create Apache Spark clusters in Azure
HDInsight.
NOTE
You may also reach the Jupyter Notebook for your cluster by opening the following URL in your browser. Replace
CLUSTERNAME with the name of your cluster:
[Link]
5. Because you created a notebook using the PySpark kernel, you do not need to create any contexts
explicitly. The Spark and Hive contexts will be automatically created for you when you run the first code
cell. You can start by importing the types that are required for this scenario. Paste the following snippet in
an empty cell, and then press SHIFT + ENTER.
6. Create an RDD using the sample log data already available on the cluster. You can access the data in the
default storage account associated with the cluster at
\HdiSamples\HdiSamples\WebsiteLogSampleData\SampleLog\[Link].
logs = [Link]('wasb:///HdiSamples/HdiSamples/WebsiteLogSampleData/SampleLog/[Link]')
7. Retrieve a sample log set to verify that the previous step completed successfully.
[Link](5)
[Link]('wasb:///HdiSamples/HdiSamples/WebsiteLogSampleData/[Link]')
2. iislogparser provides a function parse_log_line that returns None if a log line is a header row, and
returns an instance of the LogLine class if it encounters a log line. Use the LogLine class to extract only
the log lines from the RDD:
def parse_line(l):
import iislogparser
return iislogparser.parse_log_line(l)
logLines = [Link](parse_line).filter(lambda p: p is not None).cache()
3. Retrieve a couple of extracted log lines to verify that the step completed successfully.
[Link](2)
4. The LogLine class, in turn, has some useful methods, like is_error() , which returns whether a log entry
has an error code. Use this to compute the number of errors in the extracted log lines, and then log all the
errors to a different file.
# -----------------
# THIS IS AN OUTPUT
# -----------------
5. You can also use Matplotlib to construct a visualization of the data. For example, if you want to isolate the
cause of requests that run for a long time, you might want to find the files that take the most time to serve
on average. The snippet below retrieves the top 25 resources that took most time to serve a request.
def avgTimeTakenByKey(rdd):
return [Link](lambda line: (line.time_taken, 1),
lambda x, line: (x[0] + line.time_taken, x[1] + 1),
lambda x, y: (x[0] + y[0], x[1] + y[1]))\
.map(lambda x: (x[0], float(x[1][0]) / float(x[1][1])))
[(u'/blogposts/mvc4/[Link]', 197.5),
(u'/blogposts/mvc2/[Link]', 179.5),
(u'/blogposts/extractusercontrol/[Link]', 170.0),
(u'/blogposts/mvc4/[Link]', 159.0),
(u'/blogposts/mvcrouting/[Link]', 155.0),
(u'/blogposts/mvcrouting/[Link]', 152.0),
(u'/blogposts/linqsproc1/[Link]', 138.75),
(u'/blogposts/linqsproc1/[Link]', 137.33333333333334),
(u'/blogposts/vs2008javascript/[Link]', 127.0),
(u'/blogposts/nested/[Link]', 126.0),
(u'/blogposts/adminpack/[Link]', 124.0),
(u'/BlogPosts/datalistpaging/[Link]', 118.0),
(u'/blogposts/mvc4/[Link]', 117.0),
(u'/blogposts/mvcrouting/[Link]', 116.5),
(u'/blogposts/aboutme/[Link]', 109.0),
(u'/blogposts/anonymoustypes/[Link]', 109.0),
(u'/blogposts/mvc4/[Link]', 106.0),
(u'/blogposts/linq8/[Link]', 105.5),
(u'/blogposts/mvc2/[Link]', 104.0),
(u'/blogposts/mvc2/[Link]', 104.0),
(u'/blogposts/mvcrouting/[Link]', 104.0),
(u'/blogposts/extractusercontrol/[Link]', 103.0),
(u'/blogposts/sqlvideos/[Link]', 102.0),
(u'/blogposts/mvcrouting/[Link]', 101.0),
(u'/blogposts/mvc4/[Link]', 98.0)]
6. You can also present this information in the form of plot. As a first step to create a plot, let us first create a
temporary table AverageTime. The table groups the logs by time to see if there were any unusual latency
spikes at any particular time.
7. You can then run the following SQL query to get all the records in the AverageTime table.
%%sql -o averagetime
SELECT * FROM AverageTime
The %%sql magic followed by -o averagetime ensures that the output of the query is persisted locally on
the Jupyter server (typically the headnode of the cluster). The output is persisted as a Pandas dataframe
with the specified name averagetime.
You should see an output like the following:
For more information about the %%sql magic, see Parameters supported with the %%sql magic.
8. You can now use Matplotlib, a library used to construct visualization of data, to create a plot. Because the
plot must be created from the locally persisted averagetime dataframe, the code snippet must begin with
the %%local magic. This ensures that the code is run locally on the Jupyter server.
%%local
%matplotlib inline
import [Link] as plt
9. After you have finished running the application, you should shutdown the notebook to release the resources.
To do so, from the File menu on the notebook, click Close and Halt. This will shutdown and close the
notebook.
See also
Overview: Apache Spark on Azure HDInsight
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Spark Streaming: Use Spark in HDInsight for building real-time streaming applications
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use HDInsight Tools Plugin for IntelliJ IDEA to create and submit Spark Scala applications
Use HDInsight Tools Plugin for IntelliJ IDEA to debug Spark applications remotely
Use Zeppelin notebooks with a Spark cluster on HDInsight
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Use external packages with Jupyter notebooks
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Creating Spark ML Pipelines
8/16/2017 • 4 min to read • Edit Online
Overview
The Apache Spark [Link] package provides a uniform set of high-level APIs built on top of data frames that can
help you create and tune practical machine learning pipelines. MLlib is Spark's scalable machine learning library,
which brings modeling capabilities to this distributed environment. The moniker "Spark ML" is a term that refers to
the MLlib DataFrame-based API, as opposed to the older RDD-based pipeline API, which is now in maintenance
mode.
The primary function of an ML pipeline is to create a complete workflow by combining multiple machine learning
algorithms together. There are oftentimes many steps required to process and learn from data, which requires
applying a sequence of algorithms. Pipelines introduce a nice way to define the stages and order of your process.
The stages of a pipeline are represented by a sequence of PipelineStage s, where a Transformer and Estimator
perform tasks, and are executed in a specific order.
A Transformer is an algorithm that transforms one DataFrame to another by using the transform() method. For
example, a feature transformer could read a column of a DataFrame , map it to another column, and output a new
DataFrame with the mapped column appended to it.
Estimator s, an abstraction of learning algorithms, are responsible for fitting or training on a Dataset to produce a
Transformer. To do this, an Estimator implements a method called fit() , which accepts a DataFrame and
produces a Model , which is a Transformer .
Each stateless instance of a Transformer and Estimator has its own unique id, which can be used for specifying
parameters. Both use a uniform API for specifying these parameters.
Pipeline example
To demonstrate a practical use of an ML pipeline, we will use the sample [Link] data file that comes pre-loaded
on the Azure Storage or Data Lake Store configured as the default storage for your HDInsight cluster. To view the
contents of the file, navigate to the following location: /HdiSamples/HdiSamples/SensorSampleData/hvac.
We'll start out with a custom parser to extract the data ([Link]) we want to train our model. The function checks
whether the building is "hot" by comparing its actual temperature to the target temperature. We'll store the parsed
information wtihin a LabeledDocument , which stores the BuildingID , SystemInfo (comprising the system's Id and
age), and the label (1.0 if the building is not, 0.0 if not). The last step of this segment is to save the data into a new
DataFrame .
# List the structure of data for better understanding. Because the data will be
# loaded as an array, this structure makes it easy to understand what each element
# in the array corresponds to
# 0 Date
# 1 Time
# 2 TargetTemp
# 3 ActualTemp
# 4 System
# 5 SystemAge
# 6 BuildingID
# Define a function that parses the raw CSV file and returns an object of type LabeledDocument
def parseDocument(line):
values = [str(x) for x in [Link](',')]
if (values[3] > values[2]):
hot = 1.0
else:
hot = 0.0
The pipeline we'll be building consists of three stages: Tokenizer and HashingTF (both Transformers ), and
Logistic Regression , which is an Estimator .
Our data (extracted from the CSV and mapped to our LabeledDocument type), which is a DataFrame flows through
the pipeline when [Link](training) is called. The first stage, Tokenizer , splits the SystemInfo input column
(consisting of two "words": the system Id and age values) into a "words" output column. This new "words" column
is added to the DataFrame . The next stage, HashingTF , converts the new "words" column into feature vectors. This
new column, "features", is added to the DataFrame . Remember, these first two stages are Transformer s. Since
LogisticRegression is an Estimator , our pipeline calls the [Link]() method to produce a
LogisticRegressionModel .
# Build the pipeline with our tokenizer, hashingTF, and logistic regression stages
pipeline = Pipeline(stages=[tokenizer, hashingTF, lr])
model = [Link](training)
To take a look at the new columns added by the Tokenizer and HashingTF transformers ("words" and "features"),
as well as a sample of the LogisticRegression estimator, we'll run a [Link]() method on our
original DataFrame . * This is just for illustrative purposes. Typically, the next step would be to pass in a test
DataFrame to validate our training:
peek = [Link](training)
[Link]()
From this point, the model object can be used to make predictions. The full sample of this machine learning
application, and step-by-step instructions for running it, can be found here.
Next steps
This article introduced the key concepts behind Spark ML Pipelines, and illustrated a sample use case of pipelines
through code examples.
See a full example machine learning application that incorporates Spark ML Pipelines.
Learn more about creating Spark ML models in notebooks.
Data Science using Scala and Spark on Azure
8/14/2017 • 34 min to read • Edit Online
This article shows you how to use Scala for supervised machine learning tasks with the Spark scalable MLlib and
Spark ML packages on an Azure HDInsight Spark cluster. It walks you through the tasks that constitute the Data
Science process: data ingestion and exploration, visualization, feature engineering, modeling, and model
consumption. The models in the article include logistic and linear regression, random forests, and gradient-boosted
trees (GBTs), in addition to two common supervised machine learning tasks:
Regression problem: Prediction of the tip amount ($) for a taxi trip
Binary classification: Prediction of tip or no tip (1/0) for a taxi trip
The modeling process requires training and evaluation on a test data set and relevant accuracy metrics. In this
article, you can learn how to store these models in Azure Blob storage and how to score and evaluate their
predictive performance. This article also covers the more advanced topics of how to optimize models by using
cross-validation and hyper-parameter sweeping. The data used is a sample of the 2013 NYC taxi trip and fare data
set available on GitHub.
Scala, a language based on the Java virtual machine, integrates object-oriented and functional language concepts.
It's a scalable language that is well suited to distributed processing in the cloud, and runs on Azure Spark clusters.
Spark is an open-source parallel-processing framework that supports in-memory processing to boost the
performance of big data analytics applications. The Spark processing engine is built for speed, ease of use, and
sophisticated analytics. Spark's in-memory distributed computation capabilities make it a good choice for iterative
algorithms in machine learning and graph computations. The [Link] package provides a uniform set of high-level
APIs built on top of data frames that can help you create and tune practical machine learning pipelines. MLlib is
Spark's scalable machine learning library, which brings modeling capabilities to this distributed environment.
HDInsight Spark is the Azure-hosted offering of open-source Spark. It also includes support for Jupyter Scala
notebooks on the Spark cluster, and can run Spark SQL interactive queries to transform, filter, and visualize data
stored in Azure Blob storage. The Scala code snippets in this article that provide the solutions and show the relevant
plots to visualize the data run in Jupyter notebooks installed on the Spark clusters. The modeling steps in these
topics have code that shows you how to train, evaluate, save, and consume each type of model.
The setup steps and code in this article are for Azure HDInsight 3.4 Spark 1.6. However, the code in this article and
in the Scala Jupyter Notebook are generic and should work on any Spark cluster. The cluster setup and
management steps might be slightly different from what is shown in this article if you are not using HDInsight
Spark.
NOTE
For a topic that shows you how to use Python rather than Scala to complete tasks for an end-to-end Data Science process,
see Data Science using Spark on Azure HDInsight.
Prerequisites
You must have an Azure subscription. If you do not already have one, get an Azure free trial.
You need an Azure HDInsight 3.4 Spark 1.6 cluster to complete the following procedures. To create a cluster, see
the instructions in Get started: Create Apache Spark on Azure HDInsight. Set the cluster type and version on the
Select Cluster Type menu.
WARNING
Billing for HDInsight clusters is prorated per minute, whether you are using them or not. Be sure to delete your cluster
after you have finished using it. For more information, see How to delete an HDInsight cluster.
For a description of the NYC taxi trip data and instructions on how to execute code from a Jupyter notebook on the
Spark cluster, see the relevant sections in Overview of Data Science using Spark on Azure HDInsight.
Select Scala to see a directory that has a few examples of prepackaged notebooks that use the PySpark API. The
Exploration Modeling and Scoring using [Link] notebook that contains the code samples for this suite of
Spark topics is available on GitHub.
You can upload the notebook directly from GitHub to the Jupyter Notebook server on your Spark cluster. On your
Jupyter home page, click the Upload button. In the file explorer, paste the GitHub (raw content) URL of the Scala
notebook, and then click Open. The Scala notebook is available at the following URL:
[Link]
Setup: Preset Spark and Hive contexts, Spark magics, and Spark
libraries
Preset Spark and Hive contexts
The Spark kernels that are provided with Jupyter notebooks have preset contexts. You don't need to explicitly set
the Spark or Hive contexts before you start working with the application you are developing. The preset contexts
are:
sc for SparkContext
sqlContext for HiveContext
Spark magics
The Spark kernel provides some predefined “magics,” which are special commands that you can call with %% . Two
of these commands are used in the following code samples.
%%local specifies that the code in subsequent lines will be executed locally. The code must be valid Scala code.
%%sql -o <variable name> executes a Hive query against sqlContext . If the -o parameter is passed, the result
of the query is persisted in the %%local Scala context as a Spark data frame.
For more information about the kernels for Jupyter notebooks and their predefined "magics" that you call with %%
(for example, %%local ), see Kernels available for Jupyter notebooks with HDInsight Spark Linux clusters on
HDInsight.
Import libraries
Import the Spark, MLlib, and other libraries you'll need by using the following code.
# IMPORT SPARK AND JAVA LIBRARIES
import [Link]
import [Link]._
import [Link]
import [Link]
import [Link]._
import [Link]
# SPECIFY SQLCONTEXT
val sqlContext = new SQLContext(sc)
Data ingestion
The first step in the Data Science process is to ingest the data that you want to analyze. You bring the data from
external sources or systems where it resides into your data exploration and modeling environment. In this article,
the data you ingest is a joined 0.1% sample of the taxi trip and fare file (stored as a .tsv file). The data exploration
and modeling environment is Spark. This section contains the code to complete the following series of tasks:
1. Set directory paths for data and model storage.
2. Read in the input data set (stored as a .tsv file).
3. Define a schema for the data and clean the data.
4. Create a cleaned data frame and cache it in memory.
5. Register the data as a temporary table in SQLContext.
6. Query the table and import the results into a data frame.
Set directory paths for storage locations in Azure Blob storage
Spark can read and write to Azure Blob storage. You can use Spark to process any of your existing data, and then
store the results again in Blob storage.
To save models or files in Blob storage, you need to properly specify the path. Reference the default container
attached to the Spark cluster by using a path that begins with wasb:/// . Reference other locations by using
wasb:// .
The following code sample specifies the location of the input data to be read and the path to Blob storage that is
attached to the Spark cluster where the model will be saved.
# SET PATHS TO DATA AND MODEL FILE LOCATIONS
# INGEST DATA AND SPECIFY HEADERS FOR COLUMNS
val taxi_train_file =
[Link]("wasb://mllibwalkthroughs@[Link]/Data/NYCTaxi/[Link]
[Link]")
val header = taxi_train_file.first;
Import data, create an RDD, and define a data frame according to the schema
# CREATE AN INITIAL DATA FRAME AND DROP COLUMNS, AND THEN CREATE A CLEANED DATA FRAME BY FILTERING FOR UNWANTED
VALUES OR OUTLIERS
val taxi_train_df = [Link](taxi_temp, taxi_schema)
Output:
Time to run the cell: 8 seconds.
Query the table and import results in a data frame
Next, query the table for fare, passenger, and tip data; filter out corrupt and outlying data; and print several rows.
Output:
In the following code, the %%local magic creates a local data frame, sqlResults. You can use sqlResults to plot by
using matplotlib.
TIP
Local magic is used multiple times in this article. If your data set is large, please sample to create a data frame that can fit in
local memory.
The Spark kernel automatically visualizes the output of SQL (HiveQL) queries after you run the code. You can
choose between several types of visualizations:
Table
Pie
Line
Area
Bar
Here's the code to plot the data:
# RUN THE CODE LOCALLY ON THE JUPYTER SERVER AND IMPORT LIBRARIES
%%local
import [Link] as plt
%matplotlib inline
Output:
Create features and transform features, and then prep data for input
into modeling functions
For tree-based modeling functions from Spark ML and MLlib, you have to prepare target and features by using a
variety of techniques, such as binning, indexing, one-hot encoding, and vectorization. Here are the procedures to
follow in this section:
1. Create a new feature by binning hours into traffic time buckets.
2. Apply indexing and one-hot encoding to categorical features.
3. Sample and split the data set into training and test fractions.
4. Specify training variable and features, and then create indexed or one-hot encoded training and testing
input labeled point resilient distributed datasets (RDDs) or data frames.
5. Automatically categorize and vectorize features and targets to use as inputs for machine learning models.
Create a new feature by binning hours into traffic time buckets
This code shows you how to create a new feature by binning hours into traffic time buckets and how to cache the
resulting data frame in memory. Where RDDs and data frames are used repeatedly, caching leads to improved
execution times. Accordingly, you'll cache RDDs and data frames at several stages in the following procedures.
# CACHE THE DATA FRAME IN MEMORY AND MATERIALIZE THE DATA FRAME IN MEMORY
taxi_df_train_with_newFeatures.cache()
taxi_df_train_with_newFeatures.count()
# CREATE INDEXES AND ONE-HOT ENCODED VECTORS FOR SEVERAL CATEGORICAL FEATURES
Output:
Time to run the cell: 4 seconds.
Sample and split the data set into training and test fractions
This code creates a random sampling of the data (25%, in this example). Although sampling is not required for this
example due to the size of the data set, the article shows you how you can sample so that you know how to use it
for your own problems when needed. When samples are large, this can save significant time while you train
models. Next, split the sample into a training part (75%, in this example) and a testing part (25%, in this example) to
use in classification and regression modeling.
Add a random number (between 0 and 1) to each row (in a "rand" column) that can be used to select cross-
validation folds during training.
# RECORD THE START TIME
val starttime = [Link]().getTime()
# SPLIT THE SAMPLED DATA FRAME INTO TRAIN AND TEST, WITH A RANDOM COLUMN ADDED FOR DOING CROSS-VALIDATION
(SHOWN LATER)
# INCLUDE A RANDOM COLUMN FOR CREATING CROSS-VALIDATION FOLDS
val splits = [Link](Array(trainingFraction, testingFraction), seed = seed)
val trainData = splits(0)
val testData = splits(1)
Output:
Time to run the cell: 2 seconds.
Specify training variable and features, and then create indexed or one -hot encoded training and testing input
labeled point RDDs or data frames
This section contains code that shows you how to index categorical text data as a labeled point data type, and
encode it so you can use it to train and test MLlib logistic regression and other classification models. Labeled point
objects are RDDs that are formatted in a way that is needed as input data by most of machine learning algorithms
in MLlib. A labeled point is a local vector, either dense or sparse, associated with a label/response.
In this code, you specify the target (dependent) variable and the features to use to train models. Then, you create
indexed or one-hot encoded training and testing input labeled point RDDs or data frames.
# RECORD THE START TIME
val starttime = [Link]().getTime()
# MAP NAMES OF FEATURES AND TARGETS FOR CLASSIFICATION AND REGRESSION PROBLEMS
val featuresIndOneHot = List("paymentVec", "vendorVec", "rateVec", "TrafficTimeBinsVec", "pickup_hour",
"weekday", "passenger_count", "trip_time_in_secs", "trip_distance",
"fare_amount").map([Link](_))
val featuresIndIndex = List("paymentIndex", "vendorIndex", "rateIndex", "TrafficTimeBinsIndex", "pickup_hour",
"weekday", "passenger_count", "trip_time_in_secs", "trip_distance",
"fare_amount").map([Link](_))
# SPECIFY THE TARGET FOR CLASSIFICATION ('tipped') AND REGRESSION ('tip_amount') PROBLEMS
val targetIndBinary = List("tipped").map([Link](_))
val targetIndRegression = List("tip_amount").map([Link](_))
# CREATE INDEXED DATA FRAMES THAT YOU CAN USE TO TRAIN BY USING SPARK ML FUNCTIONS
val indexedTRAINbinaryDF = [Link]()
val indexedTESTbinaryDF = [Link]()
val indexedTRAINregDF = [Link]()
val indexedTESTregDF = [Link]()
# CREATE ONE-HOT ENCODED (VECTORIZED) DATA FRAMES THAT YOU CAN USE TO TRAIN BY USING SPARK ML FUNCTIONS
val assemblerOneHot = new VectorAssembler().setInputCols(Array("paymentVec", "vendorVec", "rateVec",
"TrafficTimeBinsVec", "pickup_hour", "weekday", "passenger_count", "trip_time_in_secs", "trip_distance",
"fare_amount")).setOutputCol("features")
val OneHotTRAIN = [Link](trainData)
val OneHotTEST = [Link](testData)
Output:
Time to run the cell: 4 seconds.
Automatically categorize and vectorize features and targets to use as inputs for machine learning models
Use Spark ML to categorize the target and features to use in tree-based modeling functions. The code completes
two tasks:
Creates a binary target for classification by assigning a value of 0 or 1 to each data point between 0 and 1 by
using a threshold value of 0.5.
Automatically categorizes features. If the number of distinct numerical values for any feature is less than 32, that
feature is categorized.
Here's the code for these two tasks.
# CATEGORIZE FEATURES AND BINARIZE THE TARGET FOR THE BINARY CLASSIFICATION PROBLEM
# TRAIN DATA
val indexer = new VectorIndexer().setInputCol("features").setOutputCol("featuresCat").setMaxCategories(32)
val indexerModel = [Link](indexedTRAINbinaryDF)
val indexedTrainwithCatFeat = [Link](indexedTRAINbinaryDF)
val binarizer: Binarizer = new Binarizer().setInputCol("label").setOutputCol("labelBin").setThreshold(0.5)
val indexedTRAINwithCatFeatBinTarget = [Link](indexedTrainwithCatFeat)
# TEST DATA
val indexerModel = [Link](indexedTESTbinaryDF)
val indexedTrainwithCatFeat = [Link](indexedTESTbinaryDF)
val binarizer: Binarizer = new Binarizer().setInputCol("label").setOutputCol("labelBin").setThreshold(0.5)
val indexedTESTwithCatFeatBinTarget = [Link](indexedTrainwithCatFeat)
# TRAIN DATA
val indexer = new VectorIndexer().setInputCol("features").setOutputCol("featuresCat").setMaxCategories(32)
val indexerModel = [Link](indexedTRAINregDF)
val indexedTRAINwithCatFeat = [Link](indexedTRAINregDF)
# TEST DATA
val indexerModel = [Link](indexedTESTbinaryDF)
val indexedTESTwithCatFeat = [Link](indexedTESTregDF)
# LOAD THE SAVED MODEL AND SCORE THE TEST DATA SET
val savedModel = [Link](filename)
println(s"Coefficients: ${[Link]} Intercept: ${[Link]}")
Output:
ROC on test data = 0.9827381497557599
Use Python on local Pandas data frames to plot the ROC curve.
# QUERY THE RESULTS
%%sql -q -o sqlResults
SELECT tipped, probability from testResults
# RUN THE CODE LOCALLY ON THE JUPYTER SERVER AND IMPORT LIBRARIES
%%local
%matplotlib inline
from [Link] import roc_curve,auc
Output:
Output:
ROC on test data = 0.9847103571552683
Create a GBT classification model
Next, create a GBT classification model by using MLlib's GradientBoostedTrees() function, and then evaluate the
model on test data.
# TRAIN A GBT CLASSIFICATION MODEL BY USING MLLIB AND A LABELED POINT
# EVALUATE THE MODEL ON TEST INSTANCES AND THE COMPUTE TEST ERROR
val labelAndPreds = [Link] { point =>
val prediction = [Link]([Link])
([Link], prediction)
}
val testErr = [Link](r => r._1 != r._2).[Link] / [Link]()
//println("Learned classification GBT model:\n" + [Link])
println("Test Error = " + testErr)
# USE BINARY AND MULTICLASS METRICS TO EVALUATE THE MODEL ON THE TEST DATA
val metrics = new MulticlassMetrics(labelAndPreds)
println(s"Precision: ${[Link]}")
println(s"Recall: ${[Link]}")
println(s"F1 Score: ${[Link]}")
Output:
Area under ROC curve: 0.9846895479241554
# CREATE A REGULARIZED LINEAR REGRESSION MODEL BY USING THE SPARK ML FUNCTION AND DATA FRAMES
val lr = new
LinearRegression().setLabelCol("tip_amount").setFeaturesCol("features").setMaxIter(10).setRegParam(0.3).setElas
ticNetParam(0.8)
# SUMMARIZE THE MODEL OVER THE TRAINING SET AND PRINT METRICS
val trainingSummary = [Link]
println(s"numIterations: ${[Link]}")
println(s"objectiveHistory: ${[Link]}")
[Link]()
println(s"RMSE: ${[Link]}")
println(s"r2: ${trainingSummary.r2}")
Output:
Time to run the cell: 13 seconds.
# LOAD A SAVED LINEAR REGRESSION MODEL FROM BLOB STORAGE AND SCORE A TEST DATA SET
Output:
R-sqr on test data = 0.5960320470835743
Next, query the test results as a data frame and use AutoVizWidget and matplotlib to visualize it.
The code creates a local data frame from the query output and plots the data. The %%local magic creates a local
data frame, sqlResults , which you can use to plot with matplotlib.
NOTE
This Spark magic is used multiple times in this article. If the amount of data is large, you should sample to create a data frame
that can fit in local memory.
Output:
# MAKE PREDICTIONS
val predictions = [Link](indexedTESTwithCatFeat)
Output:
Test R-sqr is: 0.7655383534596654
# DEFINE THE PIPELINE WITH A TRAIN/TEST VALIDATION SPLIT (75% IN THE TRAINING SET), AND THEN THE SPECIFY
ESTIMATOR, EVALUATOR, AND PARAMETER GRID
val trainPct = 0.75
val trainValidationSplit = new TrainValidationSplit().setEstimator(lr).setEvaluator(new
RegressionEvaluator).setEstimatorParamMaps(paramGrid).setTrainRatio(trainPct)
# RUN THE TRAIN VALIDATION SPLIT AND CHOOSE THE BEST SET OF PARAMETERS
val model = [Link](OneHotTRAINLabeled)
# MAKE PREDICTIONS ON THE TEST DATA BY USING THE MODEL WITH THE COMBINATION OF PARAMETERS THAT PERFORMS THE
BEST
val testResults = [Link](OneHotTESTLabeled).select("label", "prediction")
Output:
Test R-sqr is: 0.6226484708501209
Optimize the binary classification model by using cross-validation and hyper-parameter sweeping
This section shows you how to optimize a binary classification model by using cross-validation and hyper-
parameter sweeping. This uses the Spark ML CrossValidator function.
# RECORD THE START TIME
val starttime = [Link]().getTime()
# CREATE DATA FRAMES WITH PROPERLY LABELED COLUMNS TO USE WITH THE TRAIN AND TEST SPLIT
val indexedTRAINwithCatFeatBinTargetRF =
[Link]("labelBin","featuresCat").withColumnRenamed(existingName="labelBin",new
Name="label").withColumnRenamed(existingName="featuresCat",newName="features")
val indexedTESTwithCatFeatBinTargetRF =
[Link]("labelBin","featuresCat").withColumnRenamed(existingName="labelBin",newN
ame="label").withColumnRenamed(existingName="featuresCat",newName="features")
[Link]()
[Link]()
# RUN THE TRAIN VALIDATION SPLIT AND CHOOSE THE BEST SET OF PARAMETERS
val model = [Link](indexedTRAINwithCatFeatBinTargetRF)
# MAKE PREDICTIONS ON THE TEST DATA BY USING THE MODEL WITH THE COMBINATION OF PARAMETERS THAT PERFORMS THE
BEST
val testResults = [Link](indexedTESTwithCatFeatBinTargetRF).select("label", "prediction")
Output:
Time to run the cell: 33 seconds.
Optimize the linear regression model by using custom cross-validation and parameter-sweeping code
Next, optimize the model by using custom code, and identify the best model parameters by using the criterion of
highest accuracy. Then, create the final model, evaluate the model on test data, and save the model in Blob storage.
Finally, load the model, score test data, and evaluate accuracy.
val nFolds = 3
val numModels = [Link]
val numParamsinGrid = 2
val numParamsinGrid = 2
var maxDepth = -1
var numTrees = -1
var param = ""
var paramval = -1
var validateLB = -1.0
var validateUB = -1.0
val h = 1.0 / nFolds;
val RMSE = [Link](numModels)(0.0)
# CREATE K-FOLDS
val splits = [Link](indexedTRAINbinary, numFolds = nFolds, seed=1234)
# LOOP THROUGH K-FOLDS AND THE PARAMETER GRID TO GET AND IDENTIFY THE BEST PARAMETER SET BY LEVEL OF ACCURACY
for (i <- 0 to (nFolds-1)) {
validateLB = i * h
validateUB = (i + 1) * h
val validationCV = [Link]($"rand" >= validateLB && $"rand" < validateUB)
val trainCV = [Link]($"rand" < validateLB || $"rand" >= validateUB)
val validationLabPt = [Link](r => LabeledPoint([Link](targetIndRegression(0).toInt),
[Link]([Link]([Link](_)).toArray)));
val trainCVLabPt = [Link](r => LabeledPoint([Link](targetIndRegression(0).toInt),
[Link]([Link]([Link](_)).toArray)));
[Link]()
[Link]()
# CREATE THE BEST MODEL WITH THE BEST PARAMETERS AND A FULL TRAINING DATA SET
val best_rfModel = [Link](indexedTRAINreg,
categoricalFeaturesInfo=categoricalFeaturesInfo,
numTrees=best_numTrees, maxDepth=best_maxDepth,
featureSubsetStrategy="auto",impurity="variance", maxBins=32)
featureSubsetStrategy="auto",impurity="variance", maxBins=32)
# PREDICT ON THE TRAINING SET WITH THE BEST MODEL AND THEN EVALUATE
val labelAndPreds = [Link] { point =>
val prediction = best_rfModel.predict([Link])
( prediction, [Link] )
}
Output:
Time to run the cell: 61 seconds.
Introduction
Deep learning is impacting everything from healthcare to transportation to manufacturing, and more. Companies
are turning to deep learning to solve hard problems, like image classification, speech recognition, object
recognition, and machine translation.
There are many popular frameworks, including Microsoft Cognitive Toolkit, Tensorflow, MXNet, Theano, etc. Caffe is
one of the most famous non-symbolic (imperative) neural network frameworks, and widely used in many areas
including computer vision. Furthermore, CaffeOnSpark combines Caffe with Apache Spark, in which case deep
learning can be easily used on an existing Hadoop cluster together with Spark ETL pipelines, reducing system
complexity and latency for end-to-end learning.
HDInsight is the only fully-managed cloud Hadoop offering that provides optimized open source analytic clusters
for Spark, Hive, MapReduce, HBase, Storm, Kafka, and R Server backed by a 99.9% SLA. Each of these big data
technologies and ISV applications are easily deployable as managed clusters with enterprise-level security and
monitoring.
Some users are asking us about how to use deep learning on HDInsight, which is Microsoft's PaaS Hadoop product.
We will have more to share in the future, but today we want to summarize a technical blog on how to use Caffe on
HDInsight Spark.
If you have installed Caffe before, you will notice that installing this framework is a little bit challenging. In this blog,
we will first illustrate how to install Caffe on Spark for an HDInsight cluster, then use the built-in MNIST demo to
demostrate how to use Distributed Deep Learning using HDInsight Spark on CPUs.
There are four major steps to get it work on HDInsight.
1. Install the required dependencies on all the nodes
2. Build Caffe on Spark for HDInsight on the head node
3. Distribute the required libraries to all the worker nodes
4. Compose a Caffe model and run it distributely
Since HDInsight is a PaaS solution, it offers great platform features - so it is quite easy to perform some tasks. One
of the features that we heavily use in this blog post is called Script Action, with which you can execute shell
commands to customize cluster nodes (head node, worker node, or edge node).
#install protobuf
wget [Link]
sudo tar xzvf [Link] -C /tmp/
cd /tmp/protobuf-2.5.0/
sudo ./configure
sudo make
sudo make check
sudo make install
sudo ldconfig
echo "protobuf installation done"
There are two steps in the script action above. The first step is to install all the required libraries. Those libraries
include the necessary libraries for both compiling Caffe(such as gflags, glog) and running Caffe (such as numpy).
We are using libatlas for CPU optimization, but you can always follow the CaffeOnSpark wiki on installing other
optimization libraries, such as MKL or CUDA (for GPU).
The second step is to download, compile, and install protobuf 2.5.0 for Caffe during runtime. Protobuf 2.5.0 is
required, however this version is not available as a package on Ubuntu 16, so we need to compile it from the
source code. There are also a few resources on the Internet on how to compile it, such as this
To simply get started, you can just run this script action against your cluster to all the worker nodes and head nodes
(for HDInsight 3.5). You can either run the script actions for a running cluster, or you can also run the script actions
during the cluster provision time. For more details on the script actions, please see the documentation here
Step 2: Build Caffe on Spark for HDInsight on the head node
The second step is to build Caffe on the headnode, and then distribute the compiled libraries to all the worker
nodes. In this step, you will need to ssh into your headnode, then simply follow the CaffeOnSpark build process,
and below is the script you can use to build CaffeOnSpark with a few additional steps.
#!/bin/bash
git clone [Link] --recursive
export CAFFE_ON_SPARK=$(pwd)/CaffeOnSpark
pushd ${CAFFE_ON_SPARK}/caffe-public/
cp [Link] [Link]
echo "INCLUDE_DIRS += ${JAVA_HOME}/include" >> [Link]
#Below configurations might need to be updated based on actual cases. For example, if you are using GPU, or
using a different BLAS library, you may want to update those settings accordingly.
echo "CPU_ONLY := 1" >> [Link]
echo "BLAS := atlas" >> [Link]
echo "INCLUDE_DIRS += /usr/include/hdf5/serial/" >> [Link]
echo "LIBRARY_DIRS += /usr/lib/x86_64-linux-gnu/hdf5/serial/" >> [Link]
popd
#compile CaffeOnSpark
pushd ${CAFFE_ON_SPARK}
#always clean up the environment before building (especially when rebuiding), or there will be errors such as
"failed to execute goal [Link]:maven-antrun-plugin:1.7:run (proto) on project caffe-distri:
An Ant BuildException has occured: exec returned: 2"
make clean
#the build step usually takes 20~30 mins, since it has a lot maven dependencies
make build
popd
export LD_LIBRARY_PATH=${CAFFE_ON_SPARK}/caffe-public/distribute/lib:${CAFFE_ON_SPARK}/caffe-
distri/distribute/lib
${CAFFE_ON_SPARK}/scripts/[Link]
hadoop fs -put -f ${CAFFE_ON_SPARK}/data/mnist_*_lmdb wasb:///projects/machine_learning/image_dataset/
${CAFFE_ON_SPARK}/scripts/[Link]
hadoop fs -put -f ${CAFFE_ON_SPARK}/data/cifar10_*_lmdb wasb:///projects/machine_learning/image_dataset/
#put the already compiled CaffeOnSpark libraries to wasb storage, then read back to each node using script
actions. This is because CaffeOnSpark requires all the nodes have the libarries
hadoop fs -mkdir -p /CaffeOnSpark/caffe-public/distribute/lib/
hadoop fs -mkdir -p /CaffeOnSpark/caffe-distri/distribute/lib/
hadoop fs -put CaffeOnSpark/caffe-distri/distribute/lib/* /CaffeOnSpark/caffe-distri/distribute/lib/
hadoop fs -put CaffeOnSpark/caffe-public/distribute/lib/* /CaffeOnSpark/caffe-public/distribute/lib/
You may need to do more than what the documentation of CaffeOnSpark says. The changes are:
Change to CPU only and use libatlas for this particular purpose.
Put the datasets to the BLOB storage, which is a shared location that is accessible to all worker nodes for later
use.
Put the compiled Caffe libraries to BLOB storage, and later you will copy those libraries to all the nodes using
script actions to avoid additional compilation time.
Troubleshooting: An Ant BuildException has occured: exec returned: 2
When first trying to build CaffeOnSpark, sometimes it will say
Simply clean the code repository by "make clean" and then run "make build" will solve this issue, as long as you
have the correct dependencies.
Troubleshooting: Maven repository connection time out
Sometimes maven gives me the connection time out error, similar to below:
Retry:
[INFO] Downloading: [Link]
Feb 01, 2017 5:14:49 AM [Link] execute
INFO: I/O exception ([Link]) caught when processing request to {s}-
>[Link] Connection timed out (Read failed)
It will be OK after waiting for a few minutes and then just try to rebuild the code, so it might be Maven somehow
limits the traffic from a given IP address.
Troubleshooting: Test failure for Caffe
You probably will see a test failure when doing the final check for CaffeOnSpark, similar with below. This is
prabably related with UTF-8 encoding, but should not impact the usage of Caffe
#!/bin/bash
hadoop fs -get wasb:///CaffeOnSpark /home/changetoyourusername/
Because in step 2, we put it on the BLOB storage which is accessible to all the nodes, in this step we just simply copy
it to all the nodes.
For more information on how to define the network, please check the Caffe documentation on MNIST dataset
For the purpose of this blog, we just use this simple MNIST example. You should run the command below from the
head node:
17/02/01 23:22:16 INFO Client: Application report for application_1485916338528_0015 (state: RUNNING)
If you want to know what happened, you usually need to get the Spark driver's log, which has more information. In
this case, you need to go to the YARN UI to find the relevant YARN logs. You can get the YARN UI by this URL:
[Link]
You can take a look at how many resources are allocated for this particular application. You can click the
"Scheduler" link, and then you will see that for this application, there are 9 containers running. We ask YARN to
provide 8 executors, and another container is for driver process.
You may want to check the driver logs or container logs if there are failures. For driver logs, you can click the
application ID in YARN UI, then click the "Logs" button. The driver logs are written into stderr.
For example, you might see some of the error below from the driver logs, indicating you allocate too many
executors.
17/02/01 07:26:06 ERROR ApplicationMaster: User class threw exception: [Link]:
Insufficient training data. Please adjust hyperparameters or increase dataset.
[Link]: Insufficient training data. Please adjust hyperparameters or increase dataset.
at [Link]([Link])
at [Link]$.main([Link])
at [Link]([Link])
at [Link].invoke0(Native Method)
at [Link]([Link])
at [Link]([Link])
at [Link]([Link])
at [Link]$$anon$[Link]([Link])
Sometimes, the issue can happen in executors rather than drivers. In this case, you need to check the container logs.
You can always get the container logs, and then get the failed container. For example, you might meet this failure
when running Caffe.
17/02/01 07:12:05 WARN YarnAllocator: Container marked as failed: container_1485916338528_0008_05_000005 on
host: [Link]. Exit status: 134. Diagnostics: Exception from container-launch.
Container id: container_1485916338528_0008_05_000005
Exit code: 134
Exception message: /bin/bash: line 1: 12230 Aborted (core dumped)
LD_LIBRARY_PATH=/usr/hdp/current/hadoop-client/lib/native:/usr/hdp/current/hadoop-client/lib/native/Linux-
amd64-64:/home/xiaoyzhu/CaffeOnSpark/caffe-public/distribute/lib:/home/xiaoyzhu/CaffeOnSpark/caffe-
distri/distribute/lib /usr/lib/jvm/java-8-openjdk-amd64/bin/java -server -Xmx4608m '-[Link]=' '-
[Link]=sparkexecutor' '-[Link]=[Link]' '-
[Link]=[Link]' '-[Link]=INFO,console,RFA,ETW,Anonymizer' '-
[Link]=/var/log/sparkapp/${[Link]}' '-[Link]=[Link]' '-
[Link]=file:/usr/hdp/current/spark2-client/conf/[Link]' '-
[Link]=[Link]' -
[Link]=/mnt/resource/hadoop/yarn/local/usercache/xiaoyzhu/appcache/application_1485916338528_0008/cont
ainer_1485916338528_0008_05_000005/tmp '-[Link]=43942' '-[Link]=18080' '-
[Link]=0' -
[Link]=/mnt/resource/hadoop/yarn/log/application_1485916338528_0008/container_148591
6338528_0008_05_000005 -XX:OnOutOfMemoryError='kill %p' [Link]
--driver-url spark://CoarseGrainedScheduler@[Link]:43942 --executor-id 4 --hostname [Link] --cores 3 --
app-id application_1485916338528_0008 --user-class-path
file:/mnt/resource/hadoop/yarn/local/usercache/xiaoyzhu/appcache/application_1485916338528_0008/container_14859
16338528_0008_05_000005/__app__.jar >
/mnt/resource/hadoop/yarn/log/application_1485916338528_0008/container_1485916338528_0008_05_000005/stdout 2>
/mnt/resource/hadoop/yarn/log/application_1485916338528_0008/container_1485916338528_0008_05_000005/stderr
Stack trace: ExitCodeException exitCode=134: /bin/bash: line 1: 12230 Aborted (core dumped)
LD_LIBRARY_PATH=/usr/hdp/current/hadoop-client/lib/native:/usr/hdp/current/hadoop-client/lib/native/Linux-
amd64-64:/home/xiaoyzhu/CaffeOnSpark/caffe-public/distribute/lib:/home/xiaoyzhu/CaffeOnSpark/caffe-
distri/distribute/lib /usr/lib/jvm/java-8-openjdk-amd64/bin/java -server -Xmx4608m '-[Link]=' '-
[Link]=sparkexecutor' '-[Link]=[Link]' '-
[Link]=[Link]' '-[Link]=INFO,console,RFA,ETW,Anonymizer' '-
[Link]=/var/log/sparkapp/${[Link]}' '-[Link]=[Link]' '-
[Link]=file:/usr/hdp/current/spark2-client/conf/[Link]' '-
[Link]=[Link]' -
[Link]=/mnt/resource/hadoop/yarn/local/usercache/xiaoyzhu/appcache/application_1485916338528_0008/cont
ainer_1485916338528_0008_05_000005/tmp '-[Link]=43942' '-[Link]=18080' '-
[Link]=0' -
[Link]=/mnt/resource/hadoop/yarn/log/application_1485916338528_0008/container_148591
6338528_0008_05_000005 -XX:OnOutOfMemoryError='kill %p' [Link]
--driver-url spark://CoarseGrainedScheduler@[Link]:43942 --executor-id 4 --hostname [Link] --cores 3 --
app-id application_1485916338528_0008 --user-class-path
file:/mnt/resource/hadoop/yarn/local/usercache/xiaoyzhu/appcache/application_1485916338528_0008/container_14859
16338528_0008_05_000005/__app__.jar >
/mnt/resource/hadoop/yarn/log/application_1485916338528_0008/container_1485916338528_0008_05_000005/stdout 2>
/mnt/resource/hadoop/yarn/log/application_1485916338528_0008/container_1485916338528_0008_05_000005/stderr
at [Link]([Link])
at [Link]([Link])
at [Link]$[Link]([Link])
at
[Link]([Link]
a:225)
at
[Link]([Link]
17)
at
[Link]([Link]
3)
at [Link]([Link])
at [Link]([Link])
at [Link]$[Link]([Link])
at [Link]([Link])
from the headnode. After checking container failure, it is caused by using GPU mode (where you should use CPU
mode instead) in lenet_memory_solver.prototxt.
Getting results
Since we are allocating 8 executors, and the network topology is simple, it should only take around 30 minutes to
run the result. From the command line, you can see that we put the model to wasb:///[Link], and put the
results to a folder named wasb:///mnist_features_result.
You can get the results by running
{"SampleID":"00009597","accuracy":[1.0],"loss":[0.028171852],"label":[2.0]}
{"SampleID":"00009598","accuracy":[1.0],"loss":[0.028171852],"label":[6.0]}
{"SampleID":"00009599","accuracy":[1.0],"loss":[0.028171852],"label":[1.0]}
{"SampleID":"00009600","accuracy":[0.97],"loss":[0.0677709],"label":[5.0]}
{"SampleID":"00009601","accuracy":[0.97],"loss":[0.0677709],"label":[0.0]}
{"SampleID":"00009602","accuracy":[0.97],"loss":[0.0677709],"label":[1.0]}
{"SampleID":"00009603","accuracy":[0.97],"loss":[0.0677709],"label":[2.0]}
{"SampleID":"00009604","accuracy":[0.97],"loss":[0.0677709],"label":[3.0]}
{"SampleID":"00009605","accuracy":[0.97],"loss":[0.0677709],"label":[4.0]}
The SampleID represents the ID in the MNIST dataset, and the label is the number that the model identifies.
Conclusion
In this documentation, you have tried to install CaffeOnSpark with running a simple example. HDInsight is a full
managed cloud distributed compute platform, and is the best place for running machine learning and advanced
analytics workloads on large data set, and for distributed deep learning, you can use Caffe on HDInsight Spark to
perform deep learning tasks.
See also
Overview: Apache Spark on Azure HDInsight
Scenarios
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Introduction to R Server and open-source R
capabilities on HDInsight
8/16/2017 • 8 min to read • Edit Online
Microsoft R Server is available as a deployment option when you create HDInsight clusters in Azure. This new
capability provides data scientists, statisticians, and R programmers with on-demand access to scalable,
distributed methods of analytics on HDInsight.
Clusters can be sized appropriately to the projects and tasks at hand and then torn down when they're no longer
needed. Since they're part of Azure HDInsight, these clusters come with enterprise-level 24/7 support, an SLA of
99.9% up-time, and the ability to integrate with other components in the Azure ecosystem.
R Server on HDInsight provides the latest capabilities for R-based analytics on datasets of virtually any size, loaded
to either Azure Blob or Data Lake storage. Since R Server is built on open source R, the R-based applications you
build can leverage any of the 8000+ open source R packages. The routines in ScaleR, Microsoft’s big data analytics
package included with R Server, are also available.
The edge node of a cluster provides a convenient place to connect to the cluster and to run your R scripts. With an
edge node, you have the option of running the parallelized distributed functions of ScaleR across the cores of the
edge node server. You can also run them across the nodes of the cluster by using ScaleR’s Hadoop Map Reduce or
Spark compute contexts.
The models or predictions that result from analyses can be downloaded for use on-premises. They can also be
operationalized elsewhere in Azure, in particular through Azure Machine Learning Studio web service.
Operationalize a model
When your data modeling is complete, you can operationalize the model to make predictions for new data either
from Azure and on-premises. This process is known as scoring. Scoring can be done in HDInsight, Azure Machine
Learning, or on-premises.
Score in HDInsight
To score in HDInsight, write an R function that calls your model to make predictions for a new data file that you've
loaded to your storage account. Then save the predictions back to the storage account. You can run the routine on-
demand on the edge node of your cluster or by using a scheduled job.
Score in Azure Machine Learning (AML )
To score using an AML web service, use the open source Azure Machine Learning R package known as AzureML to
publish your model as an Azure web service. For convenience, this package is pre-installed on the edge node. Next,
use the facilities in Machine Learning to create a user interface for the web service, and then call the web service as
needed for scoring.
If you choose this option, you need to convert any ScaleR model objects to equivalent open-source model objects
for use with the web service. Use ScaleR coercion functions, such as [Link]() for ensemble-based
models, for this conversion.
Score on-premises
To score on-premises after creating your model, you can serialize the model in R, download it, de-serialize it, and
then use it for scoring new data. You can score new data by using the approach described earlier in Scoring in
HDInsight or by using DeployR.
Next steps
To learn more about how to use R Server with HDInsight clusters, see the following topics:
Getting started with R Server on HDInsight
Add RStudio Server to HDInsight (if not installed during cluster creation)
Compute context options for R Server on HDInsight
Azure Storage options for R Server on HDInsight
Compute context options for R Server on HDInsight
8/16/2017 • 4 min to read • Edit Online
Microsoft R Server on Azure HDInsight provides the latest capabilities for R-based analytics. It uses data that's
stored in HDFS in a container in your Azure Blob storage account, a Data Lake store or the local Linux file system.
Since R Server is built on open source R, the R-based applications you build can leverage any of the 8000+ open
source R packages. They can also leverage the routines in ScaleR, Microsoft’s big data analytics package that's
included with R Server.
The edge node of a cluster provides a convenient place to connect to the cluster and run your R scripts. With an
edge node, you have the option of running ScaleR’s parallelized distributed functions across the cores of the edge
node server. You also have the option to run them across the nodes of the cluster by using ScaleR’s Hadoop Map
Reduce or Spark compute contexts.
Assuming that you’d like parallelized execution for the purposes of performance, then there are three options.
Which option you choose depends on the nature of your analytics work, and the size and location of your data.
> ?rxSetComputeContext
You can also refer to the “ScaleR Distributed Computing Guide” that's available from the R Server MSDN library.
Next steps
In this article, you learned how to create a new HDInsight cluster that includes R Server. You also learned the
basics of using the R console from an SSH session. Now you can read the following articles to discover other ways
of working with R Server on HDInsight:
Overview of R Server for Hadoop
Get started with R Server for Hadoop
Add RStudio Server to HDInsight (if not added during cluster creation)
Azure Storage options for R Server on HDInsight
Azure Storage solutions for R Server on HDInsight
8/16/2017 • 6 min to read • Edit Online
Microsoft R Server on HDInsight has a variety of storage solutions to persist data, code, or objects that contain
results from analysis. These include the following options:
Azure Blob
Azure Data Lake Storage
Azure File storage
You also have the option of accessing multiple Azure storage accounts or containers with your HDI cluster. Azure
File storage is a convenient data storage option for use on the edge node that enables you to mount an Azure
Storage file share to, for example, the Linux file system. But Azure File shares can be mounted and used by any
system that has a supported OS such as Windows or Linux.
When you create an Hadoop cluster in HDInsight, you specify either an Azure storage account or a Data Lake
store. A specific storage container from that account holds the file system for the cluster that you create (for
example, the Hadoop Distributed File System). For more information and guidance, see:
Use Azure storage with HDInsight
Use Data Lake Store with Azure HDInsight clusters.
For more information on the Azure storage solutions, see Introduction to Microsoft Azure Storage.
For guidance on selecting the most appropriate storage option to use for your scenario, see Deciding when to use
Azure Blobs, Azure Files, or Azure Data Disks
WARNING
For performance purposes, the HDInsight cluster is created in the same data center as the primary storage account that you
specify. Using a storage account in a different location than the HDInsight cluster is not supported.
1. Create an HDInsight cluster with a storage account name of storage1 and a default container called
container1.
2. Specify an additional storage account called storage2.
3. Copy the [Link] file to the /share directory, and perform analysis on that file.
4. In R code, set the name node to default, and set your directory and file to process.
myNameNode <- "default"
myPort <- 0
All the directory and file references point to the storage account
wasb://container1@[Link]. This is the default storage account that's associated with
the HDInsight cluster.
Now, suppose you want to process a file called [Link] that's located in the /private directory of container2
in storage2.
In your R code, point the name node reference to the storage2 storage account.
All of the directory and file references now point to the storage account
wasb://container2@[Link]. This is the Name Node that you’ve specified.
You have to configure the /user/RevoShare/ directory on storage2 as follows:
The following commands are used to configure the Data Lake storage account with the RevoShare directory and
add the sample .csv file from the previous example:
hadoop fs -mkdir adl://[Link]/user
hadoop fs -mkdir adl://[Link]/user/RevoShare
hadoop fs -mkdir adl://[Link]/user/RevoShare/<user>
Next steps
Now that you understand the Azure storage options, use the following links to discover ways of getting data
science tasks done with R Server on HDInsight.
Overview of R Server on HDInsight
Get started with R server on Hadoop
Add RStudio Server to HDInsight (if not added during cluster creation)
Compute context options for R Server on HDInsight
Submit Jobs from R Tools for Visual Studio
8/16/2017 • 4 min to read • Edit Online
Overview
R Tools for Visual Studio (RTVS) is a free, open-source extension for the Community (free), Professional, and
Enterprise editions of both Visual Studio 2017, as well as Visual Studio 2015 Update 3 or higher. Most of the critical
features of RStudio are included in RTVS, with more being added as the tool matures. If there is a missing feature
that you'd like included in RTVS, consider filling out the RTVS survey.
RTVS enhances your R workflow by offering tools such as the R Interactive window (REPL), intellisense (code
completion), plot visualization through R libraries such as ggplot2 and ggviz, R code debugging, and more.
When installing the tools for Visual Studio 2017, make sure you select the R language support, Runtime
support for R development, and Microsoft R Client options after selecting the Data science and analytical
applications workload.
You will need to have public and private keys set up to use SSH with HDInsight for authentication.
To run the RevoScaleR and RxSpark functions, you will need to install R Server on your machine.
To create a compute context that runs RevoScaleR functions from your local client to your HDInsight cluster, you
will need to install PuTTY.
If you desire, apply the Data Science Settings to your Visual Studio environment, which provides a new layout for
your workspace that makes it easier to work with the R tools. You do this by going to the new R Tools menu item,
then selecting Data Science Settings...
Your workspace will now have a new layout optimized for working with R in Visual Studio. Refer to the screenshot
in the next section to see the layout.
To revert to other Visual Studio settings later on, first use the Tools > Import and Export Settings command,
selecting Export selected environment settings, and specifying a file name. To restore those settings, use
the same command and select Import selected environment settings. You can also use the same
commands if you change the data scientist layout and want to return to it later on, rather than using the Data
Science Settings command directly.
1. Paste the following code into the R Interactive window in Visual Studio, altering the values of the setup variables
to match your environment:
# Setup variables that connect the compute context to your HDInsight cluster
mySshHostname <- '[Link] ' # HDI secure shell hostname
mySshUsername <- 'sshuser' # HDI SSH username
mySshClientDir <- "C:\\Program Files (x86)\\PuTTY"
mySshSwitches <- '-i C:\\Users\\azureuser\\[Link]' # Path to your private ssh key
myHdfsShareDir <- paste("/user/RevoShare", mySshUsername, sep = "/")
myShareDir <- paste("/var/RevoShare", mySshUsername, sep = "/")
mySshProfileScript <- "/usr/lib64/microsoft-r/3.3/hadoop/[Link]"
# Set the current compute context as the Spark compute context defined above
rxSetComputeContext(mySparkCluster)
1. Now that the compute context has been set to your cluster, execute the following commands in the R Interactive
window:
1. Select the default storage account for your cluster, making note of the container/directory name.
2. Select Containers from the left-hand menu on your storage account blade.
1. Select your cluster's container name, browse to the user folder (you might have to click Load more at the
bottom of the list), then select RevoShare, then newUser. The [Link] file should be displayed in the
newUser folder.
1. Make sure you stop your Spark context. You cannot run multiple contexts at once:
rxStopEngine(mySparkCluster)
Next steps
In this article, we've walked through the steps to use R Tools for Visual Studio, and how to create a compute context
that allows you to execute commands on your HDInsight cluster.
Learn more about compute context options for R Server on HDInsight.
Walk through an example of combining ScaleR and SparkR for airline flight delay predictions.
Read about an alternative way of submitting R jobs, using R Studio Server
Submit Jobs from R Studio Server
8/16/2017 • 5 min to read • Edit Online
R Studio Server is a popular, web-based integrated development environment (IDE) for developing and executing R
scripts with R Server on an HDInsight cluster. It includes several features to speed up and ease development, such
as a syntax-highlighting editor that supports direct code execution, a console for interactively running R
commands, a workspace to view objects in the global environment, and much more.
To open R Studio Server from your HDInsight cluster in Azure, navigate to the Overview pane, and click on R
Server dashboards.
You will be prompted twice to enter a password. The first prompt is displayed as a popup by your browser, in
which you need to enter your cluster login credentials.
The second login prompt will ask for your R Studio user credentials. Supply the SSH login credentials here.
After successfully logging in, you should see the R Studio web interface.
Install R Studio Server
If the R Studio Server option is not available on the cluster dashboard, as outlined above, you must run the R
Studio Server install script, following these instructions.
Please note, R Studio community edition for R Server is automatically installed when you check the option to
install it when provisioning your R cluster as shown in the screenshot above.
1. Enter the following code to install the ggplot2 package, plot random data on the chart, build a linear regression
model, and compare actuals to predictions. Refer to the detailed comments to understand each step.
# ggplot2 contains a dataset called diamonds. Make this dataset available using the data() function.
data(diamonds, package = "ggplot2")
# Create a listing of all objects in the "global environment". Look for "diamonds" in the results.
ls()
# Now investigate the structure of diamonds, a data frame with 53,940 observations
str(diamonds)
### Plots in R
# R has three systems for static graphics: base graphics, lattice and ggplot2.
# This example uses ggplot2
# Now, build a simple regression model, examine the results of the model and plot the points and the
regression line.
# Build the model. log of price explained by log of carat. This illustrates how linear regression works.
Later we fit a model that includes the remaining variables
Later we fit a model that includes the remaining variables
# It is easy to get regression diagnostic plots. The same plot function that plots points either with a
formula or with the coordinates also has a "method" for dealing with a model object.
par(mfrow = c(2, 2)) # Set up for multiple plots on the same figure.
plot(model, col = "blue")
par(mfrow = c(1, 1)) # Rest plot layout to single plot on a 1x1 grid
# Finally, let's look at the model object. R packs everything that goes with the model, e.g. the formula
and results into the object. You can pick out what you need by indexing into the model object.
str(model)
model$coefficients # note this is the same as coef(model)
summary(model)
# R-squared = 0.9824, i.e. model explains 98.2% of variance, i.e. a better model than previously
# Inspect predictions
head(predicted_values)
1. Click the Save button on top of the script window. When prompted, enter a name for your script, as well as
location.
1. Execute entire script by entering Ctrl+Alt+R ( Command+Alt+R on Mac), through the menu by going to Code,
Run Region, Run All. As the job executes, you will see information output within the Console beneath your
script.
1. When execution is complete, the output of our graph will be displayed within the Plots tab. You may also view
the environment data of the job within the Environment tab. Click on the table icon next to one of the data
elements within the environment tab to view the data.
1. View a nicely formatted report that includes all of the R commands, in-line with the output of each segment, by
going to File, Compile Notebook... in the menu. There are a few options in the dropdown menu within the
Compile Notebook from R Script dialog window, including HTML. Below is a sample portion of the compiled
notebook generated from the script executed in this exercise.
Next steps
In this article, we've shown how easy it is to execute R scripts through the web-based R Studio Server.
Learn how to install R Studio Server if you didn't select the option to install it when provisioning your cluster.
Walk through an example of combining ScaleR and SparkR for airline flight delay predictions.
Learn about using R Tools for Visual Studio as an alternative to submitting jobs, as well as the nice features it
offers, such as debugging and intellisense (code completion).
What is Spark Streaming?
8/16/2017 • 9 min to read • Edit Online
Spark Streaming enables you to implement scalable, high-throughput, fault-tolerant applications for the
processing of data streams. You can run your Spark Streaming applications on HDInsight Spark clusters, and
connect it to process data from a variety of sources such as Azure Event Hubs, Azure IoT Hub, Kafka, Flume,
Twitter, ZeroMQ, raw TCP sockets or even by monitoring the HDFS filesystem for changes.
Spark Streaming creates a long running job during which you are able to apply transformations to the data (such
as map, reduce, join and extract data by windows of time) and then push out the results to filesystems, databases,
dashboards and the console.
Spark Streaming takes a micro-batch approach to how it processes data. This means that it must first wait to
collect a time-defined batch of events (usually configred in the range of less than a second to a few seconds),
before it sends the batch of events on for processing. This is in contrast to approaches that would receive a single
event and process that single event immediately. The benefit of the micro-batch approach, as you will see, is it lets
more efficiently process data that is rapidly ingested into your solution and gives you an abstraction that makes
applying aggregate calculations on the events a little easier.
The design goals of Spark Streaming include low latency (measured in seconds) and linear scalability. However,
what sets Spark Streaming apart are its support for fault tolerance with the guarantee that any given event would
be processed exactly once, even in the face of a node failure. Additionally, Spark Streaming is integrated with the
Spark core API, giving Spark developers a familiar programming model and new developers one less new
framework to learn when first starting with Spark.
Introducing the DStream
Spark Streaming represents a continous stream of data using a discretized stream or DStream. This DStream can
be created from input sources like Event Hubs or Kafka, or by applying transformation on another DStream.
The DStream represents a few layers of abstraction on top of the raw event data. To understand how they work, it
helps to build up a DStream from a single event.
Start with a single event, say a temperature reading from a connected thermostat. When this event arrives at your
Spark Streaming application, the first thing that happens is the event is stored in a reliable way- it is replicated so
that multiple nodes have a copy of your event. This ensures that the failure of any single node will not result in the
loss of your event. Spark core has a data structure that distributes data across multiple nodes in the cluster, where
each node generally maintains its data completely in-memory for best performance. This data structure is called a
resilient distributed dataset or RDD. The temperature reading event will be stored in an RDD.
Each RDD represents events collected over some user defined timeframe called the batch interval. Everytime the
batch interval elapses a new RDD is produced that contains all the data in the interval of time that just completed.
It is this continuous set of RDD's that are collected into a DStream. So for example, if the batch interval was
configured to be 1 second long, your DStream emits a batch every second containing one RDD that contains all
the data ingested during that second. When processing the DStream, the temperature event would appear in one
of these batches. A Spark Streaming application that processes these events, processes the batches that contains
the events and ultimately acts on the data stored in the RDD each batch contains.
Create a DStream
Using the StreamingContext instance you created, create an input DStream for your input source. In this case, we
are opening watching for the appearance of new files in default storage attached to the HDInsight cluster.
Apply transformations
You implement the processing by applying transformations on the DStream. Our application will receive one line
of text at a time from the file, split each line into words, and then follows the map reduce pattern to count the
number of times each word appears.
Output results
Push the transformation results out to the destination systems by applying output operations. In this case, we
show the result of each run thru the computation in the console output.
[Link]()
[Link]()
[Link]()
For details on the Spark Stream API, along with the event sources, transformations and output operations it
supports see Spark Streaming Programming Guide.
Here is another sample application that is completely self-contained that you can run inside a Jupyter Notebook. In
the example below, we create a mock data source in the class DummySource that outputs the value of a counter
and the current time in milliseconds every 5 seconds. We create a new StreamingContext object that has a batch
interval of 30 seconds. Every time a batch is created, it examines the RDD produced, converts it to a Spark
DataFrame and creates a temporary table over the DataFrame.
class DummySource extends [Link][(Int, Long)]
([Link].MEMORY_AND_DISK_2) {
def onStop() { }
// Set the active SQLContext so that we can access it statically within the foreachRDD
[Link]([Link])
// Access the SQLContext and create a table called demo_numbers we can query
val _sqlContext = [Link]([Link])
_sqlContext.createDataFrame(rdd).toDF("value", "time")
.registerTempTable("demo_numbers")
}
We can then query the DataFrame periodically to see the current set of values present in the batch. In this case, we
use the following SQL query.
%%sql
SELECT * FROM demo_numbers
VALUE TIME
10 1497314465256
11 1497314470272
12 1497314475289
13 1497314480310
VALUE TIME
14 1497314485327
15 1497314490346
In the above expect six values in the typical case, because the DummySource creates a value every 5 seconds, and
we emit a batch every 30 seconds.
Sliding Windows
If you want to perform aggregate calculations on your DStream over some time period, for example to get an
average temperature over the last 2 seconds, you can use the sliding window operations included with Spark
Streaming. A sliding window is defined as having a duration (referred to as the window length) and the interval at
which the window's content are evaluated (referred toas the slide interval).
These sliding windows can overlap, for example you can define a window with a length of 2 seconds, that slides
every 1 second. This means every time you perform an aggregation calculation, the window will include data from
the last 1 second of the previous window as well as any new data in the next 1 second.
By way of example, we can enhance the code that uses the DummySource above to first collect the batches into a
window with a 1 minute duration, that slides by 1 minute as well.
// Set the active SQLContext so that we can access it statically within the foreachRDD
[Link]([Link])
// Access the SQLContext and create a table called demo_numbers we can query
val _sqlContext = [Link]([Link])
_sqlContext.createDataFrame(rdd).toDF("value", "time")
.registerTempTable("demo_numbers")
}
After the first minute, this will yield 12 entries or six entries from each of the two batches collected in the window.
VALUE TIME
1 1497316294139
2 1497316299158
3 1497316304178
VALUE TIME
4 1497316309204
5 1497316314224
6 1497316319243
7 1497316324260
8 1497316329278
9 1497316334293
10 1497316339314
11 1497316344339
12 1497316349361
The sliding window functions available in the Spark Streaming API include window, countByWindow,
reduceByWindow and countByValueAndWindow. For details on these functions see Transformations on DStreams.
Checkpointing
In order to deliver resiliency and fault tolerance, Spark Streaming relies on checkpointing to insure that stream
processing can continue uninterrupted, even in the face of node failures. In HDInsight, Spark creates checkpoints
to durable storage (Azure Storage or Data Lake Store). These checkpoints store the metadata about the streaming
application- such as the configuration, the operations defined by the application and any batches that were
queued but not yet processed. In some cases, the checkpoints will also include the saving of the data in the RDD's
to shorten the time it takes to rebuild the state of the data from what is presend in the RDD's managed by Spark.
See also
Create an Apache Spark Cluster in HDInsight
Spark Streaming Programming Guide
Launch Spark jobs remotely with LIVY
What is Spark Structured Streaming?
8/16/2017 • 10 min to read • Edit Online
Spark Structured Streaming enables you to implement scalable, high-throughput, fault-tolerant applications for the
processing of data streams without having to build programs with specialized streaming constructs in mind.
Structured Streaming is built upon the Spark SQL engine, and improves upon the constructs from Spark SQL Data
Frames and Datasets that enable you to write streaming queries in the same way you would write batch queries.
You can run your Structured Streaming applications on HDInsight Spark clusters, and connect it to process data in
a streaming fashion from Kafka, a TCP socket (for debugging purposes), Azure Storage and Azure Data Lake Store.
The latter two options which rely on external storage services enable you to watch for new files added into storage
and process their content as if it were streamed.
Structured Streaming creates a long running query during which you are able to apply operations to the input
data- such as selection, projection, aggregation, windowing and joining the streaming DataFrame with reference
DataFrames and then output the result to file storage (Azure Storage Blobs or Data Lake Store) or to any datastore
via custom code (such as SQL Database or Power BI). It also provides convenient output to the console which is
useful when debugging locally and to an in-memory table which lets you peek at the data generated when
debugging in HDInsight.
NOTE
Spark Structured Streaming is intended to be the replacement for Spark Streaming (DStreams). This means going forward,
Structured Streaming will receive enhancments and maintenance, whereas DStreams will be in maintenance mode only. It is
important to note, however, that Structured Streaming is currently not as feature complete as DStreams when it comes to
the sources and sinks that it supports out of the box, so you should evaluate your requirements first before choosing the
appropriate Spark stream processing option.
Streams as Tables
Spark Structured Streaming takes the perspective that a stream of data can be represented as a table that is
unbounded in height- in other words it continues to grow as new data arrives. This Input Table is continously
processed by a long running query, and the results flushed out to an Output Table. This concept is best explained
with the following illustration:
In Structured Streaming data arrives at the system and is immediately ingested into an Input Table. You write
queries (using the DataFrame and Dataset APIs) that perform operations against this Input Table. The query output
yields another table, called the Results Table. The Results Table contains results of your query from which you draw
any data you would send to an external datastore (such a relational database). The timing of when data is
processed from the Input Table is controlled by the trigger interval. By default Structured Streaming tries to
process the data as soon as it arrives. In practice this means as soon as it is done processing the run of the previous
query, it starts another processing run against any newly received data. However, you can also configure the
trigger to run on a longer interval, so that the streaming data is processed according to time-based batches.
With regards to the output, the data in the Results Tables may be completely refreshed everytime there is new data
so that it includes all of the output data since the streaming query began, or it may only contain just the data that is
new since the last time the query was processed. This behavior is controlled by the output mode. Let's look at
examples of each of these modes in turn.
Append Mode
In Append Mode, only the rows added to the Results Table since the last query run will be present in the Results
Table and written to external storage. This is best explained by example. Suppose you have the simplest form of
query that just copies all data from the Input Table to the Results Table unaltered. Every time a trigger happens, the
new data is processed and the rows representing that new data appear in the Results Table.
Consider a scenario where you are processing telemetry from temperature sensors, like thermostats. Assume the
first trigger processed one event at time 00:01 for device 1 having a temperature reading of 95 degrees. In the first
trigger of the query, only the row with time 00:01 would appear in the Results Table. Consider what happens at
time 00:02 when another event arrives. In this case, the only new row would be the row with time 00:02 and so the
Results Table would contain only one row- the one with the time of 00:02 as shown in the illustration.
Of course, this is a trivial example query. Most likely when using the Append Mode in this way, your query would
be applying projections (e.g., selecting the columns it cares about), filtering (e.g., picking only rows that match
certain conditions) or joining (e.g., augmenting the data with data from a static lookup table). The Append Mode is
useful, because it makes it easy to push only the relevant, new data points out to external storage.
Complete Mode
Now let's consider the same scenario, but apply the Complete Mode. In the Complete Mode, the entire Output
Table is refreshed on every trigger so that it includes data not just from the most recent trigger run, but from all
runs. In the trivial example we showed earlier, we could use the Complete Mode to copy the data unaltered from
the Input Table to the Results Table. On every trigger run, the new result rows would appear along with all the
previous rows. Naturally, this means that the Output Results table would end up storing all of the data collected
since the query began- you would eventually run out of memory. This is why Complete Mode is intended for use
with aggregate queries, which effectively summarize the data in some way and on every trigger the Results Table is
updated with a new summary.
Let's use the following illustration as an example. Assume so far we have already processed 5 seconds worth of
data and are looking at the result of processing the data for the sixth second. In our Input Table, we have collected
events for time 00:01 and time 00:03. Let's assume the goal of our query is to tell us the average temperature of
the device every five seconds. The implementation of this query has to apply an aggregate that takes all of the
values that fall within each 5 second window of time, and averages the temperature and produces a row that
represents the average temperature for that interval. At the end of the first 5 second window, we have two tuples
that appear in the interval: (00:01, 1, 95) and (00:03, 1, 98). So for the window 00:00-00:05 we get a tuple with the
average temperature of 96.5 degrees (the average of 95 and 98 is 96.5). Now let's consider what happens at the
next 5 second window. In that window we only have one data point at time 00:06, to the resulting average
temperature is 98 degrees. At time 00:10, when we use the Complete Mode, the Results Table will have the rows
for both windows 00:00-00:05 and 00:05-00:10 because the query will output all the aggregated rows, not just the
new ones. In other words, the Results Table will continue to grow as new windows are added.
It is important to realize that not all queries using Complete Mode will always cause the table to grow without
bounds- and this is where Complete Mode is ideal. Consider in the above example that instead of averaging the
temperature by time window, we averaged instead by the device ID. The Result Table would contain a fixed number
of rows (one per device) with the average temperature for the device across all data points received from that
device. As new temperatures are received, the Results Table would be updated so that the averages in the table are
always current.
{"time":1469501107,"temp":"95"}
{"time":1469501147,"temp":"95"}
{"time":1469501202,"temp":"95"}
{"time":1469501219,"temp":"95"}
{"time":1469501225,"temp":"95"}
These JSON files are stored in the "temps" subfolder, underneath the container used by the HDInsight cluster.
Define the input source
First you need to configure a DataFrame that describes the source of the data and any settings required by that
source. In our example, we draw from the JSON files in Azure Storage and apply a schema to them at read time.
import [Link]._
import [Link]._
//This is the cluster-local path to the folder containing the JSON files
val inputPath = "/temps/"
//Define the schema of the JSON files as having the "time" of type TimeStamp and the "temp" field of type
String
val jsonSchema = new StructType().add("time", TimestampType).add("temp", StringType)
//Create a Streaming DataFrame by calling readStream and configuring it with schema and path
val streamingInputDF = [Link](jsonSchema).json(inputPath)
For details on the Spark Structured Stream API, along with the input data sources, operations and output sinks it
supports see Spark Structured Streaming Programming Guide.
See also
Create an Apache Spark Cluster in HDInsight
Spark Structured Streaming Programming Guide
Launch Spark jobs remotely with LIVY
Apache Spark streaming (DStream) example with
Kafka (preview) on HDInsight
8/16/2017 • 3 min to read • Edit Online
Learn how to use Spark Apache Spark to stream data into or out of Apache Kafka on HDInsight using DStreams.
This example uses a Jupyter notebook that runs on the Spark cluster.
NOTE
The steps in this document create an Azure resource group that contains both a Spark on HDInsight and a Kafka on
HDInsight cluster. These clusters are both located within an Azure Virtual Network, which allows the Spark cluster to directly
communicate with the Kafka cluster.
When you are done with the steps in this document, remember to delete the clusters to avoid excess charges.
NOTE
Though Kafka itself is limited to communication within the virtual network, other services on the cluster such as SSH and
Ambari can be accessed over the internet. For more information on the public ports available with HDInsight, see Ports and
URIs used by HDInsight.
While you can create an Azure virtual network, Kafka, and Spark clusters manually, it's easier to use an Azure
Resource Manager template. Use the following steps to deploy an Azure virtual network, Kafka, and Spark clusters
to your Azure subscription.
1. Use the following button to sign in to Azure and open the template in the Azure portal.
The Azure Resource Manager template is located at
[Link]
[Link].
WARNING
To guarantee availability of Kafka on HDInsight, your cluster must contain at least three worker nodes. This template
creates a Kafka cluster that contains three worker nodes.
This template creates an HDInsight 3.6 cluster for both Kafka and Spark.
2. Use the following information to populate the entries on the Custom deployment blade:
Resource group: Create a group or select an existing one. This group contains the HDInsight cluster.
Location: Select a location geographically close to you.
Base Cluster Name: This value is used as the base name for the Spark and Kafka clusters. For
example, entering hdi creates a Spark cluster named spark-hdi__ and a Kafka cluster named kafka-
hdi.
Cluster Login User Name: The admin user name for the Spark and Kafka clusters.
Cluster Login Password: The admin user password for the Spark and Kafka clusters.
SSH User Name: The SSH user to create for the Spark and Kafka clusters.
SSH Password: The password for the SSH user for the Spark and Kafka clusters.
3. Read the Terms and Conditions, and then select I agree to the terms and conditions stated above.
4. Finally, check Pin to dashboard and then select Purchase. It takes about 20 minutes to create the clusters.
Once the resources have been created, you are redirected to a blade for the resource group that contains the
clusters and web dashboard.
IMPORTANT
Notice that the names of the HDInsight clusters are spark-BASENAME and kafka-BASENAME, where BASENAME is the
name you provided to the template. You use these names in later steps when connecting to the clusters.
Since the steps in this document create both clusters in the same Azure resource group, you can delete the
resource group in the Azure portal. Deleting the group removes all resources created by following this document,
the Azure Virtual Network, and storage account used by the clusters.
Next steps
In this example, you learned how to use Spark to read and write to Kafka. Use the following links to discover other
ways to work with Kafka:
Get started with Apache Kafka on HDInsight
Use MirrorMaker to create a replica of Kafka on HDInsight
Use Apache Storm with Kafka on HDInsight
Apache Spark streaming: Process data from Azure
Event Hubs with Spark cluster on HDInsight
8/16/2017 • 15 min to read • Edit Online
In this article, you create an Apache Spark streaming sample that involves the following steps:
1. You use a standalone application to ingest messages into an Azure Event Hub.
2. With two different approaches, you retrieve the messages from Event Hub in real-time using an
application running in Spark cluster on Azure HDInsight.
3. You build streaming analytic pipelines to persist data to different storage systems, or get insights from
data on the fly.
Prerequisites
An Azure subscription. See Get Azure free trial.
An Apache Spark cluster on HDInsight. For instructions, see Create Apache Spark clusters in Azure
HDInsight.
NOTE
You should select the same Location as your Apache Spark cluster in HDInsight to reduce latency and costs.
8. Back in the namespace blade (not the specific Event Hub blade), click Shared access policies, and then
click RootManageSharedAccessKey.
9. Click the copy button to copy the RootManageSharedAccessKey primary key and connection string to
the clipboard. Save these to use later in the tutorial.
<repository>
<id>spark-eventhubs</id>
<url>[Link]
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
You can then add the following dependency to your project to take the pre-released version.
Maven Dependency
SBT Dependency
// [Link]
libraryDependencies += "[Link]" % "spark-streaming-eventhubs_2.11" % "2.0.4"
ssc
}
if ([Link] != 8) {
println("Usage: program progressDir PolicyName PolicyKey EventHubNamespace EventHubName" +
" BatchDuration(seconds) Spark_Checkpoint_Directory maxRate")
[Link](1)
}
[Link]()
[Link]()
}
In the above example, eventhubParameters are the parameters specific to a single EventHubs instance and you
have to pass it to the createDirectStreams API which constructs a Direct DStream object mapping to a Event
Hubs namespace. Over the Direct DStream object, you can call any DStream API provided by Spark Streaming
API framework. In this example, we calculate the frequency of each word within the last 3 micro batch intervals.
Receiver-based Connection
A Spark streaming example application written in Scala, which receives events and route the to different
destinations, is available at [Link] Follow the
steps below to update the application for your Event Hub configuration and create the output jar.
1. Launch IntelliJ IDEA and from the launch screen select Check out from Version Control and then click
Git.
2. In the Clone Repository dialog box, provide the URL to the Git repository to clone from, specify the
directory to clone to, and then click Clone.
3. Follow the prompts till the project is completely cloned. Press Alt + 1 to open the Project View. It should
resemble the following.
4. Make sure the application code is compiled with Java8. To ensure this, click File, click Project Structure,
and on the Project tab, make sure Project language level is set to 8 - Lambdas, type annotations, etc..
5. Open the [Link] and make sure the Spark version is correct. Under <properties> node, look for the
following snippet and verify the Spark version.
<[Link]>2.11.8</[Link]>
<[Link]>2.11.8</[Link]>
<[Link]>2.11</[Link]>
<[Link]>2.0.0</[Link]>
6. The application requires a dependency jar called JDBC driver jar. This is required to write the messages
received from Event Hub into an Azure SQL database. You can download this jar (v4.1 or later) from here.
Add reference to this jar in the project library. Perform the following steps:
a. From IntelliJ IDEA window where you have the application open, click File, click Project Structure, and
then click Libraries.
b. Click the add icon ( ), click Java, and then navigate to the location where you downloaded the
JDBC driver jar. Follow the prompts to add the jar file to the project library.
c. Click Apply.
7. Create the output jar file. Perform the following steps.
a. In the Project Structure dialog box, click Artifacts and then click the plus symbol. From the pop-
up dialog box, click JAR, and then click From modules with dependencies.
b. In the Create JAR from Modules dialog box, click the ellipsis ( ) against the Main Class.
c. In the Select Main Class dialog box, select any of the available classes and then click OK.
d. In the Create JAR from Modules dialog box, make sure that the option to extract to the target
JAR is selected, and then click OK. This creates a single JAR with all dependencies.
e. The Output Layout tab lists all the jars that are included as part of the Maven project. You can
select and delete the ones on which the Scala application has no direct dependency. For the
application we are creating here, you can remove all but the last one (spark-streaming-data-
persistence-examples compile output). Select the jars to delete and then click the Delete icon (
).
Make sure Build on make box is selected, which ensures that the jar is created every time the
project is built or updated. Click Apply.
f. In the Output Layout tab, right at the bottom of the Available Elements box, you have the SQL
JDBC jar that you added earlier to the project library. You must add this to the Output Layout tab.
Right-click the jar file, and then click Extract Into Output Root.
The Output Layout tab should now look like this.
In the Project Structure dialog box, click Apply and then click OK.
g. From the menu bar, click Build, and then click Make Project. You can also click Build Artifacts to
create the jar. The output jar is created under \classes\artifacts.
{ "file":"wasb:///example/jars/[Link]",
"className":"[Link]", "args":["--eventhubs-
namespace", "mysbnamespace", "--eventhubs-name", "myeventhub", "--policy-name", "myreceivepolicy", "--
policy-key", "<put-your-key-here>", "--consumer-group", "$default", "--partition-count", 10, "--batch-
interval-in-seconds", 20, "--checkpoint-directory", "/EventCheckpoint", "--event-count-folder",
"/EventCount/EventCount10"], "numExecutors":20, "executorMemory":"1G", "executorCores":1,
"driverMemory":"2G" }
NOTE
You do not need to create the output folders (EventCheckpoint, EventCount/EventCount10) that are used as parameters.
The streaming application creates them for you.
When you run the command, you should see an output like the following:
Make a note of the batch ID in the last line of the output (in this example it is '1'). To verify that the application
runs successfully, you can look at your Azure storage account associated with the cluster and you should see the
/EventCount/EventCount10 folder created there. This folder should contain blobs that captures the number of
events processed within the time period specified for the parameter batch-interval-in-seconds.
The Spark streaming application will continue to run until you kill it. To do so, use the following command:
Run the applications to receive the events into an Azure Storage Blob as JSON
Open a command prompt, navigate to the directory where you installed CURL, and run the following command
(replace username/password and cluster name):
{ "file":"wasb:///example/jars/[Link]",
"className":"[Link]", "args":["--
eventhubs-namespace", "mysbnamespace", "--eventhubs-name", "myeventhub", "--policy-name", "myreceivepolicy",
"--policy-key", "<put-your-key-here>", "--consumer-group", "$default", "--partition-count", 10, "--batch-
interval-in-seconds", 20, "--checkpoint-directory", "/EventCheckpoint", "--event-count-folder",
"/EventCount/EventCount10", "--event-store-folder", "/EventStore10"], "numExecutors":20,
"executorMemory":"1G", "executorCores":1, "driverMemory":"2G" }
The parameters are similar to what you specified for the text output, in the previous step. Again, you do not need
to create the output folders (EventCheckpoint, EventCount/EventCount10) that are used as parameters. The
streaming application creates them for you.
After you run the command, you can look at your Azure storage account associated with the cluster and you
should see the /EventStore10 folder created there. Open any file prefixed with part- and you should see the
events processed in a JSON format.
Run the applications to receive the events into a Hive table
To run the Spark streaming application that streams events into a Hive table you need some additional
components. These are:
[Link]
[Link]
[Link]
[Link]
The .jar files are available on your HDInsight Spark cluster at /usr/hdp/current/spark-client/lib . The hive-
[Link] is available at /usr/hdp/current/spark-client/conf .
You can use WinScp to copy over these files from the cluster to your local computer. You can then use tools to
copy these files over to your storage account associated with the cluster. For more information on how to upload
files to the storage account, see Upload data for Hadoop jobs in HDInsight.
Once you have copied over the files to your Azure storage account, open a command prompt, navigate to the
directory where you installed CURL, and run the following command (replace username/password and cluster
name):
{ "file":"wasb:///example/jars/[Link]",
"className":"[Link]", "args":["--eventhubs-
namespace", "mysbnamespace", "--eventhubs-name", "myeventhub", "--policy-name", "myreceivepolicy", "--
policy-key", "<put-your-key-here>", "--consumer-group", "$default", "--partition-count", 10, "--batch-
interval-in-seconds", 20, "--checkpoint-directory", "/EventCheckpoint", "--event-count-folder",
"/EventCount/EventCount10", "--event-hive-table", "EventHiveTable10" ], "jars":
["wasb:///example/jars/[Link]", "wasb:///example/jars/[Link]",
"wasb:///example/jars/[Link]"], "files":["wasb:///example/jars/[Link]"],
"numExecutors":20, "executorMemory":"1G", "executorCores":1, "driverMemory":"2G" }
The parameters are similar to what you specified for the text output, in the previous steps. Again, you do not
need to create the output folders (EventCheckpoint, EventCount/EventCount10) or the output Hive table
(EventHiveTable10) that are used as parameters. The streaming application creates them for you. Note that the
jars and files option includes paths to the .jar files and the [Link] that you copied over to the storage
account.
To verify that the hive table was successfully created, you can SSH into the cluster and run Hive queries.
Once you are connected using SSH, you can run the following command to verify that the Hive table,
EventHiveTable10, is created.
show tables;
OK
eventhivetable10
hivesampletable
You can also run a SELECT query to view the contents of the table.
ZN90apUSQODDTx7n6Toh6jDbuPngqT4c
sor2M7xsFwmaRW8W8NDwMneFNMrOVkW1
o2HcsU735ejSi2bGEcbUSB4btCFmI1lW
TLuibq4rbj0T9st9eEzIWJwNGtMWYoYS
HKCpPlWFWAJILwR69MAq863nCWYzDEw6
Mvx0GQOPYvPR7ezBEpIHYKTKiEhYammQ
85dRppSBSbZgThLr1s0GMgKqynDUqudr
5LAWkNqorLj3ZN9a2mfWr9rZqeXKN4pF
ulf9wSFNjD7BZXCyunozecov9QpEIYmJ
vWzM3nvOja8DhYcwn0n5eTfOItZ966pa
Time taken: 4.434 seconds, Fetched: 10 row(s)
Run the applications to receive the events into an Azure SQL database table
Before running this step, make sure you have an Azure SQL database created. For instructions, see Create a SQL
database in minutes. To complete this section, you need values for database name, database server name, and
the database administrator credentials as parameters. You do not need to create the database table though. The
Spark streaming application creates that for you.
Open a command prompt, navigate to the directory where you installed CURL, and run the following command:
curl -k --user "admin:mypassword1!" -v -H "Content-Type: application/json" -X POST --data
@C:\Temp\[Link] "[Link]
{ "file":"wasb:///example/jars/[Link]",
"className":"[Link]", "args":["--
eventhubs-namespace", "mysbnamespace", "--eventhubs-name", "myeventhub", "--policy-name", "myreceivepolicy",
"--policy-key", "<put-your-key-here>", "--consumer-group", "$default", "--partition-count", 10, "--batch-
interval-in-seconds", 20, "--checkpoint-directory", "/EventCheckpoint", "--event-count-folder",
"/EventCount/EventCount10", "--sql-server-fqdn", "<database-server-name>.[Link]", "--sql-
database-name", "mysparkdatabase", "--database-username", "sparkdbadmin", "--database-password", "<put-
password-here>", "--event-sql-table", "EventContent" ], "numExecutors":20, "executorMemory":"1G",
"executorCores":1, "driverMemory":"2G" }
To verify that the application runs successfully, you can connect to the Azure SQL database using SQL Server
Management Studio. For instructions on how to do that, see Connect to SQL Database with SQL Server
Management Studio. Once you are connected to the database, you can navigate to the EventContent table that
was created by the streaming application. You can run a quick query to get the data from the table. Run the
following query:
00046b0f-2552-4980-9c3f-8bba5647c8ee
000b7530-12f9-4081-8e19-90acd26f9c0c
000bc521-9c1b-4a42-ab08-dc1893b83f3b
00123a2a-e00d-496a-9104-108920955718
0017c68f-7a4e-452d-97ad-5cb1fe5ba81b
001KsmqL2gfu5ZcuQuTqTxQvVyGCqPp9
001vIZgOStka4DXtud0e3tX7XbfMnZrN
00220586-3e1a-4d2d-a89b-05c5892e541a
0029e309-9e54-4e1b-84be-cd04e6fce5ec
003333cf-874f-4045-9da3-9f98c2b4ea49
0043c07e-8d73-420a-9af7-1fcb94575356
004a11a9-0c2c-4bc0-a7d5-2e0ebd947ab9
See also
Overview: Apache Spark on Azure HDInsight
Design of Receiver-based Connection and Direct DStream
Scenarios
Spark with BI: Perform interactive data analysis using Spark in HDInsight with BI tools
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Website log analysis using Spark in HDInsight
Create and run applications
Create a standalone application using Scala
Run jobs remotely on a Spark cluster using Livy
Tools and extensions
Use HDInsight Tools Plugin for IntelliJ IDEA to create and submit Spark Scala applicatons
Use HDInsight Tools Plugin for IntelliJ IDEA to debug Spark applications remotely
Use Zeppelin notebooks with a Spark cluster on HDInsight
Kernels available for Jupyter notebook in Spark cluster for HDInsight
Use external packages with Jupyter notebooks
Install Jupyter on your computer and connect to an HDInsight Spark cluster
Manage resources
Manage resources for the Apache Spark cluster in Azure HDInsight
Track and debug jobs running on an Apache Spark cluster in HDInsight
Use Spark Structured Streaming with Kafka (preview)
on HDInsight
8/16/2017 • 4 min to read • Edit Online
Learn how to use Spark Structured Streaming to read data from Apache Kafka on Azure HDInsight.
Spark structured streaming is a stream processing engine built on Spark SQL. It allows you to express streaming
computations the same as batch computation on static data. For more information on Structured Streaming, see
the Structured Streaming Programming Guide [Alpha] at [Link].
IMPORTANT
This example used Spark 2.1 on HDInsight 3.6. Structured Streaming is considered alpha on Spark 2.1.
The steps in this document create an Azure resource group that contains both a Spark on HDInsight and a Kafka on
HDInsight cluster. These clusters are both located within an Azure Virtual Network, which allows the Spark cluster to directly
communicate with the Kafka cluster.
When you are done with the steps in this document, remember to delete the clusters to avoid excess charges.
NOTE
The Kafka service is limited to communication within the virtual network. Other services on the cluster, such as SSH and
Ambari, can be accessed over the internet. For more information on the public ports available with HDInsight, see Ports and
URIs used by HDInsight.
While you can create an Azure virtual network, Kafka, and Spark clusters manually, it's easier to use an Azure
Resource Manager template. Use the following steps to deploy an Azure virtual network, Kafka, and Spark clusters
to your Azure subscription.
1. Use the following button to sign in to Azure and open the template in the Azure portal.
IMPORTANT
The structured streaming notebook used in this example requires Spark on HDInsight 3.6. If you use an earlier
version of Spark on HDInsight, you receive errors when using the notebook.
2. Use the following information to populate the entries on the Custom deployment blade:
Resource group: Create a group or select an existing one. This group contains the HDInsight cluster.
Location: Select a location geographically close to you.
Base Cluster Name: This value is used as the base name for the Spark and Kafka clusters. For
example, entering hdi creates a Spark cluster named spark-hdi__ and a Kafka cluster named kafka-
hdi.
Cluster Login User Name: The admin user name for the Spark and Kafka clusters.
Cluster Login Password: The admin user password for the Spark and Kafka clusters.
SSH User Name: The SSH user to create for the Spark and Kafka clusters.
SSH Password: The password for the SSH user for the Spark and Kafka clusters.
3. Read the Terms and Conditions, and then select I agree to the terms and conditions stated above.
4. Finally, check Pin to dashboard and then select Purchase. It takes about 20 minutes to create the clusters.
Once the resources have been created, you are redirected to the resource group blade.
IMPORTANT
Notice that the names of the HDInsight clusters are spark-BASENAME and kafka-BASENAME, where BASENAME is the
name you provided to the template. You use these names in later steps when connecting to the clusters.
curl -u admin:$PASSWORD -G
"[Link] |
jq -r '["\(.host_components[].HostRoles.host_name):9092"] | join(",")'
NOTE
This example expects $PASSWORD to contain the password for the cluster login, and $CLUSTERNAME to contain the name of
the Kafka cluster.
This example uses the jq utility to parse data out of the JSON document.
[Link]
When prompted, enter the cluster login (admin) and password used when you created the cluster.
2. From the upper right side of the page, use the Upload button to upload the Stream-Tweets-
To_Kafka.ipynb file to the cluster. Select Open to start the upload.
3. Find the Stream-Tweets-To_Kafka.ipynb entry in the list of notebooks, and select Upload button beside it.
Next steps
Now that you have learned how to use Spark Structured Streaming, see the following documents to learn more
about working with Spark and Kafka:
How to use Spark streaming (DStream) with Kafka.
Start with Jupyter Notebook and Spark on HDInsight
Using Spark Structured Streaming on HDInsight to
process events from Event Hubs
8/15/2017 • 9 min to read • Edit Online
In this article you will learn to process real-time telemetry using Spark Structured Streaming. To accomplish this
you will perform the following high-level steps:
1. Provision an HDInsight cluster with Spark 2.1.
2. Provision an Event Hubs instance.
3. Compile and run on your local workstation a sample Event Producer application that generates events to send
to Event Hubs.
4. Use the Spark Shell to define and run a simple Spark Structured Streaming application.
Prerequisites
An Azure subscription. See Get Azure free trial.
Make sure you have the following installed on the computer where you run Event Producer application:
Oracle Java Development kit. You can install it from here.
Apache Maven. You can download it from here. Instructions to install Maven are available here.
7. Select Create.
3. In the Create Event Hub blade, enter the name "hub1" for your Event Hub.
4. Leave the remaining settings at their defaults. Note that your Event Hub will have 2 partitions (as set in
Partition Count).
5. Select Create.
6. On your Event Hub namespace blade, select Shared access policies from the side menu.
7. In the list of Shared Access Policies, select the RootManageSharedAccessKey.
8. Copy the value under Primary Key and paste it into a temporary text file, this value is your Policy Key. Also,
take note that the Policy Name is "RootManageSharedAccessKey".
9. Close the Policy blade and select Properties from the side menu.
10. The value under Name is the your namespace, take note of this value along with your Policy Key and Name.
Also, take note that the name of your Event Hub itself is "hub1".
mvn package
5. Within the shell or command prompt, navigate into the target directory that is created and contains the file
[Link] .
6. Next, you will need to build up the command line to run the Event Producer against your Event Hub. Do this
by replacing the values in the command as follows:
8. The command will start up and if your configuration is correct in a few moments you will see output related
to the events it is sending to your Event Hub, similar to the following:
9. Leave the Event Producer running while you continue on to the steps.
3. Follow the instructions displayed for connecting to your cluster via SSH from your local environment. In
general, this will mean running SSH as follows:
ssh sshuser@<yourclustername>-[Link]
4. Complete the login by providing the password you supplied when provisioning the cluster.
5. The application you will build requires the Spark Streaming Event Hubs package. To run the Spark Shell so
that it automatically retrieves this depedency from Maven Central, be sure the supply the packages switch
with the Maven coordinates as follows:
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version [Link].6.0.10-29
/_/
Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_131)
Type in expressions to have them evaluated.
Type :help for more information.
scala>
7. Copy the following code snippet into a text editor and modify it so it has the Policy Key and Namespace set
as appropriate for your Event Hub.
8. Paste the modified snippet into the waiting scala> prompt and press return. You should see output similar
to:
11. Next, author the query so that it writes its output to the Console. Do this by pasting the following into Spark
Shell and pressing return.
12. You should see some batches start with output similar to the following
-------------------------------------------
Batch: 0
-------------------------------------------
[Stage 0:> (0 + 2) / 2]
13. This will be followed by the ouput results of the processing of each microbatch of events.
-------------------------------------------
Batch: 0
-------------------------------------------
17/06/18 18:57:39 WARN TaskSetManager: Stage 1 contains a task of very large size (419 KB). The maximum
recommended task size is 100 KB.
+--------------------+------+---------+------------+---------+------------+----------+
| body|offset|seqNumber|enqueuedTime|publisher|partitionKey|properties|
+--------------------+------+---------+------------+---------+------------+----------+
|[7B 22 74 65 6D 7...| 0| 0| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 112| 1| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 224| 2| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 336| 3| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 448| 4| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 560| 5| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 672| 6| 1497734887| null| null| Map()|
|[7B 22 74 65 6D 7...| 784| 7| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 896| 8| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1008| 9| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1120| 10| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1232| 11| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1344| 12| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1456| 13| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1568| 14| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1680| 15| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1792| 16| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 1904| 17| 1497734888| null| null| Map()|
|[7B 22 74 65 6D 7...| 2016| 18| 1497734889| null| null| Map()|
|[7B 22 74 65 6D 7...| 2128| 19| 1497734889| null| null| Map()|
+--------------------+------+---------+------------+---------+------------+----------+
only showing top 20 rows
14. As new events arrive from the Event Producer, they will be processed by this Structured Streaming query.
15. Be sure to delete your HDInsight cluster when you are finished running this sample.
See also
This article showed how to author a Spark Streaming application that processed events from Event Hubs.
For more information on Spark Structured Streaming in HDInsight, see Spark Structured Streaming Overview
Creating highly available Spark Streaming jobs in
YARN
8/16/2017 • 12 min to read • Edit Online
Spark Streaming enables you to implement scalable, high-throughput, fault-tolerant applications for the processing
of data streams. Running Spark Streaming applications on a HDInsight Spark cluster, you can connect them to
process data from a variety of sources such as Azure Event Hubs, Azure IoT Hub, Kafka, Flume, Twitter, ZeroMQ,
raw TCP sockets or even by monitoring the HDFS filesystem for changes.
Spark Streaming creates long-running jobs during which you are able to apply transformations to the data and
then push out the results to filesystems, databases, dashboards and the console. It uses micro-batches to processes
data, by waiting to collect a time-defined batch of events (usually configred in the range of less than a second to a
few seconds), before it sends the batch of events on for processing. It supports fault tolerance with the guarantee
that any given event would be processed exactly once, even in the face of a node failure.
Understanding DStreams
Spark Streaming represents a continous stream of data using a discretized stream or DStream. This DStream can
be created from input sources like Event Hubs or Kafka, or by applying transformation on another DStream. When
an event arrives at your Spark Streaming application, this event is stored in a reliable way- it is replicated so that
multiple nodes have a copy of it. This ensures that the failure of any single node will not result in the loss of your
event.
Spark core uses RDDs (resiliant distributed datasets). RDDs distribute data across multiple nodes in the cluster,
where each node generally maintains its data completely in-memory for best performance. Each RDD represents
events collected over some user defined timeframe called the batch interval. Every time the batch interval elapses a
new RDD is produced that contains all the data in the interval of time that just completed. This continuous set of
RDDs are collected into a DStream. A Spark Streaming application processes micro-batches containing events, and
ultimately acts on the data stored in the RDD each batch contains.
Understanding Spark Structured Streaming Jobs
Spark Structured Streaming was introduced in Spark 2.0. It is a an analytic engine for streaming structured data.
Spark Structured Streaming shares the same set of APIs with the SparkSQL batching engine. As with Spark
Streaming, Spark Structured Streaming provides the ability to run computation over continuously arriving data and
uses a micro-batches streaming model. Spark Structured Streaming represents a stream of data as an unbounded
Input Table (heightwise) - in other words the table continues to grow as new data arrives. This Input Table is
continously processed by a long running query, and the results flushed out to an Output Table.
In Structured Streaming data arrives at the system and is immediately ingested into the Input Table. You write
queries that perform operations against this Input Table. The query output yields another table, called the Results
Table. The Results Table contains results of your query from which you draw any data you would send to an
external datastore (such a relational database). The timing of when data is processed from the Input Table is
controlled by the trigger interval. By default Structured Streaming tries to process the data as soon as it arrives.
However, you can also configure the trigger to run on a longer interval, so that the streaming data is processed
according to time-based batches. The output mode controls the data in the Results Tables. This data may be
completely refreshed everytime there is new data so that it includes all of the output data since the streaming
query began (called complete mode ), or it may only contain just the data that is new since the last time the query
was processed (called append mode ).
In HDInsight, these checkpoints should be saved to your default storage attached to your cluster (either Azure
Storage or Azure Data Lake Store). Next, you need to specify a checkpoint interval (in seconds) on the DStream that
controls how often any state data (e.g., state derived from the input event) is persisted to storage. Persisting state
data this way can reduce the computation needed when rebuilding the state from the source event.
val lines = [Link]("hostname", 9999)
[Link](30)
[Link]()
[Link]()
In HDInsight cluster work is coordinated by YARN. Architecting for high availability for Spark Streaming has to
include not only techniques for Spark Streaming, but also for YARN components. An example configuration using
YARN is shown above. There are a number of considerations for this configuration.
Planning for failure
Considering which components could fail, namely an executor or a driver, is a first step in augmenting your
HDInsight cluster YARN configuration for high-availability. Also, certain Spark Streaming job failures may include
data guarantee requirements which needs additonal configurations and setups. For example, a streaming
application may have the business requirement for ZERO data loss guarantees in spite of any type of error that
could occur in the hosting streaming system or HDInsight cluster.
If an executor fails, then tasks and receivers are restarted by Spark automatically, there is no configuration change
needed. Importantly, if a driver fails, then all of its associated executors fail. Also all computation and received
blocks are lost. Use DStream Checkpointing (discussed in an earlier section of this article) to recover from driver
failure. As mentioned previously, DStream Checkpointing periodically saves the DAG of DStreams to fault-tolerant
storage (such as Azure BLOBs). Checkpointing allows for the failed driver to be restarted using checkpoint
information. This driver restart will launch new executors and will also restart receivers.
To recover drivers w/DStream Checkpointing
Configure automatic driver restart on the YARN by updating the configuration
[Link]-attempts setting
Set a checkpoint directory in a HDFS-compatible file system by [Link](hdfsDirectory)
Restructure source code to use checkpoints for recovery (example function shown below for setup code)
Configure to recover lost data by enabling WAL via
[Link]("[Link]","true") and disabling in-memory replication
via StorageLevel.MEMORY_AND_DISK_SER for input DStreams
To summarize, using checkpointing + WAL + reliable receivers, you will be able to deliver "at least once" data
recovery
Exactly once, as long as received data is not lost and if outputs are idempotent or transactional
Exactly once (alternative) via new Kafka Direct approach - uses Kafka as replicated log, does not use receivers or
WALs
[Link] = 2
[Link]=1h
In order to work with enhanced metrics for monitoring, here are some considerations. Spark Streaming UI
AND Spark have a configurable metrics system, or you can also use additional libraries, such as
Graphite/Grafana to download dashboard metrics such as 'num records processed', 'memory/GC usage on
driver & executors', 'total delay', 'utilization of the cluster' and others... In Structured Streaming (2.1 or
greater only) you can use StreamingQueryListener to gather additional metrics.
Not segmenting long-running jobs. When a Spark Streaming application is submitted to the cluster, the
YARN queue where the job runs must be defined. You can use a YARN Capacity Scheduler to submitting
long-running jobs to separate queue.
Not shutting down your streaming application gracefully - If your offsets are known and state stored is
externally then you can programmatically stop your streaming application at the appropriate place. One
technique is to use 'thread hooks' in Spark, by checking for external flag every n seconds -or- use by using a
marker file. You can 'touch' this file when starting the application on HDFS and then remove the file when
you want to stop. If using this method, use a separate thread in Spark application, which calls code similiar
that that shown below.
Conclusion
This article provided a series of actions that you can to take to run Spark Streaming jobs in a fault-tolerant and
highly-available way on a YARN cluster on HDInsight. These includes making cluster configuration changes for
both YARN and Spark Streaming, for example to enable checkpointing and use the write-ahead log, and detailed in
which scenarios the various activities should be used.
Spark Streaming Overview
Long-running Spark Streaming Jobs on YARN
Structured Streaming: Fault Tolerant Semantics
Discretized Streams: A Fault-Tolerant Model for Scalable Stream Processing
Creating Spark Streaming jobs with exactly once
event processing semantics
8/16/2017 • 5 min to read • Edit Online
Stream processing applications may take different approaches to how they handle the re-processing of messages
in the face of some failure in the system, these approaches yield different event processing semantics:
At least once: In some cases, it is acceptable for a given event to be processed multiple times. If the system
guarantees that the message will always get processed, but it may get processed more than once, than it
provides an at least once semantics.
At most once: In some cases, it is acceptable to lose messages, but it is critical that messages not be processed
more than once. A system to supports this is providing an at most once processing semantics.
Exactly once: In other cases, a message must processed once and only once irrespective of failures in
components of the system. Systems that support this provide an exactly once semantics.
This article focuses on how you configure Spark Streaming to achieve exactly once processing semantics.
In HDInsight, these checkpoints should be saved to your default storage attached to your cluster (either Azure
Storage or Azure Data Lake Store). Next, you need to specify a checkpoint interval (in seconds) on the DStream that
controls how often any state data (e.g., state derived from the input event) is persisted to storage. Persisting state
data this way can reduce the computation needed when rebuilding the state from the source event.
Next steps
This article covered the key components of achieving exactly once semantics with your Spark Streaming
applications.
Review Spark Streaming Overview for an architectural overview of a Spark Streaming application.
See Creating highly available Spark Streaming jobs in YARN for guidance on how to enable high availability for
your Spark Streaming applications in HDInsight.
Optimizing and configuring Spark Jobs for
Performance
8/16/2017 • 16 min to read • Edit Online
A Spark cluster is an installation of the Apache Spark library onto a HDInsight Hadoop cluster. Each HDInsight
cluster includes default configuration parameters for your Spark cluster at the top level and also at the level of
Spark services and service instances in your Spark cluster. A Spark Job is a set of multiple tasks executed via
parallel computation. Spark Jobs are generated in response to a Spark actions (such as 'collect' or 'save'). Spark
uses a threadpool of tasks for parallel execution rather than a pool of JVM resources (used by MapReduce).
A key aspect of managing a HDInsight Hadoop cluster is monitoring all jobs on the cluster to make sure they are
running in a predictable manner. This application monitoring includes Apache Spark job monitoring and
optimization. The diagram below shows the core Spark Architecture. It is important to consider the execution
objects when determining how to optimize Spark Jobs. The objects show in the the diagram are the Driver
Program and it's associated Spark Context, the Cluster Manager, and the n-number of Worker Nodes. Each Worker
Node includes it's own Executor, Cache and n-number of Task instances.
The diagram below shows the core Spark Job workflow stages. As above, it's important to review Job workflow
objects when optimizing Spark Jobs. In the diagram the data is represented by the low-level RDD Objects. The next
step is the DAG Scheduler. The DAG Scheduler interacts with the Task Scheduler to schedule, submit, launch and
retry tasks. These two schedulers interact with the worker instances. Worker instances host threads and also make
use of a Block Manager. The Block Manager stores and serves blocks of data to the workflow.
Viewing Cluster Configuration Settings
It is common practice when performing performance optimization on an HDInsight cluster to begin by verifying
cluster configuration settings. To do this for not only your particular Apache Spark configuration, but also other
services that you may have installed, you launch the HDInsight Dashboard from the Azure Portal by clicking the
'Dashboard' link on the Spark cluster blade.
You will be prompted to login with the username and password that you specified when you setup the HDInsight
cluster. After you enter your administrator cluster credentials, then you'll be presented with the Ambari Web UI.
This UI provides a dashboard view of the key cluster resource utilitization metrics.
An example Ambari HDInsight Dashboard is shown below.
In addition to viewing the top level cluster metrics, you can also view cluster configuration information. To see
configuration values for Apache Spark, click on the 'Configs' tab, then click on the 'Spark2' (or 'Spark' depending
on the version of Spark that you've installed on your cluster) service link in the service list.
You will be presented with a list of configuration values for your cluster as shown below.
To view Spark configuration values, click the one of the links labeled with the word 'spark' in the link title.
Configurations for Spark include the following both custom and advanced configuration values include these
configuration categories:
Custom Spark2-defaults
Custom Spark2-metrics-properties
Advanced Spark2-defaults
Advanced Spark2-env
Advanced spark2-hive-site-override
After you click one of these links you can view and also update configuration values. If you create a non-default set
of configuration values, then you can see a history of any configuration updates you've performed in this UI as
well. This configuration history can be helpful if you wish to verify a non-default configuration is in use for
performance optimization.
Note: If you only wish to verify common Spark configuration settings, you can also click on the 'Environment' tab
on the top level Spark Job UI interface. In this view, you can view, but not change, cluster configuration values. The
Spark Job UI is described in the next section of this article.
Track an application in the Spark UI
When working on Spark Job performance, it's important to to start by understanding how to get visibility into Job
performance via the various HDInsight job monitoring tools. To understand how these tools work, it's best to
generate a sample workload. A simple way to generate sample Spark Jobs is by runnning one or more of the
included Jupyter demo notebook(s). Click on the Jupyter blade on your HDInsight instance in the portal and then
continue clicking to open and run all cells from one or more sample notebooks.
After your sample workload has completed, from the cluster blade, click 'Cluster Dashboard', and then click 'YARN'
to launch the YARN UI. Because you started the Spark job using Jupyter notebooks, the application in the log has
the name remotesparkmagics. Click the application ID against the application name to get more information
about the job. This launches the application view.
For such applications that are launched from the Jupyter notebooks, the status is always RUNNING until you exit
the notebook. From the application view, you can drill down further to find out the containers associated with the
application and the logs (stdout/stderr). You can also launch the Spark UI by clicking the link next to the Tracking
URL (in this case 'Application Master'), as shown below.
Clicking the Tracking URL link will open the Spark Jobs UI. After the Spark Jobs UI renders, you can drill down to
view specific implementation details for the Spark jobs that have been spawned by the application workload(s)
that you started prior to navigating here. You can review detailed information about jobs, stages, storage,
environment, executors and Spark SQL via this UI.
The default view is open to the Jobs tab. The Jobs tab lists recently run Spark jobs, ordered by Job Id. It provides a
high-level view of the status of Job workflow execution outcome by displaying the Job Id, job description, data and
time that the job was submitted, job execution duration, job stage and task status. An example of the Spark Jobs UI
is shown below.
As mentioned, there are a number of views available in the Spark Jobs UI. They allow you to review detailed
execution information about the Spark Jobs that have been run on your cluster. This information is key when
monitoring and optimizing Spark Job executions. It is especially important that you review the job stages and tasks
using the DAG view and understand the overhead of each job stage so that you can verify that your Spark Job is
performing as expected.
Click the Executors tab to see processing and storage information for each executor. In this tab, you can also
retrieve the call stack by clicking on the Thread Dump link.
Click the Stages tab to see the stages associated with your Spark Job
Each job stage can have multiple job tasks for which you can view detailed execution statistics
From the stage details page, you can launch the DAG Visualization by clicking the link at the top of the
page to expand the DAG visualization view. The DAG (Direct Aclyic Graph) represents the different stages
in the application. Each blue box in the graph represents a Spark operation invoked from the application.
From the stage details page, you can also launch the application timeline view. Expand the Event
Timeline link at the top of the page to view a visualization of the job event execution details.
TIP: You can also use the Spark History Server to access details about Spark jobs executions that have previously
completed.
Logging
Spark uses log4j for logging. You can configure it by adding a [Link] file in the conf directory, or
through the Ambari interface. One of the challenges of having various logs generated during job execution, is
being able to correlate information stored in those logs with one another. To address this issue, make the
following configuration changes:
Add thread-id to executor logs: +[%t]
Add precise time stamp in executor logs: %d{ISO8601}
4. Caching
Spark provides its own native caching mechanisms, and can be used through different methods such as
.persist() , .cache() , and CACHE TABLE . This native caching is effective with small data sets as well as in ETL
pipelines where you need to cache intermediate results. However, it currently does not work well with partitioning,
since a cached table does not retain the partitioning data. Therefore, a more generic and reliable caching technique
is storage layer caching.
Native Spark caching (not recommended)
Good for small datasets
Does not work with partitioning (will be fixed in the future)
Storage level caching (recommended)
Can be implemented using Alluxio
Uses in-memory + SSD caching
Local HDFS (recommended)
hdfs://mycluster
SSD caching
Cached data will be lost when you delete the cluster, requiring cache rebuild
5. Use Memory Efficiently
Because Spark operates by placing data in memory, appropriately managing memory resources is a key aspect of
optimizing the execution of Spark Jobs. There are several techniques that you can use to use your cluster's
memory efficiently. These include the following:
Prefer smaller data partitions, account for data size, types and distribution in your partitioning strategy
Consider the newer, more efficient Kryo data Serialization, rather than the default Java Serialization
Prefer to use YARN, as it separates spark-submit per batch
Monitor and tune Spark configuration settings
For reference, the Spark memory structure and some key executor memory parameters are shown below.
Spark Memory
If you are using YARN, then YARN controls the maximum sum of memory used by the containers on each Spark
node. The graphic below shows the key objects and relationship between them.
Here are set of common practices you can try if you are addressing 'out of memory' messages:
Review DAG Management Shuffles -> reduce by map-side reducting, pre-partition (or bucketize) source data,
maximize single shuffle, reduce the amount of data sent
Prefer 'ReduceByKey'(has fixed memory limit) to 'GroupByKey'(more powerful, i.e. aggregations, windowing,
etc.. but, has unbounded memory limit)
Prefer 'TreeReduce'(does more work on the executors or partitions) to 'Reduce'(does all work on the driver)
Leverage DataFrame rather than the lower-level RDD object
Create ComplexTypes which encapsulate actions, such as 'Top N', various aggregations or windowing ops
6. Optimize Data Serialization
Because Spark Job are distributed, appropriate data serialization is key to best Spark Job performance. There are
two serialization options for Spark. Java serialization is the default. There is a new serialization library, Kryo,
available. Kryo serialization can result in faster and more compact serialization than that of Java. Kryo serialization
is a newer format and it does not yet support all Serializable types. Also it requires that you register the classes in
your program.
7. Use bucketing
Bucketing is similar to data partitioning, but each bucket can hold a set of column values (bucket), instead of just
one. This is great for partitioning on large (in the millions +) number of values, like product Ids. A bucket is
determined by hashing the bucket key of the row. Bucketed tables offer unique optimizations because they store
metadata about how they were bucketed and sorted.
Some advanced bucketing features are:
Query optimization based on bucketing meta-information
Optimized aggregations
Optimized joins
You can use partitioning and bucketing at the same time.
8. Fix slow Joins/Shuffles
If you have slow jobs on Join/Shuffle, for example it may take 20 seconds to run a map job, but 4 hrs when
running a job where the data is joined or shuffled, the cause is probably data skew. Data skew is defined as
asymmetry in your job data. To fix data skew, you should salt the entire key, or perform an isolated salt (meaning
apply the salt to only some subset of keys). If you are using the 'isolated salt' technique, you should further filter to
isolate your subset of salted keys in map joins. Another option is to introduce a bucket column and pre-aggregate
in buckets first.
Another factor causing slow joins could be the join type. By default, Spark uses the SortMerge join type. This type
of join is best suited for large data sets, but is otherwise computationally expensive (slow) because it must first sort
the left and right sides of data before merging them. A Broadcast join, on the other hand, is best suited for smaller
data sets, or where one side of the join is significantly smaller than the other side. It broadcasts one side to all
executors, so requires more memory for broadcasts in general.
You can change the join type in your configuration by setting [Link] , or you can
change the type with a join hint using the DataFrame APIs ( [Link](broadcast(df2)) ).
Example:
// Option 1
[Link]("[Link]", 1*1024*1024*1024)
// Option 2
val df1 = [Link]("FactTableA")
val df2 = [Link]("dimMP")
[Link](broadcast(df2), Seq("PK")).
createOrReplaceTempView("V_JOIN")
sql("SELECT col1, col2 FROM V_JOIN")
If you are using bucketed tables, you have a third join type: Merge join. A correctly pre-partitioned and pre-sorted
daataset will skip the expensive sort phase in a SortMerge join.
The order of joins matters, particularly in more complex queries. Make sure you start with the most selective joins.
Also, move joins that increase the number of rows after aggregations when possible.
Additionally, to manage parallelism, specifically to fight Cartesian Joins, you can adding nested structures,
windowing and/or skip step(s) in your Spark Job.
9. Spark Cluster Custom Configuration
Depending on your Spark workload, you may determine that a non-default Spark configuration would result in
more optimized Spark Job executions. You should perform benchmark testing with key workloads to validate any
non-default cluster configurations. Some of the common parameters that you may consider adjusting are listed
below with associated parameter notes.
Executors (--num-executors)
set the appropriate number of executors
Cores for each executor (--executor-cores)
have middle-sized executors, as other processed will consume some portion of the available memory
Memory for each executor (--executor-memory)
controls heap size on YARN, you'll need to leave some memory for execution overhead
Selecting the correct executor size
When deciding your executor configuration, you need to consider what the Java Garbage Collection (GC) overhead
will be.
Factors to reduce size
1. Reduce heap size below 32GB to keep GC-overhead < 10%
2. Reduce cores to keep GC-overhead < 10%
Factors to increase size
1. Reduce communication overhead between executors
2. Reduce number of open connections between executors (N2) on larger clusters (>100 executors)
3. Increase heap size to accommodate for memory demanding tasks
4. Optional: Reduce per executor memory overhead
5. Optional: Increase utilization and concurrency by oversubscribing CPU
As a general rule of thumb when selecting the executor size:
1. Start with 30GB per executor and distribute available machine cores
2. Increase number of executor-cores for larger clusters (> 100 executors)
3. Increase/decrease size based on trial runs and factors from previous slide (like observed GC-overhead)
When running concurrent queries, consider the following:
1. Start with 30GB per executor and all machine cores
2. Create multiple parallel spark applications by oversubscribing CPU (around 30% latency improvement)
3. Distribute queries across parallel applications
4. Increase/decrease size based on trial runs and factors from previous slide (like observed GC-overhead)
Always remember to monitor your query performance for outliers or other performance issues, by looking at the
time line view, SQL graph, job statistics, etc. Sometimes one or a few of the executors are slower than the others,
and tasks take much longer to execute. This frequently happens on larger clusters (> 30 nodes). To mitigate, divide
work into a larger number of tasks so the scheduler can compensate for slow tasks. For example, have at least 2x
as many tasks as the number of executor cores in the application. Also, enable speculative execution of tasks:
conf: [Link] = true .
When we discovered this issue with one customer's dataset, fixing string in an aggregation expression and re-
enabling code generation improved performance by 3x.
Conclusion
There are a number of core considerations you need to pay attention to make sure your Spark Jobs run in a
predictable and performant way. It's key for you to focus on using the best Spark cluster configuration for your
particular workload. Along with that, you'll need to monitor the execution of long-running and/or high resource
consuming Spark Job executions. The most common challenges center around memory pressure due to improper
configurations (particularly wrong-sized executors), long-running operations and tasks which result in cartesian
operations. Using caching judiciously can significantly speed up jobs. Finally, it's important to adjust for data skew
in your job tasks.
See also
Debug Spark jobs running on Azure HDInsight
Manage resources for a Spark cluster on HDInsight
Use the Spark REST API to submit remote jobs to a Spark cluster
Tuning Spark
How to Actually Tune Your Spark Jobs So They Work
Kryo Serialization
Configuring Spark Settings
8/16/2017 • 8 min to read • Edit Online
When you select a particular version of Spark, your cluster includes a number of default configuration settings. For
whichever version of Spark that you choose, you can change the default Spark configuration values by providing a
custom Spark configuration file. An example is shown below.
[Link] [Link]
[Link] 1099511627776
[Link] 1099511627776
[Link] 1099511627776
[Link] 1099511627776
In the example shown above (taken from a bioinformatics use case) default values for a number of Spark
configuration parameters are overridden. These are the compression codec, hadoop mapreduce split minimum
size and parquet block sizes, as well as the spar sql partition and open file sizes default values. These configuration
changes were made because the associated data and jobs (i.e. genomic data) have particular characteristics which
will perform better using these custom configuration settings.
Three key parameters that are often adjusted to tune Spark configurations to improve application requirements
are [Link] , [Link] , and [Link] . An Executor is a process
launched for a Spark application. It runs on the worker node and is responsible to carry out the tasks for the
application. The default number of executors and the executor sizes for each cluster is calculated based on the
number of worker nodes and the worker node size. These are stored in [Link] on the cluster head
nodes. You can edit these values in a running cluster by clicking the link Custom spark-defaults in the Ambari web
UI (shown earlier in this article). After you make changes, then you'll be prompted in the UI to Restart all the
affected services.
TIP: The three configuration parameters can be configured at the cluster level (for all applications that run on the
cluster) or can be specified for each individual application as well.
Another source of information about the resources being used by the Spark Executors is the Spark Application UI.
In the Spark UI, click the Executors tab to display a Summary and Detail view of the configuration and resources
consumed by the executors as shown below. This can help you to understand when you might want to change
default values for Spark executors for the entire cluster or a particular set of job executions.
Alternatively, you can use the Ambari REST API to programmatically verify HDInsight and Spark cluster
configuation settings. More information is available via the GitHub repository Ambari API reference.
Depending on your Spark workload, you may determine that a non-default Spark configuration would result in
more optimized Spark Job executions. You should perform benchmark testing with key workloads to validate any
non-default cluster configurations. Some of the common parameters that you may consider adjusting are listed
below with associated parameter notes. Also an example of how you might configure two worker nodes with
different node configuration values is shown in the graphic below.
Executors (--num-executors)
set the appropriate number of executors
Cores for each executor (--executor-cores)
have middle-sized executors, as other processed will consume some portion of the available memory
Memory for each executor (--executor-memory)
controls heap size on YARN, you'll need to leave some memory for execution overhead
For reference key Spark executor memory parameters are shown below.
[Link] defines the TOTAL amount of memory available for the executor
[Link] (default ~ 60%) defines the amount available for storing persisted RDDs
[Link] (default ~ 20%) deinfes the amount reserved for shuffle
[Link]/safetyFraction (~30% of total memory) - avoid using, this is used internally by
Spark
Because YARN controls the maximum sum of memory used by the containers on each Spark node it is useful to
understand the relationship between YARN configuration objects and Spark objects per node. The graphic below
shows the key objects and relationship between them.
%%configure
{"executorMemory": "3072M", "executorCores": 4, "numExecutors":10}
Conclusion
There are a number of core configuration settings that you need to monitor and adjust to make sure your Spark
Jobs run in a predictable and performant way. It's key for you to focus on using the best Spark cluster
configuration for your particular workloads. Along with that, you'll need to monitor the execution of long-running
and/or high resource consuming Spark Job executions. The most common challenges center around memory
pressure due to improper configurations (particularly wrong-sized executors), long-running operations and tasks
which result in cartesian operations.
See also
What are the Hadoop components and versions available with HDInsight?
Manage resources for a Spark cluster on HDInsight
Set up clusters in HDInsight with Hadoop, Spark, Kafka, and more
Apache Spark Configuration
Running Spark on YARN
Choosing between RDD, DataFrame, and Dataset for
Spark
8/16/2017 • 9 min to read • Edit Online
What is an RDD?
Big Data applications rely on iterative, distributed computing for faster processing of large data sets. To distribute
data processing over multiple jobs, the data is typically reused or shared across jobs. To share data between
existing distributed computing systems you need to store data in some intermediate stable distributed store such
as HDFS. This makes the overall computations of jobs slower.
Resilient Distributed Datasets (RDDs) address this by enabling fault-tolerant, distributed, in-memory
computations. (RDDs) are the baseline data abstractions in Spark. They are fault-tolerant collections of elements
stored in-memory or on-disk that can be operated on in parallel. An RDD can hold many kinds of source data.
RDDs are created by loading an external dataset or distributing a collection from the Spark driver program.
An RDD can be persisted in-memory across operations. When an RDD is persisted, each node stores any partitions
of it that it computes in-memory and then reuses them in other actions on the data set. You can mark an RDD as
persistent just by calling the persist() or cache() method. You can also specify the storage level: on-disk or in-
memory as a serialized Java object. Cached, or persistent, RDDs are fault-tolerant without replication.
Each RDD maintains its lineage (for example, the sequence of transformations that resulted in the RDD). If an RDD
is lost because a node crashed, it can be reconstructed by replaying the sequence of operations.
An Evolving API
The Apache Spark API as a whole is evolving at a rapid pace, including changes and additions to its core APIs. One
of the most disruptive areas of change is around the representation of data sets. Although Spark 1.0 used the RDD
API, two new alternative and incompatible APIs have been introduced. Spark 1.3 introduced the radically different
DataFrame API and the Spark 1.6 release introduced a preview of the new Dataset API.
You may be wondering whether to jump from RDDs directly to the Dataset API, or whether to first move to the
DataFrame API.
Currently, the DataFrame APIs offer the most performance. RDD APIs still exist in Spark 2.x for backwards
compatibility, and should not be used. Going forward, only the DataFrame and Dataset APIs will be developed.
The main disadvantage to RDDs is that they don’t perform particularly well. Whenever Spark needs to distribute the
data within the cluster, or write the data to disk, it does so using Java serialization by default (although it is possible
to use Kryo as a faster alternative in most cases). The overhead of serializing individual Java and Scala objects is
expensive and requires sending both data and structure between nodes (each serialized object contains the class
structure as well as the values). There is also the overhead of garbage collection that results from creating and
destroying individual objects.
DataFrame API
Spark 1.3 introduced a new DataFrame API to improve the performance and scalability of Spark. The DataFrame
API introduced the concept of a schema to describe the data, allowing Spark to manage the schema and only pass
data between nodes, in a much more efficient way than using Java serialization. There are also advantages when
performing computations in a single process as Spark can serialize the data into off-heap storage in a binary
format and then perform many transformations directly on this off-heap memory, avoiding the garbage-collection
costs associated with constructing individual objects for each row in the data set. Because Spark understands the
schema, there is no need to use Java serialization to encode the data.
The DataFrame API is radically different from the RDD API because it is an API for building a relational query plan
that Spark’s Catalyst optimizer can then execute. The API is natural for developers who are familiar with building
query plans, but not natural for the majority of developers. The query plan can be built from SQL expressions in
strings or from a more functional approach using a fluent-style API.
Example: Filter by attribute with DataFrame in Scala
//SQL Style
[Link]("age > 21");
Because the code is referring to data attributes by name, it is not possible for the compiler to catch any errors. If
attribute names are incorrect then the error will only detected at runtime, when the query plan is created.
How do I make a dataframe?
You can load a dataframe directly from an input data source. See the following notebooks included with your
HDInsight Spark cluster for more information.
Read and write data from Azure Storage Blobs (WASB)
Read and write data from Hive tables
Dataset API
The Dataset API, released as an API preview in Spark 1.6 (and as generally available in Spark 2.x), aims to provide
the best of both worlds; the familiar object-oriented programming style and compile-time type-safety of the RDD
API but with the performance benefits of the Catalyst query optimizer. Datasets also use the same efficient off-heap
storage mechanism as the DataFrame API.
When it comes to serializing data, the Dataset API has the concept of encoders which translate between JVM
representations (objects) and Spark’s internal binary format. Spark has built-in encoders which are very advanced
in that they generate byte code to interact with off-heap data and provide on-demand access to individual
attributes without having to de-serialize an entire object. Spark does not yet provide an API for implementing
custom encoders, but that is planned for a future release.
Transformations with the Dataset API look very much like the RDD API and deal with the Person class rather than
an abstraction of a row.
Example: Filter by attribute with Dataset
Despite the similarity with RDD code, this code is building a query plan, rather than dealing with individual objects,
and if age is the only attribute accessed, then the rest of the the object’s data will not be read from off-heap storage.
With the release of Spark 2.x, there are really only two programmatic APIs now; RDD and Dataset. For backwards
compatibility, DataFrame still exists but is just a synonym for a Dataset.
CSV support is now built-in and based on the DataBricks spark-csv project, making it easy to create Datasets from
CSV data with little coding.
Spark 2.0 is a major release, and there are some breaking changes that mean you may need to rewrite some of
your code. Here are some things we ran into when updating our apache-spark-examples.
For Scala users, SparkSession replaces SparkContext and SQLContext as the top-level context, but still provides
access to SQLContext and SQLContext for backwards compatibility
DataFrame is now a synonym for Dataset[Row] and you can use these two types interchangeably, although we
recommend using the latter. Performing a map() operation on a Dataset now returns a Dataset rather than an RDD,
reducing the need to keep switching between the two APIs, and improving performance.
Some Java functional interfaces, such as FlatMapFunction, have been updated to return Iterator rather than Iterable.
RDD vs. Dataset 2.0
Both the RDD API and the Dataset API represent data sets of a specific class. For instance, you can create an
RDD[Person] as well as a Dataset[Person] so both can provide compile-time type-safety. Both can also be used with
the generic Row structure provided in Spark for cases where classes might not exist that represent the data being
manipulated, such as when reading CSV files.
RDDs can be used with any Java or Scala class and operate by manipulating those objects directly with all of the
associated costs of object creation, serialization and garbage collection.
Datasets are limited to classes that implement the Scala Product trait, such as case classes. There is a very good
reason for this limitation. Datasets store data in an optimized binary format, often in off-heap memory, to avoid the
costs of deserialization and garbage collection. Even though it feels like you are coding against regular objects,
Spark is really generating its own optimized byte-code for accessing the data directly.
The Scala code examples below show working with RDDs, Dataframes and Datasets.
// RDD raw object manipulation
val rdd: RDD[Person] = …
val rdd2: RDD[String] = [Link](person => [Link])
// Dataset optimized direct access to memory without deserializing objects
val ds: Dataset[Person] = …
val ds2: Dataset[String] = [Link](person => [Link])
Conclusion
Currently, the DataFrame APIs offer the most performance. RDD APIs still exist in Spark 2.x for backwards
compatibility, and should not be used. Going forward, only the DataFrame and Dataset APIs will be developed.
The Spark Dataset API is very performant and provides a more natural way to code than using the more low-level
RDD abstraction. Given the rapid evolution of Spark it is likely that this API will mature and become the de-facto API
for developing new applications.
The Spark API is moving from unstructured computation (RDDs) towards structured computation (Datasets)
because of the many performance optimizations that the latter allows. DataFrames were a step in direction of
structured computation but lacked developer-desired features such as compile time safety and lambda functions.
The Spark Dataset API unifies both Dataframes and RDDs.
See also
Get started: Create an Apache Spark cluster in HDInsight and run interactive Spark SQL queries
Spark SQL, DataFrames and Datasets Guide
RDDs, DataFrames and Datasets video
What is HBase in HDInsight: A NoSQL database that
provides BigTable-like capabilities for Hadoop
8/16/2017 • 3 min to read • Edit Online
Apache HBase is an open-source, NoSQL database that is built on Hadoop and modeled after Google BigTable.
HBase provides random access and strong consistency for large amounts of unstructured and semistructured
data in a schemaless database organized by column families.
Data is stored in the rows of a table, and data within a row is grouped by column family. HBase is a schemaless
database in the sense that neither the columns nor the type of data stored in them need to be defined before
using them. The open-source code scales linearly to handle petabytes of data on thousands of nodes. It can rely
on data redundancy, batch processing, and other features that are provided by distributed applications in the
Hadoop ecosystem.
NOTE
Thrift is not supported by HBase in HDInsight.
Next steps
Get started using HBase with Hadoop in HDInsight
Create HDInsight clusters on Azure Virtual Network
Configure HBase replication in HDInsight
Analyze Twitter sentiment with HBase in HDInsight
Use Maven to build Java applications that use HBase with HDInsight (Hadoop)
See also
Apache HBase
Bigtable: A Distributed Storage System for Structured Data
Choosing storage option for HBase on HDInsight
8/15/2017 • 2 min to read • Edit Online
HBase on HDInsight can be configured to use either Azure Storage blobs or Azure Data Lake Store as the location
where it stores its data (e.g., Storefiles) and metadata. When you provision an HDInsight cluster, either option can
be used as the default storage location. Additionally, either can be attached to the HDInsight cluster as additional
storage.
Azure Storage
When using Azure Storage blobs, the files managed by HBase will be stored a block blobs in the configured Storage
Account. There are some limitation you should be aware of when choosing Azure Storage that may affect the
performance and scalability of your HDInsight HBase cluster:
Total Storage Account Capacity: Azure Storage has an upper limit of 500 TB per Storage Account. This means
that if you only have one Storage Account attached to your HDInsight HBase cluster, then the maximum size it
can support will be close to 500 TB.
Maximum Blob Size: Each individual blob in Azure Storage blobs has a maximum size of approximately 4.75 TB.
This dictates maximum size of your individual Storefiles.
Maximum Throughput for Storage Account: The Storage Account has an all-up limit of 20,000 requests per
second. This limit represents the combined requests per second against all blobs in the Storage Account. This
means there is an upper limit of how many "hot" Storefiles your Storage Account will support. For example, if
you had 41 Storefiles that were hot, each using 500 requests per second, you would hit this upper limit because
your Storage Account would be experiencing 20,500 requests per second. When you hit the limit, your requests
will be throttled, slowing down the execution of your HBase operations.
Maximum Throughout for a Single Blob: Each blob in Azure Storage supports a maximum throughput of up to
60 MB/s or 500 requests per second. This limit effectively caps the throughput available for serving requests
against your Storefiles, since each Storefile is represented by a blob. When you exceed these limits, your
requests will be throttled, slowing down the execution of your HBase operations against that Storefile.
For the latest on Azure Storage limits, see Azure subscription limits and quotas.
See also
For more details on HDInsight storage architecture, see HDInsight Architecture
Get started with an Apache HBase example in
HDInsight
8/16/2017 • 7 min to read • Edit Online
Learn how to create an HBase cluster in HDInsight, create HBase tables, and query tables by using Hive. For general
HBase information, see HDInsight HBase overview.
WARNING
Billing for HDInsight clusters is prorated per minute, whether you are using them or not. Be sure to delete your cluster after
you have finished using it. For more information, see How to delete an HDInsight cluster.
Prerequisites
Before you begin trying this HBase example, you must have the following items:
An Azure subscription. See Get Azure free trial.
Secure Shell(SSH).
curl.
hbase shell
You shall see the same results as using the scan command because there is only one row.
For more information about the HBase table schema, see Introduction to HBase Schema Design. For more
HBase commands, see Apache HBase reference guide.
5. Exit the shell
exit
You can optionally create a text file and upload the file to your own storage account. For the instructions, see
Upload data for Hadoop jobs in HDInsight.
NOTE
This procedure uses the Contacts HBase table you have created in the last procedure.
1. From SSH, run the following command to transform the data file to StoreFiles and store at a relative path
specified by [Link]. If you are in HBase Shell, use the exit command to exit.
hbase [Link] -
[Link]="HBASE_ROW_KEY,Personal:Name,Personal:Phone,Office:Phone,Office:Address" -
[Link]="/example/data/storeDataFileOutput" Contacts
wasb://hbasecontacts@[Link]/[Link]
2. Run the following command to upload the data from /example/data/storeDataFileOutput to the HBase
table:
3. You can open the HBase shell, and use the scan command to list the table content.
For more information about Beeline, see Use Hive with Hadoop in HDInsight with Beeline.
3. Run the following HiveQL script to create a Hive table that maps to the HBase table. Make sure that you
have created the sample table referenced earlier in this tutorial by using the HBase shell before you run this
statement.
CREATE EXTERNAL TABLE hbasecontacts(rowkey STRING, name STRING, homephone STRING, officephone STRING,
officeaddress STRING)
STORED BY '[Link]'
WITH SERDEPROPERTIES ('[Link]' =
':key,Personal:Name,Personal:Phone,Office:Phone,Office:Address')
TBLPROPERTIES ('[Link]' = 'Contacts');
4. Run the following HiveQL script to query the data in the HBase table:
2. Use the following command to create a new HBase table with two-column families:
curl -u <UserName>:<Password> \
-X PUT "[Link] \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"@name\":\"Contact1\",\"ColumnSchema\":[{\"name\":\"Personal\"},{\"name\":\"Office\"}]}" \
-v
curl -u <UserName>:<Password> \
-X PUT "[Link] \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "{\"Row\":[{\"key\":\"MTAwMA==\",\"Cell\": [{\"column\":\"UGVyc29uYWw6TmFtZQ==\",
\"$\":\"Sm9obiBEb2xl\"}]}]}" \
-v
You must base64 encode the values specified in the -d switch. In the example:
MTAwMA==: 1000
UGVyc29uYWw6TmFtZQ==: Personal:Name
Sm9obiBEb2xl: John Dole
false-row-key allows you to insert multiple (batched) values.
4. Use the following command to get a row:
curl -u <UserName>:<Password> \
-X GET "[Link] \
-H "Accept: application/json" \
-v
For more information about HBase Rest, see Apache HBase Reference Guide.
NOTE
Thrift is not supported by HBase in HDInsight.
When using Curl or any other REST communication with WebHCat, you must authenticate the requests by providing the
user name and password for the HDInsight cluster administrator. You must also use the cluster name as part of the Uniform
Resource Identifier (URI) used to send the requests to the server:
curl -u <UserName>:<Password> \
-G [Link]
{"status":"ok","version":"v1"}
WARNING
Billing for HDInsight clusters is prorated per minute, whether you are using them or not. Be sure to delete your cluster after
you have finished using it. For more information, see How to delete an HDInsight cluster.
Troubleshoot
If you run into issues with creating HDInsight clusters, see access control requirements.
Next steps
In this article, you learned how to create an HBase cluster and how to create tables and view the data in those
tables from the HBase shell. You also learned how to use a Hive query on data in HBase tables and how to use the
HBase C# REST APIs to create an HBase table and retrieve data from the table.
To learn more, see:
HDInsight HBase overview: HBase is an Apache, open-source, NoSQL database built on Hadoop that provides
random access and strong consistency for large amounts of unstructured and semistructured data.
Using the HBase REST SDK
8/16/2017 • 5 min to read • Edit Online
When you use HBase as your massively scalable NoSQL database, you are given two primary choices to work with
your data: Hive queries and calls to HBase's RESTful API. A common way to work with the REST API is through the
use of curl , or similar.
If your developers are more familiar with C# , with .NET as the platform of choice, the Microsoft HBase REST Client
Library for .NET provides a client library on top of the HBase REST API, and is available as a NuGet package to
quickly get started.
Install-Package [Link]
Replace CLUSTERNAME with your HDInsight HBase cluster name, and USERNAME and PASSWORD with the
Hadoop credentials specified on cluster creation. The default Hadoop user name is admin.
await [Link](newTableSchema);
}
We created a new table named "RestSDKTable" with two column families, t1 and t2. As discussed above, column
families are stored separately in different HFiles, thus it makes sense to have a separate column family for data
which is queried often. For example, we'll add columns to the t1 column family that we'll query often.
Delete a table
Deleting a table is as simple as this:
await [Link]("RestSDKTable");
Inserting data
When you insert data, you must specify a unique row key. This serves as the Id for the row. All of the data is stored
in a byte[] array. You'll notice that we are storing the title , director , and release_date columns within the t1
column family, and description and tagline within the t2 column family. This is because we tend to query the t1
column family more often. You may partition your data into column families however you see fit.
var key = "fifth_element";
var row = new [Link] { key = [Link](key) };
var value = new Cell
{
column = [Link]("t1:title"),
data = [Link]("The Fifth Element")
};
[Link](value);
value = new Cell
{
column = [Link]("t1:director"),
data = [Link]("Luc Besson")
};
[Link](value);
value = new Cell
{
column = [Link]("t1:release_date"),
data = [Link]("1997")
};
[Link](value);
value = new Cell
{
column = [Link]("t2:description"),
data = [Link]("In the colorful future, a cab driver unwittingly becomes the central figure
in the search for a legendary cosmic weapon to keep Evil and Mr Zorg at bay.")
};
[Link](value);
value = new Cell
{
column = [Link]("t2:tagline"),
data = [Link]("The Fifth is life")
};
[Link](value);
HBase implements BigTable. Thus, the format from our data above will look like:
Selecting data
To read data from the HBase table, pass the table name and row key to the GetCellsAsync method to return the
CellSet .
In this case, we're just returning the first matching row (there should only be one when using a unique key), then
converting the returned values into string format from the byte[] array. You may also convert the values to
other types, such as an integer for our movie's release date:
if (releaseDateField != null)
{
releaseDate = Convert.ToInt32([Link]([Link]));
}
[Link](releaseDate);
// Should return 1997
// Assume the table has integer keys and we want data between keys 25 and 35
var scanSettings = new Scanner()
{
batch = 10,
startRow = [Link](25),
endRow = [Link](35)
};
RequestOptions scanOptions = [Link]();
[Link] = "hbaserest0/";
ScannerInformation scannerInfo = null;
try
{
scannerInfo = await [Link](tableName, scanSettings, scanOptions);
CellSet next = null;
while ((next = [Link](scannerInfo, scanOptions).Result) != null)
{
foreach (var row in [Link])
{
// ... read the rows
}
}
}
finally
{
if (scannerInfo != null)
{
await [Link](tableName, scannerInfo, scanOptions);
}
}
Next steps
In this article, we learned how to use the HBase .NET SDK to work with the HBase REST API. Learn more about
HBase and other tools to work with its data by following the links below.
Get started with an Apache HBase example in HDInsight
Build an end-to-end application with Analyze real-time Twitter sentiment with HBase
Setting up Backup and Replication for HBase and
Phoenix on HDInsight
8/16/2017 • 9 min to read • Edit Online
HBase supports a few different approaches for guarding against data loss. These approaches are:
Copying the hbase folder
Export then Import
Copy table
Snapshots
Replication
As Apache Phoenix stores all of its metadata in HBase tables, any option you take that backs up the HBase system
catalog tables applies to the backup of Phoenix metadata.
This article covers each of these approaches, providing guidance one when to use which and how to setup that
form of backup.
/hbase
If you are using Azure Storage blobs, the external view of this same path is as follows, where the hbase folder sits at
the root of the blob container in your Azure Storage account:
wasbs://<containername>@<accountname>.[Link]/hbase
In Azure Data Lakes Store, the hbase folder simple sits under the root path you specified during cluster
provisioning, typically underneath a clusters folder, with a subfolder named after your HDInsight cluster:
/clusters/<clusterName>/hbase
This folder contains all of the data that hbase has flushed to disk, but it may not contain all off the data HBase is
managing in-memory. Therefore, it is important to shut down your cluster first before relying on this folder as an
accurate representation of your HBase data. Once you have done so, however, you can use this approach to restore
HBase in two different ways.
1. Without moving the data at all, you can create a new HDInsight instance and have it point to this same storage
location. The new instance will therefore be provisioned with all of the existing data.
2. You can use AzCopy (for Azure Storage) or AdlCopy (for Data Lake Store) to copy the hbase folder to another
Azure Storage blobs container or Data Lake Store location, and then start a new cluster with that data.
Note that this approach is very course-grained, you have to copy all of the HBase data and have no mechanisms for
selecting a subset of Tables or Column Families to copy.
Export then Import
In this approach, from the source HDInsight cluster, you use the Export utility (included with HBase) to export data
from a source Table that you indicate and the data is written to the default attached storage. You can then copy the
export folder to the destination storage location, and run the Import utility in the context of the destination
HDInsight cluster.
To export a table, you need to first SSH into the head node of your source HDInsight cluster and then run the
following hbase command providing the name of your table and the location to export to in the default storage.
To import the table, you need to SSH into the head node of your destination HDInsight cluster and then run the
following bhase command.
When specifying the export path, you supply paths that refer to the default storage or to any of the attached
storage options, so long as you adjust to use the full path syntax. For example, in Azure Storage, this has the
following form:
wasbs://<containername>@<accountname>.[Link]/<path>
In Azure Data Lake Store, the expanded syntax has the form:
adl://<accountName>.[Link]/<path>
As illustrated, this approach offers table level granularity. You can get even more granular with the process by
specifying a date range (in the form of start and end times in milliseconds since the Unix epoch) for the rows to
include, which allows you to perform the process incrementally:
Note that you have to specify the number of versions of each row to include, so if you want all version in the data
range, for specify an arbitrarily large number like 1000 that your data is not likely to exceed.
Copy Table
The CopyTable utility copies data directly from a source Table in a row by row fashion to an existing destination
table with the same schema as the source, where the destination table can be on the same cluster or a different
HBase cluster.
To use CopyTable, you need to SSH into the head node of your HDInsight cluster which will act as the source. Then
you run the hbase command with the following syntax:
If you are using CopyTable to copy to a table on the same cluster, then you can omit the peer switch. Otherwise,
you need to provide the destinationAddress, which has the following form:
<destAddress> = <ZooKeeperQuorum>:<Port>:<ZnodeParent>
The <ZooKeeperQuorum> needs to be the comma separated list of ZooKeeper nodes, for example:
[Link],zk4-
[Link],zk3-
[Link]
The <Port> on HDInsight defaults to 2181, and the <ZnodeParent> is /hbase-unsecure. So the complete using our
example qurom would be
[Link],zk4-
[Link],zk3-
[Link]:/hbase-unsecure
See the section Manually Collecting the ZooKeeper Quorum List in this article for details on how to retrieve these
values for your HDInsight cluster.
The CopyTable utility supports additional parameters that let you specify the timerange of rows to copy, as well as
the subset of column families in a table to copy. To view the complete list of parameters supported by CopyTable,
run CopyTable without any parameters:
hbase [Link]
When using CopyTable, it is important to recognize that it places a processing burden on the source table as it does
a scan of the content to copy over to the destination table. This may reduce your HBase cluster's performance as it
executes.
[!NOTE]
For a robust script you can use to automate the copying of data between tables, see hdi_copy_table.sh in the
[Azure HBase Utils]([Link] repository on GitHub.
The curl command retrieves a JSON document with hbase configuration and the grep call filters the listing to just
the line referring to the "[Link]" key and value pair. The output of this command looks similar to
the following:
"[Link]" : "[Link],zk4-
[Link],zk3-
[Link]"
The value you need is the entire string on the right of the colon.
If you need to retrieve the IP addresses for these hosts, you can use the following curl command against each host
in the previous list.
Where <zookeeperHostFullName> is the full DNS name of the ZooKeeper host, such as zk0-
[Link].
The output of the above command contains the IP address for the specified host and looks similar to:
Remember that you will need to collect the IP addresses for all ZooKeeper nodes in your quorum, and then rebuild
destAddress as follows:
<destAddress> = <Host_1_IP>,<Host_2_IP>,<Host_3_IP>:<Port>:<ZnodeParent>
For example:
<destAddress> = [Link],[Link],[Link]:2181:/hbase-unsecure
Snapshots
Snapshots enable you to take a point-in-time backup of data in your HBase datastore. They have minimal overhead
and complete within seconds because a snapshot operation is effectively a metadata operation that captures the
names of the files in storage relevant to that point in time. At the time of a snapshot, no actual data is copied.
Snapshots take advantage of the immutable nature of the data stored in HDFS (e.g., where updates, deletes and
inserts are actually represented as new data) to provide this point in time capability. You can restore the snapshot
(a process referred to as cloning) on the same cluster. You can also export a snaphot to another cluster.
To create a snapshot, SSH in to the head node of your HDInsight HBase cluster and run the hbase shell.
hbase shell
Within the hbase shell, run the snapshot command providing the of the table to snapshot and a name for the
snapshot:
You can restore a snapshot by name within the hbase shell by first disabling the table, restoring the snapshot and
then re-enabling the table:
disable '<tableName>'
restore_snapshot '<snapshotName>'
enable '<tableName>'
If you wish to restore a snapshot to a new table, you can do with clone_snapshot:
clone_snapshot '<snapshotName>', '<newTableName>'
To export a snapshot to HDFS for use by another cluster, first make sure you have created the snapshot as
described previously. Then you will need to use the ExportSnapshot utility. This is run from within the SSH session
to the head node, but not within the hbase shell:
In the command the specified must refer to any of the storage locations accessible to your source cluster, and
should point to the hbase folder used by your destination cluster. For example, if you had a secondary Azure
Storage account attached to your source cluster that provides access to the container used by the default storage of
the destination cluster, you could use a command similar to the following:
Once the snapshot has been exported in this way, you should SSH into the head node of the destination cluster and
restore the snapshot using the restore_snapshot command within the hbase shell as previously described.
Note that snapshots provide a complete backup of a table at the time the snapshot command is taken. They do not
provide the ability to perform incremental snapshots by windows of time, nor to specify subsets of columns
families to include in the snapshot.
Replication
HBase replication enables you to automatically push transactions from a source cluster to a destination cluster,
using an asynchronous mechanism that has minimal overhead on the source cluster. In HDInsight, you can setup
replication between clusters where:
The source and destination clusters are in the same virtual network
The source and destinations clusters are in different virtual networks connected by a VPN gateway, but both
clusters exist in the same geographic location
The source cluster and destinations clusters are in different virtual networks connected by a VPN gateway and
each cluster exists in a different geographic location
Irrespective of the deployment topology, the general setup for replication is as follows:
1. Create the tables and populate data in the source cluster.
2. Create empty destination tables in the destination cluster that follow the same schema as the tables used in the
source.
3. Register the destination cluster as a peer to the source cluster.
4. Enable replication on the desired source tables.
5. Copy existing data from the source tables to the destination tables.
6. Replication will automatically copy new data modifications as they happen on the source tables to the
destination tables.
Enabling replication in this way on HDInsight is accomplished by applying a Script Action to your running source
HDInsight cluster.
For a step by step walkthru of enabling replication in your cluster, or to experiment with replication on sample
clusters provisoned in Virtual Networks using ARM templates, see Configure HBase replication. This guide also
includes instructions for enabling replication of Phoenix metadata, which is still experimental.
See also
Configure HBase replication
Using Spark to read and write HBase data
8/16/2017 • 6 min to read • Edit Online
Apache HBase is typically queried either with its low level API of scans, gets and puts or with a SQL syntax using
Phoenix. Apache Spark can be used as a convinient and performant alternative way to query and modify data
stored by HBase. This is enabled by the use of the Spark HBase Connector.
This article covers how to setup your HDInsight Spark cluster so that it can query and modify data in you HDInsight
HBase cluster using the Spark HBase Connector.
Deployment Environment
To begin, you will need two separate HDInsight clusters- one of the HBase cluster type and one of the Spark cluster
type with Spark 2.1 (HDI 3.6) installed. The Spark cluster will need to be able to communicate directly with the
HBase cluster with minimal latency, so deploying both clusters within the same Virtual Network is the
recommended configuration. For instructions on how to deploy an HDInsight cluster into a Virtual Network, see
Create Linux based clusters in HDInsight using the Azure Portal.
This article assumes you have deployed your Spark and HDInsight cluster into one Virtual Network and that you
have SSH access to both. You will also need to have access to the default storage attached to each cluster.
Overall Process
The high-level process for enabling your Spark cluster to query your HDInsight cluster is as follows:
1. Acquire the [Link] file from your HBase cluster configuration folder (/etc/hbase/conf).
2. Place a copy of [Link] in your Spark 2 configuration folder (/etc/spark2/conf).
3. Run spark-shell referencing the Spark Hbase Connector by its Maven coordinates in the packages switch.
4. Define a catalog that maps the schema from Spark to Hbase
5. Interact with the HBase data via either the RDD or DataFrame APIs.
The following sections walk thru each section in detail.
hbase shell
3. Create a Contacts table with the column families "Personal" and "Office":
5. Select the Storage account in the list that has a checkmark under the Default column.
7. In the list of containers, select the container that is used by your HBase cluster.
8. In the file list, select [Link].
9. On the Blob properties panel, select Download and save it [Link] to a location on your local
machine.
3. Select the Storage account in the list that has a checkmark under the Default column.
5. In the list of containers, select the container that is used by your Spark cluster.
6. Select upload.
7. Choose the [Link] file you previously downloaded to your local machine.
8. Select Upload.
9. Connect to the head node of your Spark cluster via SSH.
10. Run the following command to copy [Link] from your Spark cluster's default storage to the Spark 2
conf folder on the cluster's local storage:
3. Keep this Spark Shell instance open and continue to the next step.
import [Link].{SQLContext, _}
import [Link]._
import [Link].{SparkConf, SparkContext}
import [Link]._
2. Run the following to define a catalog for the Contacts table you create in HBase. In the belowm you defines a
schema for the HBase table with name Contacts, identify the row key as key, and map the column names as
they will be used in Spark to the column family, column name and column type as they appear in HBase.
Note that the rowkey also has to be defined in details as a named column (rowkey), which has a specific
column family, cf, of rowkey.
3. Run the following to define a method that will provide a DataFrame around your Contacts table in HBase:
def withCatalog(cat: String): DataFrame = {
[Link]
.read
.options(Map([Link]->cat))
.format("[Link]")
.load()
}
val df = withCatalog(catalog)
[Link]()
6. You should see your two rows of data in output similar to the following:
+------+--------------------+--------------+-------------+--------------+
|rowkey| officeAddress| officePhone| personalName| personalPhone|
+------+--------------------+--------------+-------------+--------------+
| 1000|1111 San Gabriel Dr.|1-425-000-0002| John Dole|1-425-000-0001|
| 8396|5415 San Gabriel Dr.| 230-555-0191| Calvin Raji| 230-555-0191|
+------+--------------------+--------------+-------------+--------------+
7. Next, register a temp table so you can query the HBase table use Spark SQL:
[Link]("contacts")
+-------------+--------------------+
| personalName| officeAddress|
+-------------+--------------------+
| John Dole|1111 San Gabriel Dr.|
| Calvin Raji|5415 San Gabriel Dr.|
+-------------+--------------------+
[Link](newData).[Link]
.options(Map([Link] -> catalog))
.format("[Link]").save()
[Link]()
+------+--------------------+--------------+------------+--------------+
|rowkey| officeAddress| officePhone|personalName| personalPhone|
+------+--------------------+--------------+------------+--------------+
| 1000|1111 San Gabriel Dr.|1-425-000-0002| John Dole|1-425-000-0001|
| 16891| 40 Ellis St.| 674-555-0110|John Jackson| 230-555-0194|
| 8396|5415 San Gabriel Dr.| 230-555-0191| Calvin Raji| 230-555-0191|
+------+--------------------+--------------+------------+--------------+
Next Steps:
Read more about the Spark HBase Connector and view the source on GitHub.
Monitoring HBase with Operations Management
Suite (OMS)
8/15/2017 • 5 min to read • Edit Online
The HDInsight HBase Monitoring solution is a management solution for Azure Log Analytics that collects important
HDInsight HBase performance metrics from your HDInsight Cluster nodes and provides the tools to search the
metrics, as well HBase-specific visualizations and dashboards. By using the metrics that you collect with the
solution, you can create custom monitoring rules and alerts. You can monitor the metrics for multiple HDInsight
HBase clusters across multiple Azure subscriptions.
Log Analytics is a service in Operations Management Suite (OMS) that monitors your cloud and on-premises
environments to maintain their availability and performance. It collects data generated by resources in your cloud
and on-premises environments and from other monitoring tools to provide analysis across multiple sources.
Management solutions add functionality to OMS, providing additional data and analysis tools to Log Analytics. Log
Analytics management solutions are a collection of logic, visualization, and data acquisition rules that provide
metrics pivoted around a particular area. They may also define new record types to be collected that can be
analyzed with Log Searches or by additional user interface provided by the solution in the dashboard.
Insight & Analytics is built on the underlying Log Analytics platform. You can choose to use the Log Analytics
capabilities and pay per GB ingested into the service or switch your workspace to the Insight & Analytics tier and
pay per node managed by the service. Insight & Analytics offers a superset of the capabilities offered under Log
Analytics. The HBase Monitoring solution is available to either Log Analytics or Insight & Analytics.
When you provision the HDInsight HBase Monitoring solution, you will create an OMS workspace. You can think of
the workspace as a unique Log Analytics environment with its own data repository, data sources, and solutions. You
may create multiple workspaces in your subscription to support multiple environments such as production and
test.
5. In the Management Solutions blade, select the HDInsight HBase Monitoring management solution that
you want to add to a workspace.
6. In the management solution blade, review information about the management solution, and then click Create.
7. In the management solution name blade, select an existing workspace that you want to associate with the
management solution or create a new OMS workspace and then select it.
8. Change workspace settings for the Azure subscription, resource group, and location as appropriate.
9. Select Create.
10. To start using the management solution that you've added to your workspace, navigate to Log Analytics >
workspace name > Solutions. An entry for your management solution is displayed in the list. Click the
entry to navigate to the solution.
11. The blade for your HDInsight HBase monitoring solution should appear.
12. At this point, your Summary tiles will not show any data because you have yet to configure your HDInsight
HBase cluster to send data to Log Analytics.
4. In the Submit script action, set the Script type to "- Custom".
5. Provide a name for this script.
6. For the Bash Script URI, paste in the following URI:
[Link]
7. For the Node types, select all three (Head, Region, ZooKeeper).
8. In the Parameters text box, enter your Workspace ID and your Workspace Key, enclosing each value in
quotes and separating the two quoted values with a space.
"WorkspaceID" "WorkspaceKey"
For example:
"481506d5-f04e-4901-afa6-0a688232a1c1"
"bQCW1P27febK2k/S/+70jxgap2A2HTUU9V1YHE7nfW8uR31XZx3OEzJvnVNvOBo7pe+W5+ahn/my6JDtTIufcg=="
9. Select Persist this script action to rerun when new nodes are added to the cluster.
10. Select Create.
11. The Script Action will take a few minutes to run. You can monitor its status from Script Actions blade.
12. When the Script Action completes, you should see a green checkmark next to the script name in the listing.
6. Selecting any one of these will drill down into the Log Search view where you can refine the query and
explore the data in more detail.
See Also
You can create alerts against metrics collected by the HDInsight HBase Monitoring management solution, see
Creating Alerts for step by step instructions.
Learn more about how to conduct Log Searches.
HBase - Migrating to a New Version
8/16/2017 • 5 min to read • Edit Online
The process of upgrading HDInsight clusters is straightforward for most cluster types, such as Spark and Hadoop.
Since these are job-based clusters, the steps to conduct are to back up transient (locally stored) data, delete the
existing cluster, create a new cluster in the same VNET subnet, import transient data, and start jobs/continue
processing on the new cluster.
Since HBase is a database, there are additional steps one must take in order to upgrade. The general steps leading
up to the actual upgrade workflow remain the same, such as planning and testing. This article covers the additional
steps required for a successful HBase upgrade with minimal downtime.
Client-Server wire N Y Y
Compatibility
Server-Server Compatibility N Y Y
Stable N Y Y
Evolving N N Y
Unstable N N N
Dependency Compatibility N Y Y
Operational Compatibility N N Y
Please note that the above indicates what could break, not necessarily what will break. Specific breaking
changes should be outlined within the version release notes.
HDInsight upgrade with same HBase major version
The following scenario is for upgrading from HDInsight 3.4 to 3.6 with the same HBase major version. The same
general steps can be followed when upgrading other version numbers, provided no compatibility issues between
versions.
1. Make sure that your application works with the new version. This can be done by first checking the compatibility
matrix and release notes, as outlined in the previous section. You may also test your application in a cluster
running the target version of HDInsight and HBase.
2. Create a new HDInsight cluster, using the same storage account, but with a different container name.
3. Flush your source HBase cluster. This is the cluster from which you are upgrading. Run the following script,
the latest version of which can be found on GitHub:
#!/bin/bash
#-------------------------------------------------------------------------------#
# SCRIPT TO FLUSH ALL HBASE TABLES.
#-------------------------------------------------------------------------------#
LIST_OF_TABLES=/tmp/[Link]
HBASE_SCRIPT=/tmp/hbase_script.txt
TARGET_HOST=$1
usage ()
{
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]
then
cat << ...
Usage:
$0 [hostname]
For Example:
validate_machine ()
{
THIS_HOST=`hostname`
get_tables_list ()
{
hbase shell << ... > $LIST_OF_TABLES 2> /dev/null
list
exit
...
}
add_table_for_flush ()
{
TABLE_NAME=$1
echo "[INFO] Adding table '$TABLE_NAME' to flush list..."
cat << ... >> $HBASE_SCRIPT
flush '$TABLE_NAME'
...
}
clean_up ()
{
rm -f $LIST_OF_TABLES
rm -f $HBASE_SCRIPT
}
########
# MAIN #
########
usage $1
validate_machine
clean_up
get_tables_list
START=false
cat $HBASE_SCRIPT
When you write data to HBase, it is first written to an in-memory store, called a memstore. Once the memstore
reaches a certain size, it is flushed to disk for durability. This long-term storage is the cluster's storage account.
Since we will be deleting the old cluster, the memstores will go away, potentially losing data. The above script
manually flushes the memstore for each table for long-term retention.
4. Log in to Ambari for the new HDInsight cluster. We need to change the [Link] HDFS setting to
point to the container name used by the original cluster. This setting can be found under HDFS -> Configs ->
Advanced -> Advanced core-site.
5. Save your changes and restart all required services (Ambari will indicate which services require restart)
6. Point your application to the new cluster.
Avoid having your applications rely on a static DNS name for your cluster by hard-coding it, as it will change
when upgrading. There are two options we recommend to mitigate this issue: either configure a CNAME in
your domain name's DNS settings that points to the cluster's name, or use a configuration file for your
application that you can update without redeploying.
Next steps
In this article, we covered the steps necessary to upgrade an HBase cluster. Learn more about HBase and upgrading
HDInsight clusters by following the links below:
Learn how to upgrade other HDInsight cluster types
Learn more about connecting to and using Ambari to manage your clusters
Read in-depth information about changing Ambari configs, including settings to optimize your HBase and other
HDInsight clusters
Learn about the various Hadoop components available with HDInsight
8/16/2017 • 6 min to read • Edit Online
title: Introduction: Phoenix in HDInsight - Azure HDInsight | Microsoft Docs description: '' services: hdinsight
documentationcenter: ''
tags: azure-portal keywords: HBase,phoenix,sql
This typically yields a significant performance increase over executing queries without an index. Such secondary
indexes are known as a covering index, wherein the index contains all of the columns included in the query.
Therefore, the table lookup is not required and the index satisfies the entire query.
Views
Phoenix views provide a nice way to overcome one of HBase's limitations; the performance degredation
experienced when you create more than around 100 physical tables. Views help in this regard by enabling multiple
virtual tables to share the same underlying physical HBase table.
Creating views is very similar to using standard SQL view syntax. One primary difference is that you can define
additional columns for your view in addition to the columns inherited from its base table. You may also optionally
add new KeyValue columns.
For example, let's suppose we have a physical table named product_metrics with the following definition:
We can define a view over top of this table, that adds additional columns:
If you wish to alter an existing table to be transactional, use the same property in an ALTER statement:
Be aware that you cannot switch a transactional table back to being non-transactional.
Example:
Find the Phoenix SQL configuration section to enable/disable phoenix, as well as set the query timeout in minutes
and seconds.
Next steps
In this article, we introduced Phoenix, and how it can help improve both development and query execution
efficiency when using an HBase HDInsight cluster.
Get some hands-on experience with Phoenix: Use Apache Phoenix with Linux-based HBase clusters in HDInsight
Use Apache Phoenix with HBase clusters in HDInsight
8/16/2017 • 5 min to read • Edit Online
If you want to query HBase using SQL instead of scans, you can by using Apache Phoenix in HDInsight. You use the
SQLLine utility to submit SQL to Phoenix and view the results.
For more information about Phoenix, see Phoenix in 15 minutes or less and Phoenix in HDInsight for an overview.
For information on the Phoenix grammar, see Phoenix Grammar.
NOTE
For the Phoenix version information in HDInsight, see What's new in the Hadoop cluster versions provided by HDInsight?.
To highlight how you can efficiently leverage HDInsight HBase and Phoenix to analyze big data stores, this
walkthrough shows you how to use HBase Phoenix to do sales analysis of an imaginary online book store.
Upload sample data to HDInsight cluster storage account
To begin, we need to upload the sample data we'll use for the remaining exercies. Read more about various ways
to upload data for Hadoop jobs in HDInsight.
1. Browse to the HBase HDInsight cluster on the Azure portal.
2. On the left-hand menu, select Storage accounts.
3. Select your Azure Blob Storage or Azure Data Lake Store account listed in the Storage accounts pane.
4. Browse to the /example/data folder.
If using Azure Blob Storage, the /example/data folder will be located within your cluster's container.
In Azure Data Lake Store, use the data explorer to navigate to /clusters/hbase/example/data .
5. Upload the sample [Link] file to this location.
Bulk Load data into HBase using Phoenix
Phoenix provides two ways to bulk load into HBase. The PSQL command line utility, which is a single-threaded
client loading tool, and a MapReduce bulk loading utility. PSQL is suited for gigabytes of data, whereas
MapReduce is used for much larger data volumes.
To bulk upload data into HBase using the Phoenix PSQL command line tool, perform the following actions:
1. SSH into your HBase cluster. For more information, see Use SSH with HDInsight.
2. From SSH, run the following commands to run SQLLine:
cd /usr/hdp/current/phoenix-client/bin
./[Link] <ZooKeeperHostname>:2181:/hbase-unsecure
Note: The above query creates a weblogs table with two column families, t1 and t2. Column families are
stored separately in different HFiles, thus it makes sense to have a separate column family for data
which is queried often. The paymentamount, quantity, and shippingamount columns will be queried
often, so they are in a different column family.
5. Now, let's copy the [Link] file from our storage acount via hdfs to our local temp directory.
6. Finally, we'll use PSQL to bulk insert the rows into our new HBase table.
The above code executes the PSQL client utility to bulk upload data into the weblogs table. It takes three
parameters: table name (-t), zookeeper fqdn, and the path of the csv file to bulk load from.
Once the PSQL operation is complete, you should have an output on your command window similar to the
following:
+---------------------------------------+---------------+
| BOOKNAME | QUANTITYSOLD |
+---------------------------------------+---------------+
| Advances in school psychology | 90233 |
| History of political economy | 93772 |
| New Christian poetry | 90467 |
| Science in Dispute | 92221 |
| Space fact and fiction | 95544 |
| THE BOOK OF WITNESSES | 93753 |
| The adventures of Arthur Conan Doyle | 93710 |
| The voyages of Captain Cook | 94207 |
| Understanding American politics | 91119 |
+---------------------------------------+---------------+
9 rows selected (21.942 seconds)
Next steps
In this article, you have learned how to use Apache Phoenix in HDInsight. To learn more, see:
HDInsight HBase overview: HBase is an Apache, open-source, NoSQL database built on Hadoop that provides
random access and strong consistency for large amounts of unstructured and semistructured data.
Provision HBase clusters on Azure Virtual Network: With virtual network integration, HBase clusters can be
deployed to the same virtual network as your applications so that applications can communicate with HBase
directly.
Configure HBase replication in HDInsight: Learn how to configure HBase replication across two Azure
datacenters.
Analyze Twitter sentiment with HBase in HDInsight: Learn how to do real-time sentiment analysis of big data by
using HBase in a Hadoop cluster in HDInsight.
8/16/2017 • 6 min to read • Edit Online
title: Introduction: Bulk Loading with Phoenix via psql in HDInsight - Azure HDInsight | Microsoft Docs description: ''
services: hdinsight documentationcenter: ''
tags: azure-portal keywords: HBase,phoenix,sql
2. Copy your CSV file (such as [Link] shown below) into a /tmp/ directory for loading into your
newly-created table. Use the hdfs command (shown below) to copy your CSV file to your desired source
location.
1,Samantha,260000.0,18,US
2,Sam,10000.5,56,US
3,Anton,550150.0,Norway
... 4997 more rows
1. Create a SQL SELECT query to verify the input data loaded properly using standard SQL syntax. Save your
query as a [Link] file. Query to execute on the data: You can put any SQL query which you
would like to run on the data (let’s say [Link]). A Sample query:
2. Bulk Load the data by opening a new* Hadoop command line window and running the cd... and Bulk
Load [Link] commands shown below, to first change to the execution directory location and to exectute
the bulk load using the psql tool. Note: The example shown below assumes that you have copied the
[Link] file from our storage acount via hdfs to your local temp directory.
cd /usr/hdp/current/phoenix-client/bin
python [Link] ZookeeperQuorum [Link] /tmp/[Link] [Link]
Tip: To determine the ZookeeperQuorum name you'll need to locate the zookeeper quorum string. The zookeeper
string is present in file /etc/hbase/conf/[Link] . The name of property is [Link] .
After the psql operation has completed, you should see an output on your command window similar to the one
below:
cd /usr/hdp/current/phoenix-client/bin
/usr/hdp/current/phoenix-client$ HADOOP_CLASSPATH=/usr/hdp/current/hbase-client/lib/hbase-
[Link]:/etc/hbase/conf hadoop jar \
/usr/hdp/[Link]-258/phoenix/[Link]
[Link] --table Customers --input \
/inputFolderBulkLoad/[Link] –zookeeper ZookeeperQuorum:2181:/hbase-unsecure
Note: If you are bulk-loading via MapReduce from ADLS Storage, then you need to locate the root directory for
ADLS. In order to find root directory, locate the entry for [Link] in [Link] .
In the command below, adl://[Link]/hbase1 is the ADLS root directory. In
order to run bulk load command, cd to /usr/hdp/current/phoenix-client and pass ADLS input and output folders
as parameters as shown below:
Recommendations
1. Use the same storage medium: Use same storage medium for both input and output folders. This means that
both the input and output folders should be either in WASB or in ADLS. If you want to transfer data from WASB
to ADLS, you can use the distcp command. An example command is shown below.
1. Use larger-size worker nodes: The map processes of the MapReduce bulk copy produce large amounts of
temporary output which fill up the available non-DFS space. Use a larger sized worker node VM if you intend
to perform a large amount of bulk loading. The number of worker nodes you allocate to your cluster will
directly affect the processing speed of the bulk load activity.
2. Split input files: Because the bulk load is a storage-intensive operation, splitting your input files into multiple
chunks(~10GB each) and then perform bulk load on them will result in better performance.
3. Avoid Region Server hotspots: HBase sequential write may suffer from region server hotspotting if your row
key is monotonically increasing. Salting the row key provides a way to mitigate this problem. Phoenix
provides a way to transparently salt the row key with a salting byte for a particular table. See link in the 'next
steps' section for more detail.
Next steps
In this article, you have learned how to use bulk load data using psql and the MapReduce command from Apache
Phoenix in HDInsight. To learn more, see:
Bulk Data Loading with Apache Pheonix
Use Apache Phoenix with Linux-based HBase clusters in HDInsight
Salted Tables
Phoenix Grammar
Read and Write Phoenix Data from a Spark cluster
8/15/2017 • 1 min to read • Edit Online
Apache HBase data can be queried either with its low level API of scans, gets and puts or with a SQL syntax using
Apache Phoenix. Phoenix is an API for HBase which uses a JDBC driver (rather than Hadoop MapReduce) to extend
the HBase key-value store to enable features that make it similiar to a relational database. These features include
adding a SQL query engine, metadata repository and an embedded JDBC driver. Phoenix was originially developed
at Salesforce, and it was subsequently open-sourced as an Apache project. It is important to note that Phoenix is
desinged to work only with HBase data.
Apache Spark can be used as a convenient and performant alternative way to query and modify data stored by
HBase. This method of cross-cluster access is enabled by the use of the Spark-HBase Connector (also called the
SHC ). See Using Spark to Query HBase for details on this approach.
IMPORTANT As of this writing (June 2017) HDInsight does not support the open source Apache Spark plugin
for Phoenix. You are advised to use the Spark-HBase connector to support querying HBase from Spark at this
time.
See Also
Using Spark to Query HBase
Spark HBase Connector
Phoenix Spark depenency list
Apache Phoenix and HBase Past Present and Future of SQL over HBase
New Features in Apache Phoenix
Apache Spark Plugin for Apache Phoenix
Using the Phoenix Query Server REST SDK
8/16/2017 • 11 min to read • Edit Online
Apache Phoenix is an open source, massively parallel relational database layer over HBase. It allows you to use
SQL-like queries over HBase through tools like SQLLine using SSH. Phoenix also provides an HTTP server called
Phoenix Query Server (PQS) that exposes a thin client that supports two transport mechanisms, JSON and Protocol
Buffers, for client communication. Protocol Buffers is the default mechanism, and offers more efficient
communication than JSON.
In this article, we'll show you how to use the PQS REST SDK to create tables, upsert rows individually and in bulk,
and select data using SQL statements. We'll be using the Microsoft .NET driver for Apache Phoenix Query Server in
our examples. This SDK is built on Apache Calcite's Avatica APIs, which exclusively uses Protocol Buffers as the
serialization format.
Refer to the Apache Calcite Avatica Protocol Buffers Reference for more information.
Install-Package [Link]
Replace CLUSTERNAME with your HDInsight HBase cluster name, and USERNAME and PASSWORD with the
Hadoop credentials specified on cluster creation. The default Hadoop user name is admin.
In each of our samples, you will see that we initially make a call to the OpenConnectionRequestAsync method, passing
in the unique connection id. We subsequently define ConnectionProperties and RequestOptions , passing those
objects as well as the generated connection id to the ConnectionSyncRequestAsync method. PQS's
ConnectionSyncRequest object helps ensure that the client and server have a consistent view of the database
properties.
The ConnectionSyncRequest ConnectionProperties
When you make a call to ConnectionSyncRequestAsync , you pass a ConnectionProperties object:
PROPERTY DESCRIPTION
try
{
// Opening connection
var info = new pbc::MapField<string, string>();
openConnResponse = await [Link](connId, info, options);
// Syncing connection
ConnectionProperties connProperties = new ConnectionProperties
{
HasAutoCommit = true,
AutoCommit = true,
HasReadOnly = true,
ReadOnly = false,
TransactionIsolation = 0,
Catalog = "",
Schema = "",
IsDirty = true
};
await [Link](connId, connProperties, options);
if (openConnResponse != null)
{
[Link](connId, options).Wait();
openConnResponse = null;
}
}
We created a new table named "Customers" using the IF NOT EXISTS option. The CreateStatementRequestAsync call
is used to create a new Statement in the Avitica (PQS) server. In the finally block, we ensure that the
CreateStatementResponse that this method returns, as well as the OpenConnectionResponse object are properly
closed.
var states = new List<string> { "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FM", "FL", "GA",
"GU", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MH", "MD", "MA", "MI", "MN", "MS", "MO", "MT",
"NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "MP", "OH", "OK", "OR", "PW", "PA", "PR", "RI", "SC", "SD",
"TN", "TX", "UT", "VT", "VI", "VA", "WA", "WV", "WI", "WY" };
We'll use the table's StateProvince column value in a select operation later on.
}
catch (Exception ex)
{
}
finally
{
if (statementHandle != null)
{
await [Link](connId, [Link], options);
statementHandle = null;
}
if (openConnResponse != null)
{
await [Link](connId, options);
openConnResponse = null;
}
}
The overall structure of executing an insert statement is very similar to how we created a new table. One thing of
note is at the end of the try block, we explicitly commit the transaction. Also notice that we are executing an insert
request 300 times since it's in a loop. This makes for a lengthly process due to excessive requests over a thin client.
A more efficient execution plan is to insert our records within a batch process.
// Creating statement
createStatementResponse = await [Link](connId, options);
}
catch (Exception ex)
{
}
finally
{
if (openConnResponse != null)
{
await [Link](connId, options);
openConnResponse = null;
}
}
In our environment, individually inserting 300 new records took almost 2 minutes. Inserting 300 records as a batch,
however, took only about 6 seconds!
Selecting data
In this example, we'll show how you can reuse the same connection to execute multiple queries. First we'll
demonstrate selecting all, and fetching remaining records once the default maximum of 100 have been returned.
Then we'll show using a total row count select statement, retrieving the single scalar result. Finally, we'll execute a
select statement that returns the total number of customers per State.
try
{
// Opening connection
pbc::MapField<string, string> info = new pbc::MapField<string, string>();
openConnResponse = await [Link](connId, info, options);
// Syncing connection
ConnectionProperties connProperties = new ConnectionProperties
{
HasAutoCommit = true,
HasAutoCommit = true,
AutoCommit = true,
HasReadOnly = true,
ReadOnly = false,
TransactionIsolation = 0,
Catalog = "",
Schema = "",
IsDirty = true
};
await [Link](connId, connProperties, options);
var createStatementResponse = await [Link](connId, options);
// Running query 2
string sql2 = "select count(*) from Customers";
ExecuteResponse countResponse = await [Link](connId, sql2,
[Link], [Link], [Link], options);
long count = [Link][0].[Link][0].Value[0].[Link];
// Running query 3
string sql3 = "select StateProvince, count(*) as Number from Customers group by StateProvince order by
Number desc";
ExecuteResponse groupByResponse = await [Link](connId, sql3,
[Link], [Link], [Link], options);
}
finally
{
if (statementHandle != null)
{
await [Link](connId, [Link], options);
statementHandle = null;
}
}
if (openConnResponse != null)
{
await [Link](connId, options);
openConnResponse = null;
}
}
The output of the executed select statements should yield the following result:
id0 first0
id1 first1
id10 first10
id100 first100
id101 first101
id102 first102
...
...
id185 first185
id186 first186
id187 first187
id188 first188
NJ: 21
CA: 19
GU: 17
NC: 16
IN: 16
MA: 16
AZ: 16
ME: 16
IL: 15
OR: 15
...
...
MO: 10
HI: 10
GA: 10
DC: 9
NM: 9
MD: 9
MP: 9
SC: 7
AR: 7
MH: 6
FM: 5
Next steps
Learn more about Phoenix in HDInsight
Read Using the HBase REST SDK for information on another HBase-related SDK you can use.
Phoenix Performance Best Practices
8/15/2017 • 11 min to read • Edit Online
This article provides the fundamental techniques you should consider when optimizing the peformance of your
Phoenix deployment on HDInsight.
However, if you frequently query by lastName this would not perform well because you would need to do a table
scan and read the value of every lastname, so you might define a primary key on the lastName, firstName and a
social security number (to disambiguate two residents at the same address with the same name, like a father and
son).
SOCIALSECURITYN
ROWKEY ADDRESS PHONE FIRSTNAME LASTNAME UM
If you defined a primary key on the table for on lastName, firstName and socialSecurityNum your row keys as
generated by Phoenix might look as follows:
SOCIALSECURITYN
ROWKEY ADDRESS PHONE FIRSTNAME LASTNAME UM
By way of example, for the fist row in the example above the data stored actually looks like:
As you can see, the rowkey now stores a duplicate copy of the data. It is important to be aware of the size and
number of columns you include in your Primary Key, because this value is included with every cell in the underlying
HBase table.
Also, if the primary key you have selected has values that are monotonically increasing, you should create the table
with salt buckets (see the Partition Data section below) to help avoid creating write hotspots.
Column Family Design
Choosing which columns to group into the same column family is another important consideration. If some
columns are accessed more frequently than others, you should create multiple column families to separate the
frequently-accessed columns from rarely-accessed columns.
Another consideration, is to identify which columns tend to be accessed together and put those in the same column
family.
Column Design
There are a few considerations to what you store within a column as well:
Keep VARCHAR columns under 1MB or so due to the I/O costs of large columns. When processing queries,
HBase materializes cells in full before sending them over to the client, and the client receives them in full before
handing them off to the application code.
Store column values using a compact format such as protobuf, Avro, msgpack or BSON. Avoid JSON if you can
as it is significantly less compact.
Consider compressing data before storage to cut latency and I/O costs.
Partition Data
Phoenix enables you to control the number of regions on which your data is distributed, which can significantly
increase read/write performance. You can accomplish this either by salting or pre-splitting your data. Both are tasks
you perform when creating your Phoenix table.
To salt a table during creation, you specify the number of salt buckets, for example:
Salting does the splitting of the table along the value of primary key lines, choosing the values automatically. If you
want to control where the table splits occur, you can pre-split the table by providing the actual values that define
the ranges alon which the splitting occurs. For example, the following creates a table that will be split along five
regions:
Index Design
A Phoenix index is an HBase table that stores a copy of some or all of the data from the table that it indexes. You
apply an index to benefit specific kinds of queries.
When you have an index in place and you query a table, Phoenix selects the best index for the query automatically.
The primary index is created automatically based on the primary keys you select. You can also create secondary
indexes by specifying which columns are included based on the anticipated queries the index will support.
When designing your indexes, keep the following points in mind:
Only create the indexes you need.
Limit the number of indexes on frequently updated tables (since updates to a table translates into writes to both
the main table and the tables containing the indexes).
SOCIALSECURITYN
ROWKEY ADDRESS PHONE FIRSTNAME LASTNAME UM
SOCIALSECURITYN
ROWKEY ADDRESS PHONE FIRSTNAME LASTNAME UM
However, if we frequently want to look up the firstName and lastName given the socialSecurityNum, we could
create a covered index as follows that includes the firstName and lastName as actual data in the index table:
This would enable the following query to acquire all data just be reading from the table containing the secondary
index:
SELECT socialSecurityNum, firstName, lastName FROM CONTACTS WHERE socialSecurityNum > 100;
Query Design
Naturally, an important aspect of performant Phoenix queries is the actual design of your query.
The main considerations in query design are:
Understand the query plan and make sure it is as expected
Join efficiently
Understand the query plan
In SQLLine, use EXPLAIN followed by your SQL query to view the plan of operations that Phoenix will perform
when executing the query.
The key things to look for are:
Plan is using your primary key when appropriate.
Plan uses the secondary indexes you intend, as opposed to the data table.
Plan uses RANGE SCAN or SKIP SCAN whenever possible rather than TABLE SCAN.
Plan examples
Assume you have a table called FLIGHTS that stores flight delay information.
Say you wanted to select all the flights with the AIRLINEID of "19805" which is not a field that is in the primary key
nor in any index:
select * from "FLIGHTS" where airlineid = '19805';
CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER FLIGHTS
SERVER FILTER BY AIRLINEID = '19805'
In the above plan, notice the phrase FULL SCAN OVER FLIGHTS. This indicates the execution will do a TABLE SCAN
over all rows in the table, instead of using the more efficient RANGE SCAN or SKIP scan option.
Now, say you want to query for flights in January 1st, 2014 for the carrier "AA" where its flightnum was greater
than 1. Let's assume that the columns year, month, dayofmonth, carrier and flightnum exist in our table, and are all
part of the composite primary key. Our query would look as follows:
select * from "FLIGHTS" where year = 2014 and month = 1 and dayofmonth = 2 and carrier = 'AA' and flightnum >
1;
explain select * from "FLIGHTS" where year = 2014 and month = 1 and dayofmonth = 2 and carrier = 'AA' and
flightnum = 1;
CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER FLIGHTS [2014,1,2,'AA',2] - [2014,1,2,'AA',*]
Notice in the above the values in square brackets after the table name show the range of values for the primary
keys having values that are fixed with year of 2014, month of 1, dayofmonth of 2 but allow values for flightnum
starting (and including) 2 and upwards. This query plan confirms our primary key is being used as we would expect.
Next, say we created an index on the flights table called carrier2_idx that is on the carrier field only, but includes
flightdate, tailnum, origin and flightnum as covered columns whose data is also stored in the index.
Say we want to get the carrier along with the flightdate and tailnum, as in the following query:
We should see this index used, as the explain command would show:
CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN RANGE SCAN OVER CARRIER2_IDX ['AA']
In the above notice it used our CARRIER2_IDX with the key value of 'AA', as was expected.
For a complete listing of the items that can appear in explain plan results, see the Explain Plans section in the
Apache Phoenix Tuning Guide
Join efficiently
Generally, you will want to avoid joins unless one side is small, especially on frequent queries.
If necessary, you can do large joins with the /+ USE_SORT_MERGE_JOIN */ hint, but a big join will be an expensive
operation over huge numbers of rows. If the overall size of all right-hand-side tables would exceed the available
memory, use the /+ NO_STAR_JOIN */hint.
Scenarios
There are some common patterns we can use to apply the aforementioned guidance. The following provides
guidance on each.
Read-heavy workloads
For read-heavy use cases, make sure you are using indexes. Additionally, to save read-time overhead, consider
creating covered indexes.
Write -heavy worklaods
For write-heavy workloads, if the primary key is monotonically increasing, create salt buckets to help avoid write
hotspots at the expense of overall read throughput due to the additional scans needed. Also, when using UPSERT to
write a large number of records, turn off autocommit and batch records (instead of writing them one by one).
Bulk deletes
When deleting a large data set, turn on autoCommit before issuing the DELETE query so that the client does not
need to remember the row keys of all the keys as they are deleted. This prevents the client from buffering the rows
affected by the DELETE so that Phoenix can delete them directly on the region servers without the expense of
returning them to the client.
Immutable and Append-Only
If your scenario favors write-speed over data integrity, you can consider disabling the write ahead log. This is an
option specified when you are creating your table and takes effect when the DISABLE_WAL option is set to true. For
example:
See Also:
Phoenix Tuning Guide
Secondary Indexes
Install third-party Hadoop applications on Azure
HDInsight
8/16/2017 • 8 min to read • Edit Online
In this article, you will learn how to install an already published third-party Hadoop application on Azure
HDInsight. For instructions on installing your own application, see Install custom HDInsight applications.
About ISVs
ISVs, or Independent Software Vendors, are organizations who build products, provide custom development
services, and serve as a valuable resource to Microsoft and our customers. We invite ISVs to leverage the capability
to make it easier for customers to discover and use your solution through the Azure Marketplace. Please reach out
to hdipartners@[Link] if you would like to participate.
Prerequisites
All that's needed is an existing HDInsight cluster, or you can follow steps to create an HDInsight cluster.
6. Click one of the applications, accept the legal terms, and then click Select.
You can see the installation status from the portal notifications (click the bell icon on the top of the portal). After
the application is installed, the application will appear on the Installed Apps blade.
5. Click one of the installed applications to show the property. The property blade lists:
App name: application name.
Status: application status.
Webpage: The URL of the web application that you have deployed to the edge node if there is any. The
credential is the same as the HTTP user credentials that you have configured for the cluster.
HTTP endpoint: The credential is the same as the HTTP user credentials that you have configured for the
cluster.
SSH endpoint: You can use SSH to connect to the edge node. The SSH credentials are the same as the
SSH user credentials that you have configured for the cluster. For information, see Use SSH with
HDInsight.
6. To delete a application, right-click the application, and then click Delete from the context menu.
Troubleshoot
See Troubleshoot the installation.
Next steps
Install custom HDInsight applications: learn how to deploy an un-published HDInsight application to HDInsight.
Publish HDInsight applications: Learn how to publish your custom HDInsight applications to Azure Marketplace.
MSDN: Install an HDInsight application: Learn how to define HDInsight applications.
Customize Linux-based HDInsight clusters using Script Action: learn how to use Script Action to install
additional applications.
Create Linux-based Hadoop clusters in HDInsight using Resource Manager templates: learn how to call
Resource Manager templates to create HDInsight clusters.
Use empty edge nodes in HDInsight: learn how to use an empty edge node for accessing HDInsight cluster,
testing HDInsight applications, and hosting HDInsight applications.
Install published application - Dataiku DDS on Azure
HDInsight
8/16/2017 • 5 min to read • Edit Online
In this article, you will learn how to install the Dataiku DDS published Hadoop application on Azure HDInsight. Read
Install third-party Hadoop applications for a list of available Independent Software Vendor (ISV) applications, as
well as an overview of the HDInsight application platform. For instructions on installing your own application, see
Install custom HDInsight applications.
Prerequisites
When creating a new HDInsight cluster, or to install on an existing one, you must have the following configuration
to install this app:
Cluster tier(s): Standard, Premium
Cluster type(s): Hadoop, Spark
Cluster version(s): 3.4, 3.5
In the New project form, type in a Name. The Project Key will be automatically filled with a suggested
value. In this case, enter "Orders". Click CREATE.
Click + IMPORT YOUR FIRST DATASET in your new project page.
Select Upload your files under the Files dataset list. You are presented with the Upload dialog. Click on
Add a file, select the haiku_shirt_sales.csv file you downloaded, and validate.
The file is uploaded to DSS. Let’s now check if DSS detected our CSV format correctly by clicking on the
Preview button:
The import is almost perfect. The CSV has been detected using a Tab separator. You can see the data is in a
tabular format, with colums called features and lines which represent observations. One thing is wrong with
our dataset though… Apparently the file contained a blank line between the header and the data. Let’s just
input 1 in the Skip next lines to sort this out:
We can now give our new dataset a name. Enter haiku_shirt_sales in the field on top of the screen. Finally,
we need to save our work by either hitting the Create button or using the shortcut Ctrl-S.
Your dataset has been created, and you are now taken to a tabular view of your data where you can start
exploring it. For each column, you should see that Dataiku Science Studio has detected a meaning, in blue (in
our case Text, Number or Date (unparsed)). A gauge indicates the ratio of the column for which the values
do not seem to match the meaning (in red) or are completey missing (blank). In our dataset, for example, the
department has empty values, as well as invalid data.
Data manipulation
The Data Scientists’ Murphy’s law states that real world data is never in the right format. Cleaning it up usually
consists of a chain of scripts with a lot of business logic, that are always difficult to maintain. Sadly, a large part of
the job of the Data Scientist is to clean up data. Dataiku DSS has a dedicated tool to make this task more user-
friendly.
Let’s get started with data manipulation:
Click on Lab in the upper-right corner.
The Lab window opens. The lab is where you will iteratively work on your dataset to get further into it. In this
tutorial, we are going to use the Visual analysis part of the Lab. Click on the New button below Visual
analysis. You will be prompted to specify a name for your analysis. Let’s leave the default name for now,
then click CREATE.
Now let's quickly make sense of our data by clicking on the Quick columns stats button on the upper-right
corner of the page as shown:
You will see statistics based on data type and values displayed in timeline-based graphs under the Columns
quick view pane.
That's it for now. DSS is such a powerful tool with an intuitive interface, it won't take you very long to create
visualizations for this data, figure out ways to clean up the data, and work with it in a multitude of ways.
To view the complete tutorial, along with others that go into greater detail, visit the Learn Dataiku DSS page next.
Next steps
Read the Dataiku DSS reference docs.
Install custom HDInsight applications: learn how to deploy an un-published HDInsight application to HDInsight.
Publish HDInsight applications: Learn how to publish your custom HDInsight applications to Azure Marketplace.
MSDN: Install an HDInsight application: Learn how to define HDInsight applications.
Customize Linux-based HDInsight clusters using Script Action: learn how to use Script Action to install
additional applications.
Use empty edge nodes in HDInsight: learn how to use an empty edge node for accessing HDInsight cluster,
testing HDInsight applications, and hosting HDInsight applications.
Install published application - Datameer on Azure
HDInsight
8/16/2017 • 4 min to read • Edit Online
In this article, you will learn how to install the Datameer published Hadoop application on Azure HDInsight. Read
Install third-party Hadoop applications for a list of available Independent Software Vendor (ISV) applications, as
well as an overview of the HDInsight application platform. For instructions on installing your own application, see
Install custom HDInsight applications.
About Datameer
Sitting natively on the powerful Hadoop platform, Datameer extends existing Azure HDInsight capabilities by
facilitating quick integration, preparation and analysis of all structured and unstructured data. Datameer makes it
easy to ingest and integrate data with more than 70 sources and formats: structured, semi-structured, and
unstructured. You can directly upload data, or use their unique data links to pull data on demand. Datameer’s self-
service functionality and familiar spreadsheet interface reduces the complexity of big data technology and
dramatically accelerates time to insight. The spreadsheet interface provides a simple mechanism for entering
declarative spreadsheet formulas that are translated to fully optimized Hadoop jobs. If you have BI or Excel skills,
you can use Hadoop in the cloud quickly.
Datameer documentation
Prerequisites
When creating a new HDInsight cluster, or to install on an existing one, you must have the following configuration
to install this app:
Cluster tier: Standard
Cluster type: Hadoop
Cluster version: 3.4
After completing your selected license option, you'll be presented with a login form. Enter the default credentials
displayed prior to the login form. After logging in, accept the softwarae agreement to continue.
Now that you've logged into Datameer, please follow these steps for a "Hello World" demonstration:
Download the sample CSV.
Click the + sign on top of the Datameer dashboard, and click File Upload.
In the upload dialog, browse and select the Hello [Link] file you just downloaded. Make sure the File
Type is set to CSV / TSV. Click Next. Keep clicking Next until you reach the end of the wizard.
Name the file Hello World underneath a New Folder. You may rename the new folder as "Demo", or
similar. Click Save.
Click the + sign once more and select Workbook to create a new Workbook for our data.
Expand the Data folder, FileUploads, then the Demo folder you created when saving the "Hello World" file.
Select Hello World form the list of files, then click Add Data.
You will now see the data loaded in a familiar spreadsheet interface. Click the Filter button in the toolbar to
select a subset of the data.
In the Apply Filter dialog, select the City column, equals operator, and type Chicago in the filter text box.
Check the Create filter in new sheet checkbox, then click Create Filter.
Save the Workbook by clicking File, then Save. Supply a name, such as "Hello World Workbook".
After entering your file name and clicking Save, you'll be presented with options for how and when to run
the Workbook. For now, leave all of the options at their default values, then check the Start calculation
process immediately after saave, and click Save.
Datameer provides powerful visualization tools. To display our data, we'll create an Infographic. Once again,
click the + sign on top of the dashboard, then select Infographic.
Drag a Bar Chart widget from the list of widgets on the left (step 1). Next, navigate through the Data folder
under the data browser on the right, expand your Workbook, then your worksheet you added with the filter
(step 2). Drag the Name column over top of the bar chart. Drop it into the Label target to set the
Workbook's Name column as the chart's label field.
Now drag the Age column into the chart's *Data field, thus setting Age as the chart's Y axis.
Congratulations! At this point, you've created a nice visualization of your data without writing any code. Feel free to
add text over top of your chart, change colors, and adding additional visualizations to discover the great options at
your disposal.
Next steps
Read the Datameer documentation
Install custom HDInsight applications: learn how to deploy an un-published HDInsight application to HDInsight.
Publish HDInsight applications: Learn how to publish your custom HDInsight applications to Azure Marketplace.
MSDN: Install an HDInsight application: Learn how to define HDInsight applications.
Customize Linux-based HDInsight clusters using Script Action: learn how to use Script Action to install
additional applications.
Use empty edge nodes in HDInsight: learn how to use an empty edge node for accessing HDInsight cluster,
testing HDInsight applications, and hosting HDInsight applications.
Install published application - H2O Sparkling Water
on Azure HDInsight
8/16/2017 • 3 min to read • Edit Online
In this article, you will learn how to install the H20 Sparkling Water published Hadoop application on Azure
HDInsight. Read Install third-party Hadoop applications for a list of available Independent Software Vendor (ISV)
applications, as well as an overview of the HDInsight application platform. For instructions on installing your own
application, see Install custom HDInsight applications.
Prerequisites
When creating a new HDInsight cluster, or to install on an existing one, you must have the following configuration
to install this app:
Cluster tier(s): Standard or Premium
Cluster type: Spark
Cluster version(s): 3.5 or 3.6
Now that you've logged into Jupyter Notebook and selected the H2O folder, please follow these steps for a "Hello
World" demonstration:
The first step when creating a new notebook is to configure the Spark environment. This information is
included in the Sentiment_analysis_with_Sparkling_Water example. When configuring the Spark
environment, be sure to use the correct jar, and specify the IP address provided by the output of the first cell.
Note: If you are unable to open H2O Flow (it just redirects you to a help page), try clearing your browser
cache. If still unable to reach it, you likely do not have enough resources on your cluster. Try increasing
the number of Worker nodes under the Scale cluster option in your cluster blade.
Select the Million_Songs.flow example from the menu on the right. When prompted with a warning, click
Load Notebook. This demo is designed to run in a few minutes using real data. The goal is to predict from
the data whether the song was released before or after 2004 using binary classification.
Find the path containing [Link], and replace the entire path with [Link]
[Link]/bigdata/laptop/milsongs/[Link].
Find the path containing [Link] and replace with [Link]
[Link]/bigdata/laptop/milsongs/[Link].
Click the Run All button on the toolbar to execute all statements within the notebook cells.
After several minutes, you should see an output similar to the following:
That's it! You've harnessed artificial intelligence in Spark within a matter of minutes. Feel free to explore more
examples in H2O Flow to get a feel for the different types of machine learning algorithms you can use.
Next steps
Read the H2O documentation
Install custom HDInsight applications: learn how to deploy an un-published HDInsight application to HDInsight.
Publish HDInsight applications: Learn how to publish your custom HDInsight applications to Azure Marketplace.
MSDN: Install an HDInsight application: Learn how to define HDInsight applications.
Customize Linux-based HDInsight clusters using Script Action: learn how to use Script Action to install
additional applications.
Use empty edge nodes in HDInsight: learn how to use an empty edge node for accessing HDInsight cluster,
testing HDInsight applications, and hosting HDInsight applications.
Install published application - StreamSets Data
Collector on Azure HDInsight
8/16/2017 • 2 min to read • Edit Online
In this article, you will learn how to install the StreamSets Data Collector for HDInsight published Hadoop
application on Azure HDInsight. Read Install third-party Hadoop applications for a list of available Independent
Software Vendor (ISV) applications, as well as an overview of the HDInsight application platform. For instructions
on installing your own application, see Install custom HDInsight applications.
Prerequisites
When creating a new HDInsight cluster, or to install on an existing one, you must have the following configuration
to install this app:
Cluster tier(s): Standard or Premium
Cluster version(s): 3.5 and above
In the New Pipeline window, enter a name for the pipeline ("Hello World"), optionally enter a description,
and click Save.
The Data Collector console will appear. The Properties panel displays pipeline properties.
You are now ready to follow the official StreamSets tutorial. This will provide you with detailed step-by-step
directions to create your first pipeline.
Next steps
Read the StreamSets Data Collector documentation
Install custom HDInsight applications: learn how to deploy an un-published HDInsight application to HDInsight.
Publish HDInsight applications: Learn how to publish your custom HDInsight applications to Azure Marketplace.
MSDN: Install an HDInsight application: Learn how to define HDInsight applications.
Customize Linux-based HDInsight clusters using Script Action: learn how to use Script Action to install
additional applications.
Use empty edge nodes in HDInsight: learn how to use an empty edge node for accessing HDInsight cluster,
testing HDInsight applications, and hosting HDInsight applications.
Install published application - Cask Data Application
Platform (CDAP) on Azure HDInsight
8/16/2017 • 5 min to read • Edit Online
In this article, you will learn how to install the CDAP published Hadoop application on Azure HDInsight. Read Install
third-party Hadoop applications for a list of available Independent Software Vendor (ISV) applications, as well as an
overview of the HDInsight application platform. For instructions on installing your own application, see Install
custom HDInsight applications.
About CDAP
Developing applications in the traditional Hadoop world is a not an easy task. Listed below are some key aspects
that add to the challenges faced by a Hadoop developer: -
Over the past few years, the increased interest in the Big Data space has resulted in a technology explosion in
the Hadoop ecosystem. It has become progressively difficult to keep track of all the existing technologies as well
as new ones come up.
Simple processes like data ingestion and ETL require a complicated setup which is not generally extensible or
reusable.
Apart from the significant learning curve involved in using each of the different Hadoop technologies, there is a
substantial amount of time spent in integrating all of them to form a data processing solution.
Moving from a proof-of-concept solution to a production-ready one is far from a trivial step involving multiple
iterations and can lead to an increased unpredictability in delivery times.
It is hard to locate data and trace its flow in an application. Collecting metrics and auditing is generally a
challenge and often requires building a separate solution.
How does CDAP help?
CDAP (Cask Data Application Platform) is a unified integration platform for big data. The highlight of CDAP is that a
user can focus on building applications rather than its underlying infrastructure and integration.
CDAP works using high-level concepts and abstractions which are familiar to developers and empowers them to
use their existing skills to build new solutions. These abstractions hide the complexities of internal systems and
encourage re-usability of solutions.
An extension called Cask Hydrator is available in CDAP, which provides a rich user interface to develop and
manage data pipelines. A data pipeline is composed of various plugins which perform several tasks like data
acquisition, transformation, analysis, and post-run operations.
Each CDAP plugin has well-defined interfaces which essentially means that evaluating different technologies
would just be a matter of replacing a plugin with another one – there is no need to touch the rest of the application.
CDAP pipelines provide a high-level pictorial flow of the data in your application which enables developers to
easily visualize the end-to-end flow of the data and all the steps involved in the processing starting from its
ingestion, to the various transformations and analyses performed on the data followed by the eventual writing into
an external data store.
Here is an example of a data pipeline which ingests twitter data in real time, filters out some tweets based on some
pre-defined criteria, transforms, and projects the data into a more readable format, groups them according to a set
of values and writes the results into an HBase store.
The end-to-end pipeline was completely built using the Cask Hydrator UI, utilizing its plugin interface and drag-
and-drop functionality to form connections between each stage. It is easy to isolate and modify the functionality of
each plugin independent of the rest of the pipeline. Using CDAP, similar pipelines can be built and validated in less
than a couple of hours. In the traditional Hadoop world, constructing such solutions could easily take a few days.
Additionally, CDAP provides an extension called Cask Tracker where you can visually trace the data as it flows
through the application. Cask tracker adds data governance to the system so that data assets are formally
managed throughout the application. You can track its lineage, collect relevant metrics, and audit the data trail
throughout the process.
Here is an illustration of how data is flowing in the above pipeline:
Prerequisites
When creating a new HDInsight cluster, or to install on an existing one, you must have the following configuration
to install this app:
Cluster tier: Standard
Cluster type: HBase
Cluster version: 3.4, 3.5
After signing in, you will be presented with the Cask CDAP GUI home page.
To get an idea of using the CDAP interface, click the Cask Market menu link on top of the page.
Once the datapack has been successfully loaded, click View Stream Details.
On the Access Log details page, click Enable within the Usage tab to enable metadata for the namespace.
You will see a graph displaying audit message information, once metadata has been enabled.
To explore the log data, click the Explore icon on top of the page.
You will see a sample SQL query. Feel free to modify, if desired, then click Execute.
After the query has finished, click the View icon under the Actions column.
After you've identified the business problem and have started collecting and processing your data, you need to
create a model that represents the question you wish to predict. Your model will use one or more machine learning
algorithms to make the type of prediction that best fits your business needs. The majority of your data should be
used to train your model, with the smaller portion being used to test or evaluate it.
After you create, load, test and evaulate your model, the next step is to deploy your model so that it can be used for
supplying answers to your question. The last step is to monitor your model's performance and tune, if necessary.
See also
Scenarios
Hive and Azure Machine Learning
Hive and Azure Machine Learning end-to-end
Using an Azure HDInsight Hadoop Cluster on a 1 TB dataset
Spark and MLLib
Machine learning with Spark on HDInsight
Spark with Machine Learning: Use Spark in HDInsight for analyzing building temperature using HVAC data
Spark with Machine Learning: Use Spark in HDInsight to predict food inspection results
Deep Learning, CNTK and others
Embarrassingly Parallel Image Classification, Using Cognitive Toolkit and TensorFlow on Azure HDInsight Spark
Data Science Azure Virtual Machine
Introducing [Link] on Azure HDInsight
ETL at Scale
8/16/2017 • 7 min to read • Edit Online
In this scenario, HDInsight is used to perform an Extract, Transform, and Load (ETL) process that filters and shapes
the source data, and then uses it to populate a database table. Specifically, this scenario describes:
Introduction to racecar telemetry
ETL process goals and data sources
The ETL workflow
Encapsulating the ETL tasks in an Oozie workflow
Automating the ETL workflow
Analyzing the loaded data
The scenario demonstrates how you can:
Use the .NET Library for Avro to serialize data for processing in HDInsight.
Use the classes in the .NET API for Hadoop WebClient package to upload files to Azure storage.
Use an Oozie workflow to define an ETL process that includes Pig, Hive, and Sqoop tasks.
Use the classes in the .NET API for Hadoop WebClient package to automate execution of an Oozie workflow.
The workflow and its individual components are described in following section.
Sometimes the sensor data malfuctions and we get nulls in the value. We want to use Hive to clean the records
before loading it into our data warehouse. We'll use a query like this:
## Using Power BI
Now that your data is in the final resting place, we can use Power BI to create visualizations.
To see the speed of the car over time, follow these steps:
3. In the Get Data window, click Azure on the left. Then click Azure SQL Database.
6. Fill in your Azure security credentials on the database credentials pane. Click OK.
8. Drag lap time over to the Axis and speed over to the Values section of the chart.
A key component of any data analytics solution is the data pipeline that acquires data, cleans and shapes the data
and performs and desired calculations or aggregations prior to landing the data in the serving location, from
which it will ultimately be consumed by clients, reports or API's. Fundamental to the success of the data pipeline is
repeatability, enabling the data movement and processing performed by the pipeline to be performed on a
schedule or triggered by the availability of new data.
This article introduces how to operationalize your data pipelines that achieve this repeatability using Oozie
running on HDInisght Hadoop clusters to build a complete data pipeline to prepare and process airline flight time-
series data.
In this scenario, suppose that you receive a flat file containing a batch of flight data for a time period (e.g.,
monthly). This flight data includes information such as the origin and destination airport, the miles flown, the
departure and arrival times, and a whole host of other data. Your goal with this pipeline is to be able to summarize
airline performance by day, such that each airline has one row for each day describing the total miles they flew
that day, as well as the average departure and arrival delays in minutes.
You want to build a pipeline that whenever a new time period worth of flight data arrives, the detailed flight
information is stored with your Hive data warehouse to support long term analytics and enables you to ask new
questions of the data. At the same time you are creating a much smaller, summarized version of the flight data
that has just the daily flight summaries you need at the moment. You want to be able to store the daily flight
summary data in a SQL Database that provides the reports for your website.
The following diagram illustrates the desired pipeline that is implemented in this article:
This recurring data pipeline can be implemented using Oozie, and this article shows how to implement it in a step
by step fashion.
Oozie Solution Overview
The desired pipeline can be achieved using Apache Oozie running within an HDInsight Hadoop cluster.
Oozie describes its pipelines in terms of actions, workflows and coordinators. Actions are what describe the actual
work to perform, such as running a Hive query. Workflows define the sequence of actions. A coordinator defines
the schedule overwhich the workflow is run, and can check for the availability of new data prior to launching an
instance of the workflow, delaying the run as needed.
The following diagram captures the high level design of the pipeline using Oozie:
The sections that follow walk thru the implementation of this pipeline.
Provision Azure Resources
To follow along with this article, you will need to provision an Azure SQL Database and an HDInsight Hadoop
cluster in the same location. The Azure SQL Database will be used both to store the summary data produced by
the pipeline, as well as the metadata store for Oozie.
Provision SQL Database
1. Using the Azure Portal, create a new Resource Group called oozie that will contain all of the resources used by
this article.
2. Within the oozie resource group, provision an Azure SQL Server and Database. You do not need a database
larger than the S1 Standard pricing tier.
3. Using the Azure Portal, navigate to the blade of your newly deployed SQL Database, and select Tools.
7. In the query editor text area, enter the following SQL statements to create the dailyflights table which will
store the summarized data that results from each run of the pipeline.
CREATE TABLE dailyflights
(
YEAR INT,
MONTH INT,
DAY_OF_MONTH INT,
CARRIER CHAR(2),
AVG_DEP_DELAY FLOAT,
AVG_ARR_DELAY FLOAT,
TOTAL_DISTANCE FLOAT
)
GO
8. On the Storage blade, leave the primary storage type set to Azure Storage, select Create new and provide a
name for the new account.
9. For the metastore settings, under the Select a SQL database for Hive, choose the database you previously
created.
10. Select Authenticate SQL Database
11. Enter your SQL database username and password, and choose select.
12. Back on the Metastore Settings, select your database for the Oozie metadata store and authenticate as you
did previously.
13. Select Next.
14. On the Summary blade, select Create to deploy your cluster.
Verify SSH Tunneling Setup
In order to utilize the Oozie Web Console to view the status of your coordinator and workflow instances, you will
need to setup an SSH tunnel to your HDInsight cluster.
Detailed step by step instructions are available in the article SSH Tunnel.
Note that you can also use Chrome with the Foxy Proxy extension to browse your cluster's web resources across
the SSH tunnel. You need to configure it to proxy all request thru the host "localhost" on port 9876, which is the
port upon which your tunnel is open.
This approach is compatible when using the Windows Subsystem for Linux, also known as Bash on Windows 10.
In summary, you will need to run the following command to open the tunnel to your cluster:
Once you have setup your proxy, you can verify the tunnel is operational by navigating to Ambari on your head
node by browsing to:
[Link]
To access the Oozie Web Console, from Ambari, select Oozie, Quick Links and then select Oozie Web Console.
If you can access the Oozie Web Console, you are good to go.
Configure Hive
You will need to upload the CSV file [Link] containing sample data for one month of flight data.
Copy this file up to the Azure Storage account attached to your HDInsight cluster and place it in the
/example/data/flights folder.
One way to accomplish this is using SCP in your bash shell session.
First, use SCP to copy the files from your local machine to the local storage of your HDInsight cluster head node:
Second, use the HDFS command to copy the file from your head node local storage to Azure Storage:
The sample data you will process is now available. However, the pipeline requires two Hive tables to be created
prior to its execution. You can create these using Ambari by following these steps:
1. Login to Ambari by navigating to [Link]
2. From the list of services, select Hive.
3. Select Go To View next to the Hive View 2.0 label.
4. In the query text area, paste the following statements to create the RawFlights table. The RawFlights table
provides a schema on read over any of the CSV files that appear within the /example/data/flights folder in
Azure Storage.
SET [Link]=nonstrict;
SET [Link]=nonstrict;
Observe the values present with the syntax ${}, these are Oozie variables that are configured later and Oozie will
substitute with the actual values at runtime.
The second step is a query in the file [Link] as follows:
DROP TABLE ${hiveTableName};
CREATE EXTERNAL TABLE ${hiveTableName}
(
YEAR INT,
MONTH INT,
DAY_OF_MONTH INT,
CARRIER STRING,
AVG_DEP_DELAY FLOAT,
AVG_ARR_DELAY FLOAT,
TOTAL_DISTANCE FLOAT
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t' STORED AS TEXTFILE LOCATION '${hiveDataFolder}';
INSERT OVERWRITE TABLE ${hiveTableName}
SELECT year, month, day_of_month, carrier, avg(dep_delay) avg_dep_delay,
avg(arr_delay) avg_arr_delay, sum(distance) total_distance
FROM flights
GROUP BY year, month, day_of_month, carrier
HAVING year = ${year} AND month = ${month} AND day_of_month = ${day};
This query creates a staging table that will store only the summarized data for one day, take note of the SELECT
statement that computes the average delays and total of distance flown by carrier by day. The data inserted into
this table stored at a known location (the path indicated by the hiveDataFolder variable) so that it can be used as
the source for Sqoop in the next step.
The third step is effectively to run the following sqoop command:
These three steps are expressed as three separate actions in the Oozie workflow (a file named [Link]):
The two Hive queries are accessed by their path in Azure Storage, and the remaining variable values are provided
by the [Link] file, for example:
nameNode=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]
jobTracker=hn0-[CLUSTERNAME].[UNIQUESTRING].[Link]
queueName=default
[Link]=true
appBase=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/oozie
[Link]=${appBase}/load_flights_by_day
hiveScriptLoadPartition=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/oozie/load_flights_by_day/
[Link]
hiveScriptCreateDailyTable=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/oozie/load_flights_by_d
ay/[Link]
hiveDailyTableName=dailyflights${year}${month}${day}
hiveDataFolder=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/example/data/flights/day/${year}/${
month}/${day}
sqlDatabaseConnectionString="jdbc:sqlserver://[SERVERNAME].[Link];user=[USERNAME];password=
[PASSWORD];database=[DATABASENAME]"
sqlDatabaseTableName=dailyflights
year=2017
month=01
day=03
Notice that the above [Link] file configures the workflow to run for the date January 3rd, 2017. The
following table summarizes each of the proeprties in more detail, and indicates from where you need to acquire
the value for your own environment.
nameNode The full path to the Azure Storage Container attached to your
HDInsight cluster.
jobTracker The internal hostname to your active cluster YARN head node.
Get this from Ambari- on the Ambari home page, select YARN
from the list of services, then choose Active Resource
Manager. The URI displayed at the top of the page is what
you are after. Append the port 8050.
queueName The name of the YARN queue that is used when scheduling
the Hive actions. Leave as default.
hiveDailyTableName The dynamically generated name to use for the staging table
sqlDatabaseTableName The name of the table in Azure SQL Database into which
summary rows are inserted. Leave as dailyflights.
year The year component of the day for which flight summaries are
computed. Leave as is.
month The month component of the day for which flight summaries
are computed. Leave as is.
day The day of month component of the day for which flight
summaries are computed. Leave as is.
Before you can deploy and run your Oozie workflow, be sure to update your copy of the [Link] file with the
values specific to your environment.
Deploy and run the Oozie Workflow
To deploy your Oozie workflow ([Link]), the Hive queries ([Link] and hive-create-
[Link]) and the [Link] configuration file, you can use SCP from your bash session.
With Oozie, the only the [Link] file must exist on the local storage of the headnode. All other files must be
stored in HDFS (Azure Storage). Additionally, the Sqoop action used by the workflow depends on a JDBC driver for
communicating with SQL Database, which must be copied from the head node to HDFS. The following instructions
walk thru each of these steps:
1. Create the load_flights_by_day subfolder underneath the user's path in the local storage of the head node:
3. SSH into your head node and naviagate into the load_flights_by_day folder:
ssh sshuser@[CLUSTERNAME]-[Link]
cd load_flights_by_day
5. Copy the [Link] from the local head node to the workflow folder in HDFS:
7. Observe the status using the Oozie Web Console. Navigate to the console as previously described and look
at the listing in the Workflow Jobs tab and selecting the All Jobs toggle.
8. When the status reads SUCCEEDED, query the SQL database table (you can use the Query Editor in the
Azure Portal as described previously) to view the inserted rows:
Now that you have the workflow running for a single day, you can wrap this workflow with a coordinator that will
effectively schedule the workflow so that it runs daily.
Run the workflow with a coordinator
When you what to schedule this workflow so that it runs daily (or to run for all days in a data range), for example
once a day as new data arrives, you need to leverage a coordinator.
In the case of the scenario, we want the workflow to run daily and so you create a coordinator that has a daily
frequency.
The following is the contents of [Link]:
As you can see, the majority of the coordinator is just passing thru configuration to the workflow instance.
However, there are a few important items to call out.
First, the start and end attributes on the coordinator element itself control the time interval over which the
coordinator runs.
A coordinator is responsible for scheduling actions within the start and end date range and according to the
interval specified by the frequency attribute. Each action scheduled ultimately runs the workflow configured. In the
coordinator definition above, the coordinator is configured to run actions from January 1st, 2017 to January 5th,
2017. The frequency is set to 1 day by the Oozie Expression Language frequency expression ${coord:days(1)}. This
results in the coordinator scheduling an action (and ultimately the workflow) once per day. For date ranges that
are in the past, as in the example, the action will be scheduled to run without delay. The start of the date from
which an action is scheduled to run is referred to as the nominal time. For example, to process the data for January
1st, 2017 the coordinator will schedule action with a nominal time of 2017-01-01T00:00:00 GMT.
Second, within the date range of the workflow, the dataset element defines where to look in HDFS for the data for
a particualr date range, and configures how Oozie determines if the data is available yet for processing.
The path to the data in HDFS is built dynamically according to the expression provided in the uri-template element.
In the above coordinator, a frequency of one day is also used with the dataset. While the start and end dates on the
coordinator element control when the actions are scheduled (and defines their nominal time), the initial-instance
and frequency on the dataset control the calculation of the date that is used in constructing the uri-template. In this
case, we set the initial instance to one day before the start of the coordinator to ensure that we pick up the first
day's (e.g., 1/1/2017) worth of data. The dataset's date calculation rolls forward from the value of initial-instance
(e.g., 12/31/2016) advancing in increments of dataset frequency (e.g., 1 day) until it finds the latest date that does
not pass the nominal time set by the coordinator (e.g., 2017-01-01T00:00:00 GMT for the first action).
Notice also the use of the empty done-flag element- this means that when Oozie checks for the presence of input
data at the appointed time, it determines data is available by presence of a directory or file- in this case it is the
presence of the csv file. If present it assumes the data is ready and can launch a workflow instance to process it,
otherwise it assumes the data is not yet ready and that run of the workflow goes into a waiting state.
Third, the data-in specifies the particular timestamp to use as the nominal time when replacing the values in uri-
template for the associated dataset.
In this case, we set the instance to the expression ${coord:current(0)} which translates to using the nominal time of
the action as originally scheduled by the coordinator. In other words, when the coordinator schedules the action to
run with a nominal time of 01/01/2017, then 01/01/2017 is what is used to replace the YEAR (2017) and MONTH
(01) variables in the URI template. Once the URI template is computed for this instance, Oozie checks if the
expected directory or file is available and schedules the run of the workflow accordingly.
These three points all combine to yield a situation where the coordinator schedules processing of the source data
in a day by day fashion. For example:
1. The coordinator starts with a nominal date of 2017-01-01.
2. Oozie looks for data available in the sourceDataFolder/[Link].
3. When it sees that file, it schedules an instance of the workflow that will process the data for 2017-01-01.
Then it continues processing for 2017-01-02. This evaluation continues up to, but excluding 2017-01-05.
As for workflows, the configuration of a coordinator is also provided in a [Link] file, which has a superset
of the settings used by the workflow:
nameNode=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]
jobTracker=hn0-[CLUSTERNAME].[UNIQUESTRING].[Link]
queueName=default
[Link]=true
appBase=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/oozie
[Link]=${appBase}
sourceDataFolder=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/example/data/flights/
hiveScriptLoadPartition=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/oozie/load_flights_by_day/
[Link]
hiveScriptCreateDailyTable=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/oozie/load_flights_by_d
ay/[Link]
hiveDailyTableNamePrefix=dailyflights
hiveDataFolderPrefix=wasbs://[CONTAINERNAME]@[ACCOUNTNAME].[Link]/example/data/flights/day/
sqlDatabaseConnectionString="jdbc:sqlserver://[SERVERNAME].[Link];user=[USERNAME];password=
[PASSWORD];database=[DATABASENAME]"
sqlDatabaseTableName=dailyflights
hiveDailyTableNamePrefix The prefix that will be used when dynamically creating the
table name of the staging table
hiveDataFolderPrefix The prefix of the path to where all the staging tables will be
stored
ssh sshuser@[CLUSTERNAME]-[Link]
5. Verify the status using the Oozie Web Console, this time selecting the Coordinator Jobs tab, and then the All
jobs toggle.
6. Select the coordinator instance to display the list of scheduled actions, you should see four actions with
nominal times in the range from 1/1/2017 to 1/4/2017, similar to the following:
Each action in this list correlates to an instance of the workflow intended to process one day's worth of data, where
the start of that day is indicated by the nominal time.
Next steps
In this article, we took a deep dive into operationalizing a data pipeline using Oozie.
Read the Apache Oozie Documentation
Streaming and Business Intelligence
8/16/2017 • 27 min to read • Edit Online
As IoT (Internet of Things) devices, such as internet-connected sensors, appliances, business and consumer devices,
continue to gain popularity, so does the need for businesses to act on this data in motion. Whether the device
sending real-time data over the internet is a surgical robot, or one of hundreds of sensors on a race car, it is often
necessary to rapidly collect and make sense of the data it produces.
Streaming data falls in the realm of real-time processing, which can be defined as processing a typically infinite
stream of input data, whose time until results are ready is short - measured in milliseconds or seconds in the
longest of cases. The sample in this article uses Event Hubs to ingest simulated telemetry data from a temperature
sensor. Another common entry point one might use for ingesting this type of data is IoT Hub, which offers bi-
directional communication with billions of devices, and exposes an Event Hubs-compatible endpoint. Apache Kafka
is yet another stream-ingestion broker one could use. We will be using Apache Spark Structured Streaming to
process the real-time telemetry data, and HBase for long-term storage.
Collecting all of this raw data alone does not help business leaders make informed decisions, however. The data
needs to be analyzed to detect anomalies, or other thresholds that trigger business rules. It also needs to be
condensed down to manageable components so it can be visualized and made sense of. This end of the spectrum is
known as Business Intelligence (BI).
The scenario we are using for this exercise, we are monitoring temperature readings from a ficticious Blue Yonders
airport terminal. We have created a [Link] app to generate sample temperature telemetry and insert them into an
Event Hubs instance. You will learn how to process this real-time data using Spark Structured Streaming. Data will
be written to an HBase table as it is being processed, and visualized using OpenTSDB.
To accomplish these tasks, you will perform the following high-level steps:
1. Provision two HDInsight clusters, one with Spark 2.1, and the other with HBase.
2. Provision an Event Hubs instance.
3. Compile and run on your local workstation a sample Event Producer application that generates events to send
to Event Hubs.
4. Use the Spark Shell to define and run a simple Spark Structured Streaming application.
5. Modify and compile a deployable Spark Structured Streaming application that writes processed data to HBase
by sending event data to OpenTSDB through its HTTP API.
6. Configure and use OpenTSDB for BI reporting.
Prerequisites
An Azure subscription. See Get Azure free trial.
IMPORTANT
You do not need an existing HDInsight cluster. The steps in this document create the following resources:
A Spark on HDInsight cluster (four worker nodes)
An HBase on HDInsight cluster (four worker nodes)
[Link]: Used generate sample temperature event data from your local machine.
Maven: Used to build and compile the project.
Git: Used to download the project from GitHub.
An SSH client: Used to connect to the HDInsight clusters. For more information, see Use SSH with HDInsight.
3. On the Create namespace blade, provide a unique name for your Event Hubs namespace.
4. Leave the Pricing tier at Standard.
5. Choose a Subscription and Resource Group as appropriate.
6. For the Location, choose the same Location as you used for your HDInsight cluster.
7. Select Create.
3. In the Create Event Hub blade, enter the name "sensordata" for your Event Hub.
4. Leave the remaining settings at their defaults. Note that your Event Hub will have 2 partitions (as set in
Partition Count).
5. Select Create.
6. On your Event Hubs blade for your namespace, select Event Hubs. Select the sensordata entry.
7. Select Shared access policies from the side menu.
8. In the list of Shared Access Policies, click the + Add link to add the following policies:
POLICY CLAIMS
spark Listen
devices Send
9. Select both policies and copy the value under Primary Key for both, then paste them into a temporary text
file. These values are your Policy Key for each policy. Also, take note that the Policy Names are "devices" and
"spark".
10. Close the Policy blade and select Properties from the side menu.
11. The value under Name is your namespace, take note of this value along with your Policy Keys and Names.
Also, take note that the name of your Event Hub itself is "sensordata".
After the command completes, you have the following directory structure:
hdinsight-streaming-and-business-intelligence/
- SendAirportTempEvents/ <-- sends mock airport temperature sensor data to Event Hub.
- BlueYonder/ <-- Apache Spark Structured Streaming app that processes the event data.
-src/
-main/
-resources/
-[Link]
-scala/com/microsoft/examples
-BlueYonderMain
-HBaseSink
-OpenTSDBSink
NOTE
This document does not go in to full details of the SendAirportTempEvents code included in this sample, but the code is fully
commented. However, we will walk through the important aspects of the BlueYonder Structured Streaming app later on.
npm install
2. Open the [Link] file in a text editor and add the Event Hub information you obtained earlier:
NOTE
This example assumes that you have used sensordata as the name of your Event Hub, and devices as the name of
the policy that has a Send claim.
node [Link]
You will see several lines of output that contain the data sent to Event Hub:
...
...
{"TimeStamp":"2017-08-03T04:29:50Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:30:00Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:00Z","DeviceId":"2","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:00Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:30:10Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:10Z","DeviceId":"2","Temperature":65.05555555555556}
{"TimeStamp":"2017-08-03T04:30:10Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:30:20Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:20Z","DeviceId":"2","Temperature":65.11111111111111}
{"TimeStamp":"2017-08-03T04:30:20Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:30:30Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:30Z","DeviceId":"2","Temperature":65.16666666666667}
{"TimeStamp":"2017-08-03T04:30:30Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:30:40Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:40Z","DeviceId":"2","Temperature":65.22222222222223}
{"TimeStamp":"2017-08-03T04:30:40Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:30:50Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:30:50Z","DeviceId":"2","Temperature":65.27777777777779}
{"TimeStamp":"2017-08-03T04:30:50Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:31:00Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:31:00Z","DeviceId":"2","Temperature":65.33333333333334}
{"TimeStamp":"2017-08-03T04:31:00Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:31:10Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:31:10Z","DeviceId":"2","Temperature":65.3888888888889}
{"TimeStamp":"2017-08-03T04:31:10Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:31:20Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:31:20Z","DeviceId":"2","Temperature":65.44444444444446}
{"TimeStamp":"2017-08-03T04:31:20Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:31:30Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:31:30Z","DeviceId":"2","Temperature":65.50000000000001}
{"TimeStamp":"2017-08-03T04:31:30Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:31:40Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:31:40Z","DeviceId":"2","Temperature":65.55555555555557}
{"TimeStamp":"2017-08-03T04:31:40Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:31:50Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:31:50Z","DeviceId":"2","Temperature":65.61111111111113}
{"TimeStamp":"2017-08-03T04:31:50Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:32:00Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:32:00Z","DeviceId":"2","Temperature":65.66666666666669}
{"TimeStamp":"2017-08-03T04:32:00Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:32:10Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:32:10Z","DeviceId":"2","Temperature":65.72222222222224}
{"TimeStamp":"2017-08-03T04:32:10Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:32:20Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:32:20Z","DeviceId":"2","Temperature":65.7777777777778}
{"TimeStamp":"2017-08-03T04:32:20Z","DeviceId":"3","Temperature":62}
{"TimeStamp":"2017-08-03T04:32:30Z","DeviceId":"1","Temperature":65}
{"TimeStamp":"2017-08-03T04:32:30Z","DeviceId":"2","Temperature":65.83333333333336}
...
...
4. Leave the event generator running while you continue the following steps.
Sample data is loaded one at a time (8,640 * # of devices total) to simulate a data stream, for a period representing
24 hours of temperature data from an airport terminal. Rooms start at an ambient temperature (such as 65 F), and
depending on the room, flights occur every 90 minutes between 5:00am and 12:00am. As people arrive 30 minutes
prior to a flight, the temperature starts to rise (5 degrees or more, depending on number of people), due to warmth
from bodies. 30 minutes after the flight arrives, people are boarded, and the temperature starts to drop towards
ambient temperature.
If you wish to batch load the data to quickly insert the same amount of data 500 events at a time, execute the app
using the -batch argument ( node [Link] -batch ).
Run Spark Shell on your HDInsight cluster
In this task, you will SSH into the head node of your HDInsight cluster, launch the Spark Shell and run a Spark
Streaming application that will retrieve and process the events from Event Hubs. This step is to demonstrate
viewing the generated data stream using Structured Streaming. You will deploy the full streaming app later on.
By this point your HDInsight cluster should be ready. If not, you will need to wait until it finishes provisioning. Once
it is ready, proceed with the following steps.
1. Navigate to your deployed HDInsight Spark cluster in the Azure Portal.
2. Select Secure Shell.
3. Follow the instructions displayed for connecting to your cluster via SSH from your local environment. In
general, this will mean running SSH as follows:
ssh sshuser@<yourclustername>-[Link]
4. Complete the login by providing the password you supplied when provisioning the cluster.
5. The application you will build requires the Spark Streaming Event Hubs package. To run the Spark Shell so
that it automatically retrieves this depedency from Maven Central, be sure the supply the packages switch
with the Maven coordinates as follows:
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version [Link].6.1.3-4
/_/
Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_131)
Type in expressions to have them evaluated.
Type :help for more information.
scala>
7. Copy the following code snippet into a text editor and modify it so it has the Policy Key and Namespace set
as appropriate for your Event Hub.
8. Paste the modified snippet into the waiting scala> prompt and press return. You should see output similar
to:
9. Next, you will begin to author a Spark Structured Streaming query by specifying the source. Paste the
following into Spark Shell and press return.
11. As you can see in the previous output, the body is in binary format. To view our device data, we need to
parse its contents. To do this, paste the following into Spark Shell and press return.
13. Next, author the query so that it writes its output to the Console. Do this by pasting the following into Spark
Shell and pressing return.
14. You should see some batches start with output similar to the following
-------------------------------------------
Batch: 0
-------------------------------------------
[Stage 0:> (0 + 2) / 2]
15. This will be followed by the ouput results of the processing of each microbatch of events.
-------------------------------------------
Batch: 0
-------------------------------------------
17/08/03 14:14:51 WARN TaskSetManager: Stage 1 contains a task of very large size (274 KB). The maximum
recommended task size is 100 KB.
+-----------------+--------------------+--------+
| Temperature| TimeStamp|DeviceId|
+-----------------+--------------------+--------+
| 65.0277777777776|2017-08-04T21:18:10Z| 3|
| 66.944444444444|2017-08-04T21:18:20Z| 1|
|71.11111111111128|2017-08-04T21:18:20Z| 2|
|65.05555555555537|2017-08-04T21:18:20Z| 3|
|66.91666666666623|2017-08-04T21:18:30Z| 1|
|71.16666666666684|2017-08-04T21:18:30Z| 2|
|65.08333333333314|2017-08-04T21:18:30Z| 3|
|66.88888888888846|2017-08-04T21:18:40Z| 1|
| 71.2222222222224|2017-08-04T21:18:40Z| 2|
|65.11111111111092|2017-08-04T21:18:40Z| 3|
|66.86111111111069|2017-08-04T21:18:50Z| 1|
|71.27777777777796|2017-08-04T21:18:50Z| 2|
|65.13888888888869|2017-08-04T21:18:50Z| 3|
|66.83333333333292|2017-08-04T21:19:00Z| 1|
|71.33333333333351|2017-08-04T21:19:00Z| 2|
|65.16666666666646|2017-08-04T21:19:00Z| 3|
|66.80555555555515|2017-08-04T21:19:10Z| 1|
|71.38888888888907|2017-08-04T21:19:10Z| 2|
|65.19444444444423|2017-08-04T21:19:10Z| 3|
|66.77777777777737|2017-08-04T21:19:20Z| 1|
+-----------------+--------------------+--------+
only showing top 20 rows
16. As new events arrive from the Event Producer, they will be processed by this Structured Streaming query.
17. End this process by entering Ctrl+C (Windows) / Cmd+C (Mac), since we will be deploying our processor
app.
Configure and build the Spark app
1. Open the BlueYonder project in your favorite scala IDE. In our case, we'll open it in IntelliJ Community
edition.
2. Open the [Link] file and add the Event Hub information you obtained earlier:
Then click the Build action underneath the BlueYonder_DefaultArtifact artifact within the Build Artifact menu.
Upload and execute the app
From a bash shell prompt for SCP, or command prompt for PSCP, upload the compiled JAR file to the local storage
of your HDInsight cluster head node. As done earlier, replace USERNAME with the SSH user you provided when
creating the cluster, and SPARKCLUSTERNAME with the name you provided earlier for your Spark cluster. When
prompted, enter the password for the SSH user. Replace the
/path/to/BlueYonder/out/artifacts/BlueYonder_DefaultArtifact/default_artifact.jar with the path to this file in the
BlueYonder project.
scp /path/to/BlueYonder/out/artifacts/BlueYonder_DefaultArtifact/default_artifact.jar
USERNAME@[Link]:default_artifact.jar
pscp "c:\path\to\BlueYonder\out\artifacts\BlueYonder_DefaultArtifact\default_artifact.jar"
USERNAME@[Link]:default_artifact.jar
Now, SSH into your Spark cluster and use the HDFS command to copy the file from your head node local storage
to Azure Storage:
It is preferable to store the application in Azure Storage so that it is still accessible across your cluster's lifecycle.
Meaning, if you were to delete and recreate your cluster, your app will still be available to run.
Next, execute the following command to submit and run the uploaded app, replacing SPARKCLUSTERNAME with
the Spark cluster name you specified earlier, and STORAGENAME with the name of your cluster's default storage
account:
Note that when submitting spark jobs that use Azure Storage as the JAR's source, you need to specify the
--master URL as either yarn or yarn-cluster . Also notice that we're using the --packages switch as maven
coordinates to our app's dependencies.
You should see output that is constantly scrolling, similar to the following snapshot:
...
...
17/08/06 18:36:19 INFO Client: Application report for application_1502027043716_0004 (state: ACCEPTED)
17/08/06 18:36:19 INFO Client:
client token: N/A
diagnostics: AM container is launched, waiting for AM container to Register with RM
ApplicationMaster host: N/A
ApplicationMaster RPC port: -1
queue: default
start time: 1502044578458
final status: UNDEFINED
tracking URL: [Link]
[Link]/proxy/application_1502027043716_0004/
user: sshuser
17/08/06 18:36:20 INFO Client: Application report for application_1502027043716_0004 (state: ACCEPTED)
17/08/06 18:36:21 INFO Client: Application report for application_1502027043716_0004 (state: ACCEPTED)
17/08/06 18:36:22 INFO Client: Application report for application_1502027043716_0004 (state: ACCEPTED)
17/08/06 18:36:23 INFO Client: Application report for application_1502027043716_0004 (state: ACCEPTED)
...
...
Let this run in the background. At this time, the data generator should still be running as well, sending simulated
streaming data to your event hub. If it has finished running, execute it once more from the command prompt with
this command:
node [Link]
The inputStream DataFrame represents an unbounded table containing the Event Hubs data, whose source
definition was passed to the options property. We capitalize on the fact that most common operations on the
DataFrame are supported for streaming. One of the columns of our unbounded table is "body", which contains the
binary representation of the JSON-formatted data we sent to Event Hubs from our simulated sensors. To make it
easier to extract that data, we cast the value to String format, then parse it using get_json_object to retrieve our
telemetry properties. It is important to note that at this point, we're just setting up the data transformation. Data is
not being received yet, because we have not started it.
At this point, we've set up the data transformations on our streaming data. What is left is to actually start receiving
the data and processing it, sending it to our presentation/BI layer.
There are a few built-in output sinks you can choose from, such as:
1. File sink: Stores the output to a directory in various file formats.
2. Console sink: Used for debugging purposes, as we did within the spark-shell session earlier.
3. Memory sink: The output is stored in memory as an in-memory table, and should be used for debugging
purposes only.
4. Foreach sink: Allows you to run arbitrary computation on the records in the output. This is what we are using
for our custom sinks.
The project contains two custom Foreach sinks: HBaseSink for writing directly to an HBase table, and
OpenTSDBSink that sends data to OpenTSDB via its HTTP API.
If you wish to use the Foreach sink by implementing the ForeachWriter interface, the writer must be
serializable. It is not enough to simply declare the writer in-line to the writeStream object, or as a separate class
within your executing class. You must create a separate file for it, as we have done with the HBaseSink and
OpenTSDBSink classes. Furthermore, your writer must do all of the initializataion within the overridden open
method (such as opening connections, starting a transaction, etc.).
When we start receiving data, we first instantiate a new OpenTSDBSink class, passing in the OpenTSDB HTTP API
URL and credentials, then pass that in to the foreach sink.
The start() method starts the streaming computation in the background, and .awaitTermination() prevents the
process from exiting while the query is active.
When you look at the OpenTSDBSink class, you will see that it extends the ForeachWriter interface, news up a
DefaultHttpClient and HttpPost object, sets up the telemetry payload (including converting the date/time entry to
the required timestamp/epoch format), and POSTs the request to our hosted OpenTSDB service on the HBase
cluster.
class OpenTSDBSink(url:String, usernamePassword:String) extends ForeachWriter[[Link]] {
var encoding:String = _
var httpClient:DefaultHttpClient = _
var post:HttpPost = _
true
}
This OpenTSDBSink class can easily be customized to send this streaming data to the Microsoft Power BI REST
API, or any other BI, reporting, or visualization platform that exposes an HTTP endpoint.
The [Link] file also contains commented code that demonstrates how to use the file sink to save
Parquet-formatted files to the cluster's default Azure Storage account (as indicated by the wasb: paths). This opens
up additional opportunities for working with the streaming data.
If you receive the following error when trying to display data on the OpenTSDB UI:
'gnuplot': No such file or directory , you need to execute the following command from each node of your
cluster (head nodes, worker nodes, and edge node): sudo apt-get install gnuplot-x11
OpenTSDB in Ambari
When you provisioned the HBase cluster with the ARM template, a few Script Actions were executed that integrated
OpenTSDB with Ambari. Log into the Ambari web interface by going to
HTTPS://[Link], where CLUSTERNAME is the name of your HBase cluster. You will
need to input your admin username and password you specified at cluster creation.
When the dashboard loads, you will see OpenTSDB in the list of services. Click on the menu item to view a
summary. Here you can view which nodes have OpenTSDB services running, and their status.
Click on the Configs tab to view basic and advanced configuration options.
The advanced tab provides an easy interface for making changes to the OpenTSDB configs, compared to modifying
the individual configuration files on each node.
You can view the OpenTSDB interface by selecting OpenTSDB View from the list of available Ambari views.
When you select the view, you will be prompted to enter the same admin credentials you used to connect to
Ambari.
Displaying telemetry data in OpenTSDB
The top of the OpenTSDB UI page contains a form through which you can specify the time series date range, metric,
tags, chart positioning, etc.
Notice that OpenTSDB automatically color-coded each of the device data series. With this visualization, you can
quickly infer the differing flight schedules, ambient room temperatures, and general sense of crowd sizes in each of
the rooms in which each sensor is located.
One thing we would like to know is what the overall average temperature of all devices looks like with respect to
the current graph. To show this new data point, click the + symbol text to the temperature tab in the form you just
modified. This allows us to add a new metric.
Now click and drag with your mouse to zoom in on a smaller time slice of data.
The page will be refreshed to display just the zoomed in time range. Notice that the From and To form values have
been updated accordingly.
Another thing to note is that each time you make a change to the chart values or displayed range, the page
refreshes with a custom URL. This allows you to bookmark or save the displayed chart to share or view later.
The tabs at the top of the page allow you to view statistics, logs, and version information. When you click on the
Stats tab, you will see interesting information about the number of data input requests received from the Spark
app, how many failed or caused exceptions, if any, the number of graph requests, latency, and other interesting bits
of information.
The Logs tab displays entries for every action in the chart's configuration, as well as other items of interest, such as
incoming put requests to the OpenTSDB HTTP API. In the below screenshot, you can see put requests invoked by
our running Spark app (highighted).
Learn more about using the OpenTSDB GUI.
NOTE
If you choose to go this route, you will need to first provision a virtual network, then add both the Spark and HBase clusters
to it so that the structured streaming app running on the Spark cluster can directly communicate with the HBase cluster
using the HBase Java API.
To write to HBase from the Spark cluster, you must provide the Spark app with the configuration details of your
HBase cluster. This example uses the [Link] file from the HBase cluster.
Download the hbase -[Link]
If you wish to write your event data directly to HBase, you will need to copy the [Link] file to the Spark
application's resource directory.
From a bash shell prompt, use SCP to download the [Link] file from the cluster. Alternately, if using
Windows, you can use PSCP from the command prompt. In the following example, replace USERNAME with the
SSH user you provided when creating the cluster, and BASENAME with the base name you provided earlier. When
prompted, enter the password for the SSH user. Replace the
/path/to/BlueYonder/src/main/resources/[Link] with the path to this file in the BlueYonder project.
scp USERNAME@[Link]:/etc/hbase/conf/[Link]
/path/to/BlueYonder/src/main/resources/[Link]
This command downloads the [Link] to the path specified.
Example using PSCP:
pscp USERNAME@[Link]:/etc/hbase/conf/[Link]
c:\path\to\BlueYonder\src\main\resources\[Link]
ssh USERNAME@[Link]
In this command, replace USERNAME with the SSH user name you provided when creating the cluster, and
BASENAME with the base name you provided. When prompted, enter the password for the SSH user.
2. From the SSH session, start the HBase shell.
hbase shell
4. Verify that the table has been created by using the following command:
scan 'SensorData'
This returns information similar to the following example, indicating that there are 0 rows in the table.
[Link]("append").foreach(writer).start().awaitTermination()
Next steps
Learn more about Structured Streaming
Learn more about connecting to and using Ambari to manage your clusters
Troubleshooting a Failed or Slow HDInsight Cluster
8/16/2017 • 17 min to read • Edit Online
This article walks you through the process of troubleshooting an HDInsight cluster that is either in the failed state,
or running slowly. A 'Failed Cluster' is defined as one that has terminated with an error code. If your jobs are taking
longer to run than expected, or you are seeing slow response times in general, you may be experiencing failures
upstream from your cluster, such as the services on which the cluster runs. However, the most common cause of
these slowdowns have to do with scale. When you provision a new HDInsight cluster, you have many options for
selecting virtual machine sizes to preserve your metadata when you delete and recreate your cluster.
There are a set of general steps to take when diagnosing a failed or slow cluster. They involve getting information
about all aspects of the environment, including, but not limited to, all associated Azure Services, cluster
configuration, job execution information, and reproducability of error state. The most common steps taken in this
process are listed below.
General troubleshooting steps to diagnose an HDInsight cluster
Step 1: Gather data about the issue
Step 2: Validate the HDInsight cluster environment
Step 3: View your cluster's health
Step 4: Review the environment stack and versions
Step 5: Examine the cluster log files
Step 6: Check configuration settings
Step 7: Reproduce the failure on a different Cluster
Or, you can use PowerShell to view this type of information. See Manage Hadoop clusters in HDInsight by using
Azure PowerShell for details.
Ambari will also display an alert showing the hosts on which the WebHCat service is down. You can attempt to
bring the service back up by restarting the service on the host for which the alert was raised:
If WebHCat server still does not come up, then clicking through operations will show the failures. For more detailed
information, refer to the stderr and stdout files referenced on the node.
WebHCat times out
The HDInsight Gateway times out responses which take longer than 2 minutes, resulting in 502 BadGateway .
WebHCat queries YARN services for job status, and if they take longer than two minutes, the request might
timeout.
When this happens, review the following logs for further investigation:
/var/log/webhcat
When WebHCat is under load, meaning there are more than 10 open sockets at any given time, it will take longer
to establish new socket connections, which might result in a time out. A quick way to validate is to check the
connection status using the below command on the current active headnode:
30111 is the port WebHCat listens to, and the above command lists network connections to and from WebHCat.
This command will show you the current open sockets on port 30111. The number of open sockets should be less
than 10.
Sometimes when debugging using the above command, you will receive no result. That doesn't mean that nothing
is listening on port 30111. Because the command netstat only prints out open sockets. No result simply means
for that given time, there are no open sockets. To check if Templeton is up and listening on port 30111, use:
Y A RN l evel t i m eo u t
Because Templeton is calling YARN to run jobs, the communication between Templeton and YARN is another
source that can cause a timeout.
At the YARN level, there are two types of timeouts:
1. Submitting a YARN job might take long enough to cause a timeout.
If you open the [Link] file mentioned earlier, and search for "queued job", you may see multiple
entries where the execution time is excessively long (>2000 ms), with each entry showing even longer wait
times.
The reason the time for the queued jobs continues to increase, is the rate at which new jobs get submitted is
much higher than the rate at which the old jobs are completed. Because of this, once the Yarn Memory is
100% used, there is no way the joblauncher queue can borrow capacity from the default queue . Thus, no
more new jobs can be accepted (meaning being added to the joblauncher queue). This would cause the
waiting time to become longer and longer, leading up to a timeout error, usually followed by many others.
As an illustration, the following shows the joblauncher queue at 714.4% over used. This is okay as long as
there is still free capacity in the default queue, meaning new jobs can still be added by borrowing capacity
from the default queue. But, if the YARN memory is at 100% capacity, meaning the cluster is fully used, new
jobs must wait, eventually causing timeouts as described above.
There are two ways to resolve this issue: one is to reduce the speed of new jobs being submitted, the second
one is to increase the consumption speed of old jobs in joblauncher queue, which is basically increasing the
processing power of your cluster by scaling up.
2. YARN processing might take a long time, which makes another source of timeouts.
List all jobs: This is a very expensive call. This call enumerates the applications from YARN
ResourceManager and for each completed application, gets the status from JobHistoryServer. In cases
of higher numbers of jobs, this call might timeout, resulting in a 502.
List jobs older than 7 days: The HDInsight YARN JobHistoryServer is configured (
[Link]-age-ms ) to retain completed job information for 7 days. Trying to
enumerating purged jobs results in a timeout, causing a 502.
Your process will involve the following:
Figure out the UTC time range to troubleshoot
Select the [Link] file, based on the time range
Look for WARN/ERROR messages during that period of time
Other failures
1. HTTP Status code 500
In most cases where WebHCat returns 500, the error message contains details on the failure. Otherwise,
looking through the [Link] for WARN/ERROR messages will reveal the issue.
2. Job failures
There may be cases where interactions with WebHCat are successful, but the jobs are failing.
Templeton collects the job console output as stderr in "statusdir" which will most often be useful for
troubleshooting. stderr contains the YARN application id of the actual query, which can be used for
troubleshooting.
As explained earlier, HDInsight clusters consist of several nodes, most of which are tasked to run submitted jobs.
Jobs will run concurrently, but log files can only display results linearly. HDInsight executes new tasks, terminating
others that fail to complete first. This activity is logged to stderr and syslog log files as they occur.
Start by checking the Script Action logs for errors or unexpected configuration changes during your cluster's
provisioning process. The next set of logs to check are the step logs to identify Hadoop jobs launched as part of a
step with errors.
The following sections cover each of the log files you can use to troubleshoot cluster errors and slowdowns:
Check the Script Action logs
HDInsight Script Actions run scripts on the cluster manually or when specified. For example, they can be used to
install additional software on the cluster or to alter configuration settings from the default values. Checking these
logs may provide insight into errors that occurred during set up of the cluster as well as configuration settings
changes that could affect availability. You can view the status of a script action by clicking on the 'ops' button on
your Ambari UI or by accessing them from the default storage account.
The storage logs are available at
\STORAGE_ACCOUNT_NAME\DEFAULT_CONTAINER_NAME\custom-scriptaction-logs\CLUSTER_NAME\DATE .
View logs in HDInsight via Quick Links in Ambari
The HDInsight Ambari UI includes a number of 'Quick Links' sections. To access the log links for a particular service
in your HDInsight cluster, open the Ambari UI for your clustuer, then click on the service link from the list at left,
next click on the 'Quick Links' drop down and then on the HDInsight node of interest and then on the link for its
associated log.
An example, for HDFS logs, is shown below:
/app-logs/<user>/logs/<applicationId>
The aggregated logs are not directly readable, as they are written in a TFile, binary format indexed by container. Use
the YARN ResourceManager logs or CLI tools to view these logs as plain text for applications or containers of
interest.
YA RN CLI tools
To use the YARN CLI tools, you must first connect to the HDInsight cluster using SSH. Specify the , , , and
information when running these commands. You can view these logs as plain text by running one of the following
commands:
yarn logs -applicationId <applicationId> -appOwner <user-who-started-the-application>
yarn logs -applicationId <applicationId> -appOwner <user-who-started-the-application> -containerId
<containerId> -nodeAddress <worker-node-address>
Y A R N R e so u r c e M a n a g e r U I
The YARN ResourceManager UI runs on the cluster headnode. It is accessed through the Ambari web UI. Use the
following steps to view the YARN logs: In your web browser, navigate to [Link]
Replace CLUSTERNAME with the name of your HDInsight cluster. From the list of services on the left, select YARN.
Yarn service selected From the Quick Links dropdown, select one of the cluster head nodes and then select
ResourceManager Log. Yarn quick links You are presented with a list of links to YARN logs.
Other logs
Heap dumps contain a snapshot of the application's memory, including the values of variables at the time the
dump was created. So they are useful for diagnosing problems that occur at run-time. See the link at the bottom of
this article for the process to enable heap dumps for your HDInsight cluster.
Conclusion
There are a number of considerations you need to pay attention to make sure your HDInsight cluster is operational.
You should focus on using the best HDInsight cluster configuration for your particular workload. Along with that,
you'll need to monitor the execution of long-running and/or high resource consuming job executions to make sure
that they don't fail and possibly bring down your entire cluster. It's also critically important to manage your cluster
configuration over time, so that you can revert to working state should the need arise.
See also
Manage HDInsight clusters by using the Ambari Web UI
Analyze HDInsight Logs
Access YARN application log on Linux-based HDInsight
Enable heap dumps for Hadoop services on Linux-based HDInsight
Known Issues for Apache Spark cluster on HDInsight
Analyze HDInsight logs
8/16/2017 • 12 min to read • Edit Online
Each Hadoop cluster in Azure HDInsight has an Azure storage account used as the default file system. The storage
account is referred as the default Storage account. Cluster uses the Azure Table storage and the Blob storage on
the default Storage account to store its logs. To find out the default storage account for your cluster, see Manage
Hadoop clusters in HDInsight. The logs retain in the Storage account even after the cluster is deleted.
3. Enter the storage account name. This can be either the short name or the FQDN.
4. Enter the storage account key. You shall see a list of tables:
5. Right-click the hadoopservicelog table in the Navigator pane and select Edit. You shall see 4 columns.
Optionally, delete the Partition Key, Row Key, and Timestamp columns by selecting them, then clicking
Remove Columns from the options in the ribbon.
6. Click the expand icon on the Content column to choose the columns you want to import into the Excel
spreadsheet. For this demonstration, I chose TraceLevel, and ComponentName: It can give me some basic
information on which components had issues.
7. Click OK to import the data.
8. Select the TraceLevel, Role, and ComponentName columns, and then click Group By control in the ribbon.
9. Click OK in the Group By dialog box
10. Click** Apply & Close**.
You can now use Excel to filter and sort as necessary. Obviously, you may want to include other columns (e.g.
Message) in order to drill down into issues when they occur, but selecting and grouping the columns described
above provides a decent picture of what is happening with Hadoop services. The same idea can be applied to the
setuplog and hadoopinstalllog tables.
Use Visual Studio
To use Visual Studio
1. Open Visual Studio.
2. From the View menu, click Cloud Explorer. Or simply click CTRL+\, CTRL+X.
3. From Cloud Explorer, select Resource Types. The other available option is Resource Groups.
4. Expand Storage Accounts, the default storage account for your cluster, and then Tables.
5. Double-click hadoopservicelog.
6. Add a filter. For example:
TraceLevel eq 'ERROR'
For more information about constructing filters, see Construct Filter Strings for the Table Designer.
Get node status. From the left pane, expand Cluster, and click Nodes. This lists all the nodes in the cluster,
HTTP address of each node, resources allocated to each node, etc.
Monitor job status. From the left pane, expand Cluster, and then click Applications to list all the jobs in the
cluster. If you want to look at jobs in a specific state (such as new, submitted, running, etc.), click the appropriate
link under Applications. You can further click the job name to find out more about the job such including the
output, logs, etc.
Access the HBase UI
From the Azure portal, click an HDInsight HBase cluster name to open the cluster blade. From the cluster blade,
click Dashboard. When prompted, enter the cluster administrator credentials. In Ambari, select HBase from the list
of services. Select Quick links on the top of the page, point to the active Zookeeper node link, and then click
HBase Master UI.
Next steps
Use Ambari Views to debug Tez Jobs on HDInsight
Enable heap dumps for Hadoop services on Linux-based HDInsight
Manage HDInsight clusters by using the Ambari Web UI
Use Ambari Views to debug Tez Jobs on HDInsight
8/16/2017 • 3 min to read • Edit Online
The Ambari Web UI for HDInsight contains a Tez view that can be used to understand and debug jobs that use Tez.
The Tez view allows you to visualize the job as a graph of connected items, drill into each item, and retrieve
statistics and logging information.
IMPORTANT
The steps in this document require an HDInsight cluster that uses Linux. Linux is the only operating system used on
HDInsight version 3.4 or greater. For more information, see HDInsight component versioning.
Prerequisites
A Linux-based HDInsight cluster. For steps on creating a cluster, see Get started using Linux-based HDInsight.
A modern web browser that supports HTML5.
Understanding Tez
Tez is an extensible framework for data processing in Hadoop that provides greater speeds than traditional
MapReduce processing. For Linux-based HDInsight clusters, it is the default engine for Hive.
Tez creates a Directed Acyclic Graph (DAG) that describes the order of actions required by jobs. Individual actions
are called vertices, and execute a piece of the overall job. The actual execution of the work described by a vertex is
called a task, and may be distributed across multiple nodes in the cluster.
Understanding the Tez view
The Tez view provides both historical information and information on processes that are running. This information
shows how a job is distributed across clusters. It also displays counters used by tasks and vertices, and error
information related to the job. It may offer useful information in the following scenarios:
Monitoring long-running processes, viewing the progress of map and reduce tasks.
Analyzing historical data for successful or failed processes to learn how processing could be improved or why it
failed.
Generate a DAG
The Tez view only contains data if a job that uses the Tez engine is currently running, or has been ran previously.
Simple Hive queries can be resolved without using Tez. More complex queries that do filtering, grouping, ordering,
joins, etc. use the Tez engine.
Use the following steps to run a Hive query that uses Tez:
1. In a web browser, navigate to [Link] where CLUSTERNAME is the
name of your HDInsight cluster.
2. From the menu at the top of the page, select the Views icon. This icon looks like a series of squares. In the
dropdown that appears, select Hive view.
3. When the Hive view loads, paste the following query into the Query Editor, and then click execute.
select market, state, country from hivesampletable where deviceplatform='Android' group by market,
country, state;
Once the job has completed, you should see the output displayed in the Query Process Results section. The
results should be similar to the following text:
4. Select the Log tab. You see information similar to the following text:
Save the App id value, as this value is used in the next section.
2. When the Tez view loads, you see a list of hive queries that are currently running, or have been ran on the
cluster.
3. If you have only one entry, it is for the query that you ran in the previous section. If you have multiple
entries, you can search by using the fields at the top of the page.
4. Select the Query ID for a Hive query. Information about the query is displayed.
5. The tabs on this page allow you to view the following information:
Query Details: Details about the Hive query.
Timeline: Information about how long each stage of processing took.
Configurations: The configuration used for this query.
From Query Details you can use the links to find information about the Application or the DAG for
this query.
The Application link displays information about the YARN application for this query. From here you
can access the YARN application logs.
The DAG link displays information about the directed acyclic graph for this query. From here you can
view a graphical representation of the DAG. You can also find information on the vertices within the DAG.
Next Steps
Now that you have learned how to use the Tez view, learn more about Using Hive on HDInsight.
For more detailed technical information on Tez, see the Tez page at Hortonworks.
For more information on using Ambari with HDInsight, see Manage HDInsight clusters using the Ambari Web UI
Common Problems FAQ
8/15/2017 • 4 min to read • Edit Online
This guide serves to address common frequently asked questions (FAQs) pertaining to common issues when using
and provisioning HDInsight clusters.
Capacity planning
There are several aspects about your chosen cluster type you must consider when planning your cluster's capacity.
Ultimately, you need to consider cost optimization, as well as the performance and usability of your cluster. Below
are some common pitfalls when it comes to capacity planning.
How do I ensure my cluster can handle the rate of growth of my data set? We don't know what the upper limit
will be.
HDInsight separates compute from data storage by using either Azure Blob Storage or Azure Data Lake Store. This
provides many benefits, including scaling out less expensive storage separate from compute. When you provision a
new HDInsight cluster, you have the choice between Azure Storage and Azure Data Lake Store as your default data
container. Azure Storage has certain capacity limits that you must consider, whereas Data Lake Store is virtually
unlimited. However, since your cluster's default storage must be located in the same location as your cluster, you
are limited by locations in which you can provision your cluster when using Data Lake Store. Data Lake Store is
currently only available in three locations globally (Central US, East US 2 and North Europe).
Alternately, it is possible to use a combination of different storage accounts with an HDInsight cluster. You might
want to use more than one storage account in the following circumstances:
When the amount of data is likely to exceed the storage capacity of a single blob storage container.
When the rate of access to the blob container might exceed the threshold where throttling will occur.
When you want to make data you have already uploaded to a blob container available to the cluster.
When you want to isolate different parts of the storage for reasons of security, or to simplify administration.
As a general rule, for a 48 node cluster, it is recommended that you have 4-8 storage accounts. This is not due to
storage space requirements, per se, but due to the fact that each storage account provides additional networking
bandwidth that opens up the pipe as wide as possible for the compute nodes to finish their jobs faster. When you
use multiple storage accounts, make the naming convention of the storage account as random as possible, with no
prefix. This is to reduce the chance of hitting storage bottlenecks or common mode failures in storage across all
accounts at the same time. This type of storage partitioning in Azure Storage meant to avoid storage throttling.
Lastly, make sure to only have one container per storage account. This yields better performance.
We've selected large VMs and enough nodes to support our batch processing needs, but cost of running the
cluster is much higher than we'd like. How do we minimize our cost while meeting our compute needs?
HDInsight gives you the flexibility to scale your cluster at will by adjusting the number of worker nodes at any time.
A common practice is to scale out your cluster to meet peak load demands, then scale it back down when those
extra nodes are no longer needed.
Another option, particularly if there are specific times during the day/week/month that you need your cluster up
and running, is to create on-demand clusters using Azure Data Factory. Since you are charged for your cluster for
its lifetime, this is one effective way in which you can manage its lifecycle, netting significant cost savings. Since
your data is stored on low-cost storage, independent of your cluster, then you don't need to worry about losing
valuable data when you delete your cluster. An alternative to using Data Factory is to create PowerShell scripts to
provision and delete your cluster, then schedule running those scripts with Azure Automation.
One thing to look out for when deleting and re-creating your clusters, is that the Hive metastore that is created by
default with a cluster is transient. When the cluster is deleted, the metastore gets deleted as well. Use an external
database like Azure Database or Oozie to persist the metastore if your cluster lifecycle management process is to
run it on-demand, deleting it when not needed.
My code works fine when running locally, but tends to fail when deploying to a multi-node cluster. How do I
isolate the problem to determine if the issue is with my multi-node cluster or something else?
Sometimes errors can occur due to the parallel execution of multiple map and reduce components on a multi-node
cluster. Consider emulating distributed testing by running multiple jobs on a single node cluster at the same time
to detect errors, then expand this approach to run multiple jobs concurrently on clusters containing more than one
node in order to help isolate the issue.
You can create a single-node HDInsight cluster in Azure by specifying the advanced option when creating the
cluster. Alternatively, you can install a single-node development environment on your local computer and execute
the solution there. A single-node local development environment for Hadoop-based solutions that is useful for
initial development, proof of concept, and testing is available from Hortonworks. For more details, see Hortonworks
Sandbox.
By using a single-node local cluster you can rerun failed jobs and adjust the input data, or use smaller datasets, to
help you isolate the problem. How you go about rerunning jobs depends on the type of application and on which
platform it is running.
Next steps
Check this FAQ periodically, as we add additional questions and answers to common problems.