Hello World – Getting Started with HDP

An introduction to Hive and Pig


In this tutorial we will be analyzing geolocation and truck data. We will import this data into HDFS and build derived tables in Hive. Then we will process the data using Pig and Hive. The processed data is then imported into Microsoft Excel where it can be visualized.


  • Hortonworks Sandbox 2.3 (installed and running)

Goals of the Tutorial

The goal of this tutorial is that you get familiar with the basics of following:

  • Hadoop and HDP
  • Ambari File User Views and HDFS
  • Ambari Hive User Views and Apache Hive
  • Ambari Pig User Views and Apache Pig
  • Data Visualization with Excel

Concepts: Hadoop & HDP

In this section we will learn about Apache Hadoop and what makes it scale to large data sets. We will also talk about various components of Hadoop ecosystem that make Apache Hadoop enterprise ready in form of Hortonworks Data Platform(HDP) distribution. The module discusses Apache Hadoop, its capabilities as a data platform and how the core of Hadoop and its surrounding ecosystem solution vendors provides the enterprise requirements to integrate alongside the Data Warehouse and other enterprise data systems as part of a modern data architecture, and as a step on the journey toward delivering an enterprise ‘Data Lake’

Apache Hadoop:

Apache Hadoop® is an open source framework for distributed storage and processing of large sets of data on commodity hardware. Hadoop enables businesses to quickly gain insight from massive amounts of structured and unstructured data. Numerous Apache Software Foundation projects make up the services required by an enterprise to deploy, integrate and work with Hadoop.

The base Apache Hadoop framework is composed of the following modules:

  • Hadoop Common Libraries and utilities needed by other Hadoop modules.
  • Hadoop Distributed File System (HDFS), a distributed file-system that stores data on commodity machines, providing very high aggregate bandwidth across the cluster.
  • Hadoop YARN, a resource-management platform responsible for managing computing resources in clusters and using them for scheduling of users’ applications.
  • Hadoop MapReduce, a programming model for large scale data processing.

Each project has been developed to deliver an explicit function and each has its own community of developers and individual release cycles.

Hortonworks Data Platform (HDP)

Hortonworks Data Platform is a packaged software hadoop distribution that aim to ease deployment and management of Hadoop clusters compared with simply downloading the various Apache code bases and trying to run them together a system. Architected, developed, and built completely in the open, Hortonworks Data Platform (HDP) provides an enterprise ready data platform that enables organizations to adopt a Modern Data Architecture.

With YARN as its architectural center it provides a data platform for multi-workload data processing across an array of processing methods – from batch through interactive to real-time, supported by key capabilities required of an enterprise data platform — spanning Governance, Security and Operations.

The Hortonworks Sandbox is a single node implementation of the Hortonworks Data Platform (HDP). It is packaged as a virtual machine to make evaluation and experimentation with HDP fast and easy. The tutorials and features in the Sandbox are oriented towards exploring how HDP can help you solve your business big data problems. The Sandbox tutorials will walk you through bringing some sample data into HDP and manipulating it using the tools built into HDP. The idea is to show you how you can get started and show you how to accomplish tasks in HDP. HDP is free to download and use in your enterprise and you can download it here: HDP on Sandbox

Lab 0: Set-up

Start the Sandbox VM and Open Ambari

Start the HDP Sandbox following the Sandbox Install Guide to start the VM:


Once you have installed the Sandbox VM, it resolves to the host on your environment, the address of which varies depending upon the Virtual Machine you are using(Vmware, VirtualBox etc). As, a general thumb rule, wait for the installation to complete and confirmation screen will tell you the host your sandbox resolves to. For example:

In case of VirtualBox: host would be


If you are using a private cluster or a cloud to run sandbox. Please find the host your sandbox resolves to.

Append the port number :8888 to your host address, open your browser, and access Sandbox Welcome page at http://host:8888/.

hadoop tutorial

Navigate to Ambari welcome page using the url given on Sandbox welcome page.

Both the username and password to login are admin.

If you want to search for the host address your sandbox is running on, ssh into the sandbox terminal upon successful installation and follow subsequent steps:

  1. login using username as “root” and password as “hadoop”.
  2. Type ifconfig and look for inet address under eth.
  3. Use the inet address, append :8080 and open it into a browser. It shall direct you to Ambari login page.
  4. This inet address is randomly generated for every session and therefore differs from session to session.

The following table has some useful URLs as well:

Sandbox welcome page

Ambari Dashboard

Ambari Welcome

Hive User View

Pig User View

FIle User View

SSH web Client

Hadoop Configuration

Enter the Ambari Welcome URL and then you should see a similar screen:

There are 5 key capabilities to explore in the Ambari Welcome screen:


  1. Operate Your Cluster” will take you to the Ambari Dashboard which is the primary UI for Hadoop Operators
  2. Manage Users + Groups” allows you to add & remove Ambari users and groups
  3. Clusters” allows you to grant permission to Ambari users and groups
  4. Ambari User Views” list the set of Ambari Users views that are part of the cluster
  5. Deploy Views” provides administration for adding and removing Ambari User Views

Take a few minutes to quickly explore these 5 capabilities and to become familiar their features.

Enter the Ambari Dashboard URL and you should see a similar screen:


Briefly skim through the Ambari Dashboard links (circled above) by clicking on

  1.  MetricsHeatmap and Configuration

and then the

  1.  DashboardServicesHostsAlertsAdmin and User Views icon (represented by 3×3 matrix ) to become familiar with the Ambari resources available to you.

To learn more about Hadoop please explore the HDP Getting Started documentation.
If you have questions, feedback or need help getting your environment ready visit  developer.hortonworks.com.  Please also explore the HDP documentation.   To ask a question check out the Hortonworks Forums.

Lab 1: HDFS – Loading Sensor Data into HDFS


In this section you will download the sensor data and load that into HDFS using Ambari User Views. You will get introduced to the Ambari Files User View to manage files. You can perform tasks like create directories, navigate file systems and upload files to HDFS.  In addition you’ll perform a few other file-related tasks as well.  Once you get the basics, you will create two directories and then load two files into HDFS using the Ambari Files User View.


  • HDFS backdrop
  • Step 1.1: Download data – Geolocation.zip
  • Step 1.2: Load Data into HDFS
  • Suggested readings

HDFS backdrop:

A single physical machine gets saturated with its storage capacity as the data grows. Thereby comes impending need to partition your data across separate machines. This type of File system that manages storage of data across a network of machines is called Distributed File Systems. HDFS is a core component of Apache Hadoop and is designed to store large files with streaming data access patterns, running on clusters of commodity hardware. With Hortonworks Data Platform HDP 2.2, HDFS is now expanded to support heterogeneous storage  media within the HDFS cluster.

Step 1.1: Download and Extract the Sensor Data Files

  • You can download the sample sensor data contained in a compressed (.zip) folder here:  Geolocation.zip
  • Save the Geolocation.zip file to your computer, then extract the files. You should see a Geolocation folder that contains the following files:
    • geolocation.csv – This is the collected geolocation data from the trucks. it contains records showing truck location, date, time, type of event, speed, etc.
    • trucks.csv – This is data was exported from a relational database and it shows info on truck model, driverid, truckid, and aggregated mileage info.

Step 1.2: Load the Sensor Data into HDFS

  • Go to the Ambari Dashboard and open the HDFS User View by click on the User Views icon and selecting the HDFS Files menu item.

Screen Shot 2015-07-21 at 10.17.21 AM

  • Starting from the top root of the HDFS file system, you will see all the files the logged in user (admin in this case) has access to see:


  • Click tmp. Then click  Lab2_3 button to create the /tmp/admin directory and then create the /tmp/admin/data directory.

Screen Shot 2015-07-27 at 9.42.07 PM

  • Now traverse to the /tmp/admin/data directory and upload the corresponding geolocation.csv and trucks.csv files into it.

Screen Shot 2015-07-27 at 9.43.28 PM

You can also perform the following operations on a file by right clicking on the file: DownloadMovePermissionsRename and Delete.


Data manipulation with Hive


In this section of tutorial you will be introduced to Apache Hive. In the earlier section we covered how to load data into HDFS. So now you have geolocation and trucks files stored in HDFS as csv files. In order to use this data in Hive we will tell you how to create a table and how to move data into Hive warehouse, from where it can be queried upon. We will analyze this data using SQL queries in Hive User Views and store it as ORC. We will also walk through Apache Tez and how a DAG is created when you specify Tez as execution engine for Hive. Lets start..!!


  • Hive basics
  • Step 2.1: Use Ambari Hive User Views
  • Step 2.2: Define a Hive Table
  • Step 2.3: Load Data into Hive Table
  • Step 2.4: Define an ORC table in Hive
  • Step 2.5: Review Hive Settings
  • Step 2.6: Analyze Truck Data
  • Suggested readings


Hive is a SQL like query language that enables analysts familiar with SQL to run queries on large volumes of data.  Hive has three main functions: data summarization, query and analysis. Hive provides tools that enable easy data extraction, transformation and loading (ETL).

Step 2.1: Become Familiar with Ambari Hive User View

Apache Hive presents a relational view of data in HDFS and ensures that users need not worry about where or in what format their data is stored.  Hive can display data from RCFile format, text files, ORC, JSON, parquet,  sequence files and many of other formats in a tabular view.   Through the use of SQL you can view your data as a table and create queries like you would in an RDBMS. To make it easy to interact with Hive we use a tool in the Hortonworks Sandbox called the Ambari Hive User View.   Ambari Hive User View provides an interactive interface to Hive.   We can create, edit, save and run queries, and have Hive evaluate them for us using a series of MapReduce jobs or Tez jobs. Let’s now open the Ambari Hive User View and get introduced to the environment, go to the Ambari User VIew icon and select Hive :Screen Shot 2015-07-21 at 10.10.18 AM The Ambari Hive User View looks like the following:Lab2_2 Now let’s take a closer look at the SQL editing capabilities in the User View:

  1. There are four tabs to interact with SQL:
    1. Query: This is the interface shown above and the primary interface to write, edit and execute new SQL statements
    2. Saved Queries: You can save your favorite queries and quickly have access to them to rerun or edit.
    3. History: This allows you to look at past queries or currently running queries to view, edit and rerun.  It also allows you to see all SQL queries you have authority to view.  For example, if you are an operator and an analyst needs help with a query, then the Hadoop operator can use the History feature to see the query that was sent from the reporting tool.
    4. UDFs:  Allows you to define UDF interfaces and associated classes so you can access them from the SQL editor.
  2. Database Explorer: Â The Database Explorer helps you navigate your database objects.  You can either search for a database object in the Search tables dialog box, or you can navigate through Database -> Table -> Columns in the navigation pane.
  3. The principle pane to write and edit SQL statements. This editor includes content assist via CTRL + Space to help you build queries. Content assist helps you with SQL syntax and table objects.

The command to autocomplete queries is CTRL-Space on all systems including Mac OS X.

  1. Once you have created your SQL statement you have 3 options:
    1. Execute: This runs the SQL statement.
    2. Explain: This provides you a visual plan, from the Hive optimizer, of how the SQL statement will be executed.
    3. Save as:  Allows you to persist your queries into your list of saved queries.
  2. When the query is executed you can see the Logs or the actual query results.
    1. Logs: When the query is executed you can see the logs associated with the query execution.  If your query fails this is a good place to get additional information for troubleshooting.
    2. Results: You can view results in sets of 50 by default.
  3. There are four sliding views on the right hand side with the following capabilities, which are in context of the tab you are in:
    1. Query: This is the default operation,which allows you to write and edit SQL.
    2. Settings:  This allows you to set properties globally or associated with an individual query.
    3. Visual Explain: This will generate an explain for the query.  This will also show the progress of the query.
    4. TEZ: If you use TEZ as the query execution engine then you can view the DAG associated with the query.  This integrates the TEZ User View so you can check for correctness and helps with performance tuning by visualizing the TEZ jobs associated with a SQL query.
    5. Notifications: This is how to get feedback on query execution.
      Take a few minutes to explore the various Hive User View features.

Step 2.2 Define a Hive Table

Now that you are familiar with the Hive User View, let’s create the initial staging tables for the geolocation and trucks data. In this section we will learn how to use the Ambari Hive User View to create four tables: geolocaiton_stage, trucking_stage, geolocation, trucking.  First we are going to create 2 tables to stage the data in their original csv text format and then will create two more tables where we will optimize the storage with ORC. Here is a visual representation of the Data Flow:Lab2_3

  1. Copy-and-paste the the following table DDL into the empty Worksheet of the Query Editor to define a new table named geolocation_staging:
    –Create table geolocation for staging initial load

    CREATE TABLE geolocation_stage (truckid string, driverid string, event string, latitude double, longitude double, city string, state string, velocity bigint, event_ind bigint, idling_ind bigint)ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘,’STORED AS TEXTFILE;

  2. Click the green Execute button to run the command. If successful, you should see the Succeeded status in the Query Process Results section:Lab2_4
  3. Create a new Worksheet by clicking the blue New Worksheet button:Lab2_5
  4. Notice the tab of your new Worksheet is labeled Worksheet (1). Double-click on this tab to rename the label to trucks_stage:Lab2_6
  5. Copy-and-paste the following table DDL into your trucks_stage worksheet to define a new table named trucks_stage: –Create table trucks for staging initial load

    CREATE TABLE trucks_stage(driverid string, truckid string, model string, jun13_miles bigint, jun13_gas bigint, may13_miles bigint, may13_gas bigint, apr13_miles bigint, apr13_gas bigint, mar13_miles bigint, mar13_gas bigint, feb13_miles bigint, feb13_gas bigint, jan13_miles bigint, jan13_gas bigint, dec12_miles bigint, dec12_gas bigint, nov12_miles bigint, nov12_gas bigint, oct12_miles bigint, oct12_gas bigint, sep12_miles bigint, sep12_gas bigint, aug12_miles bigint, aug12_gas bigint, jul12_miles bigint, jul12_gas bigint, jun12_miles bigint, jun12_gas bigint,may12_miles bigint, may12_gas bigint, apr12_miles bigint, apr12_gas bigint, mar12_miles bigint, mar12_gas bigint, feb12_miles bigint, feb12_gas bigint, jan12_miles bigint, jan12_gas bigint, dec11_miles bigint,  dec11_gas bigint, nov11_miles bigint, nov11_gas bigint, oct11_miles bigint, oct11_gas bigint, sep11_miles bigint, sep11_gas bigint, aug11_miles bigint, aug11_gas bigint, jul11_miles bigint, jul11_gas bigint, jun11_miles bigint, jun11_gas bigint, may11_miles bigint, may11_gas bigint, apr11_miles bigint, apr11_gas bigint, mar11_miles bigint, mar11_gas bigint, feb11_miles bigint, feb11_gas bigint, jan11_miles bigint, jan11_gas bigint, dec10_miles bigint, dec10_gas bigint, nov10_miles bigint, nov10_gas bigint, oct10_miles bigint, oct10_gas bigint, sep10_miles bigint, sep10_gas bigint, aug10_miles bigint, aug10_gas bigint, jul10_miles bigint, jul10_gas bigint, jun10_miles bigint, jun10_gas bigint, may10_miles bigint, may10_gas bigint, apr10_miles bigint, apr10_gas bigint, mar10_miles bigint, mar10_gas bigint, feb10_miles bigint, feb10_gas bigint, jan10_miles bigint, jan10_gas bigint, dec09_miles bigint, dec09_gas bigint, nov09_miles bigint, nov09_gas bigint, oct09_miles bigint, oct09_gas bigint, sep09_miles bigint, sep09_gas bigint, aug09_miles bigint, aug09_gas bigint, jul09_miles bigint, jul09_gas bigint, jun09_miles bigint, jun09_gas bigint, may09_miles bigint, may09_gas bigint, apr09_miles bigint, apr09_gas bigint, mar09_miles bigint, mar09_gas bigint, feb09_miles bigint, feb09_gas bigint, jan09_miles bigint, jan09_gas bigint)ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘,’STORED AS TEXTFILE;

  6. Execute the query and make sure it runs successfully. Let’s review some aspects of the CREATE TABLE statements issued above.  If you have a SQL background this statement should seem very familiar except for the last 3 lines after the columns definition:
  7. The ROW FORMAT clause specifies each row is terminated by the new line character.
  8. The FIELDS TERMINATED BY clause specifies that the fields associated with the table (in our case, the two csv files) are to be delimited by a comma.
  9. The STORED AS clause specifies that the table will be stored in the TEXTFILE format.
    For details on these clauses consult the Apache Hive Language Manual.
  10. To verify the tables were defined successfully, click the “refresh” icon in the Database Explorer. Under Databases, click default database to expand the list of table and the new tables should appear: Lab2_7
  11.  Click on the trucks_stage table name to view its schema. 9.  Click on the Load sample data icon to generate and execute a select SQL statement to query the table for a 100 rows. Notice your two new tables are currently empty.

You can have multiple SQL statements within each editor worksheet, but each statement needs to be separated by a semicolon “;”.   If you have multiple statements within a worksheet but you only want to run one of them just highlight the statement you want ran and then click the Execute button.

A few additional commands to explore tables:

  • show tables; – List the tables created in the database by looking up the list of tables from the metadata stored in HCatalog.
  • describe _table_name_; – Provides a list of columns for a particular table (ie describe geolocation_stage;)
  • show create _table_name_; – Provides the DDL to recreate a table (ie show create table geolocation_stage;)
  •  By default, when you create a table in Hive, a directory with the same name gets created in the /apps/hive/warehouse folder in HDFS.  Using the Ambari Files User View, navigate to the /apps/hive/warehouse folder. You should see both a geolocation_stage and trucks_stage directory:Lab2_8

The definition of a Hive table and its associated metadata (i.e., the directory the data is stored in, the file format, what Hive properties are set, etc.) are stored in the Hive metastore, which on the Sandbox is a MySQL database.

Step 2.3: Load Data into a Hive table**

  1. Let’s load some data into your two Hive tables. In this tutorial we are going to show you two different ways of populating a Hive table with data from our CSV files. One way will involve moving our data file into the correct hive directory, while the other method will involve us executing a simple Hive query to load the data.
    The first way to populate a table is to put a file into the directory associated with the table. Using the Ambari Files User View, click on the Move icon next to the file /tmp/admin/data/geolocation.csv. (Clicking on Move is similar to “cut” in cut-and-paste.)Screen Shot 2015-07-27 at 9.45.11 PM
  2. After clicking on the Move arrow your screen should look like the following: Lab2_10 Notice two things have changed:
  3. The file name geolocation.csv has grayed out some
  4. The icons associated with the operations on the files are removed. This is to indicate that this file is in a special state that is ready to be moved.
  5. Now navigate to the destination path /apps/hive/warehouse/geolocation_stage. You might notice that as you navigate through the directories that the file is pinned at the top. Once you get to the appropriate directory click on the Paste icon to move the file:
  6. Go back to the Ambari Hive View and click on the Load sample data icon next to the geolocation_stage table. Notice the table is no longer empty, and you should see the first 100 rows of the table:Lab2_12
  7. Now we’re going to show you the second way to load the data using a simple Hive query. Enter the following SQL command into an empty Worksheet in the Ambari Hive User View:

    LOAD DATA INPATH ‘/tmp/admin/data/trucks.csv’ OVERWRITE INTO TABLE trucks_stage;

This query is telling us that we want to load the data at the path /tmp/admin/data/trucks.csv, and then take the data and move it into the trucks_stage table which has all of the columns defined already.

  1.  You should now see data in the trucks_stage table:Lab2_13
  2. From the Files view, navigate to the /tmp/admin/data folder. Notice the folder is empty! The LOAD DATA INPATH command moved the trucks.csv file from the /user/admin/data folder to the /apps/hive/warehouse/trucks_stage folder.
  3. Lastly, we need to remove the header rows from each table that were loaded into the table. To do this we just need to use a single command for each table.

ALTER TABLE trucks_stage SET TBLPROPERTIES ("skip.header.line.count"="1");

ALTER TABLE geolocation_stage SET TBLPROPERTIES ("skip.header.line.count"="1");

Now when querying these two tables, the header lines should no longer appear in the results! Step 2.4: Define an ORC Table in Hive

Introducing Apache ORC

The Optimized Row Columnar (new Apache ORC project) file format provides a highly efficient way to store Hive data. It was designed to overcome limitations of the other Hive file formats. Using ORC files improves performance when Hive is reading, writing, and processing data. To use the ORC format, specify ORC as the file format when creating the table: CREATE TABLE  STORED AS ORC In this step, you will create two ORC tables (geolocation and trucks) that are created from the text data in your geolocation_stage and trucks_stage tables.

  1. From the Ambari Hive User View, execute the following table DDL to define a new table named geolocation and trucks:
    –Create table geolocation as ORC from geolocation_stage table

    CREATE TABLE geolocation STORED AS ORC AS SELECT * FROM geolocation_stage;

–Create table trucks as ORC from trucks_stage table

  1. Refresh the Database Explorer and verify you have a table named geolocation and trucks in the default database: Lab2_16 3. View the contents of the geolocation table. Notice it contains the same rows as geolocation_stage. 4. To verify geolocation is an ORC table, execute the following query:

    describe formatted geolocation;

  2. Scroll down to the bottom of the Results tab and you will see a section labeled Storage Information. The output should look like:Lab2_15

If you want to try running some of these commands from the Hive Shell follow the following steps from your terminal shell (ie putty):

  1. ssh root@ -p 2222 Root pwd is hadoop
  2. su hive
  3. hive
    Starts Hive shell and now you can enter commands and SQL
  4. quit;
    Exits out of the Hive shell.

Step 2.5: Review Hive Settings

  1. Open the Ambari Dashboard in another tab by right clicking on the Ambari icon
    Lab2_17 2.  Go to the Hive page then select the Configs tab then click on Settings tab:Lab2_18 Once you click on the Hive page you should see a page similar to above:
  2. Hive Page
  3. Hive Configs Tab
  4. Hive Settings Tab
  5. Version History of Configuration
    Scroll down to the Optimization Settings: Lab2_19 In the above screenshot we can see:
  6. Tez is set as the optimization engine
  7. Cost Based Optimizer (CBO) is turned on
    This shows the new HDP 2.3 Ambari Smart Configurations, which simplifies setting configurations


New in HDP 2.3

Hadoop is configured by a collection of XML files. In early versions of Hadoop operators would need to do XML editing to change settings.  There was no default versioning. Early Ambari interfaces made it easier to change values by showing the settings page with dialog boxes for the various settings and allowing you to edit them. However, you needed to know what needed to go into the field and understand the range of values. Now with Smart Configurations you can toggle binary features and use the slider bars with settings that have ranges.
By default the key configurations are displayed on the first page. If the setting you are looking for is not on this page you can find additional settings in the Advanced tab:Lab2_20 For example, what if we wanted to improve SQL performance by using the new Hive vectorization features, where would we find the setting and how would we turn it on.   You would need to do the following steps:

  1. Click on the Advanced tab and scroll to find the property
  2. Or, start typing in the property into the property search field and then this would filter the setting you scroll for.
    As you can see from the green circle above the hive.vectorized.execution.enabled is turned on already.

Step 2.6: Analyze the Trucks Data

Next we will be using Hive, Pig and Excel to analyze derived data from the geolocation and trucks tables. The business objective is to better understand the risk the company is under from fatigue of drivers, over-used trucks, and the impact of various trucking events on risk. In order to accomplish this we are going to apply a series of transformations to the source data, mostly though SQL, and use Pig to calculate risk. In Step 10 we will be using Microsoft Excel to generate a series of charts to better understand risk.

Let’s get started with the first transformation. We want to calculate the miles per gallon for each truck. We will start with our truck data table.  We need to sum up all the miles and gas columns on a per truck basis. Hive has a series of functions that can be used to reformat a table. The keyword LATERAL VIEW is how we invoke things. The stack function allows us to restructure the data into 3 columns labeled rdate, gas and mile with 54 rows. We pick truckid, driverid, rdate, miles, gas from our original table and add a calculated column for mpg (miles/gas) and then we will calculate average mileage.

  1. Using the Ambari Hive User View, execute the following query:
    – Create table truck_mileage from existing trucking data

    CREATE TABLE truck_mileage STORED AS ORC AS SELECT truckid, driverid, rdate, miles, gas, miles / gas mpg FROM trucks LATERAL VIEW stack( 54, ‘jun13’,jun13_miles,jun13_gas,‘may13’,may13_miles,may13_gas,‘apr13’,apr13_miles,apr13_gas,‘mar13’,mar13_miles,mar13_gas,‘feb13’,feb13_miles,feb13_gas,‘jan13’,jan13_miles,jan13_gas,‘dec12’,dec12_miles,dec12_gas,‘nov12’,nov12_miles,nov12_gas,‘oct12’,oct12_miles,oct12_gas,‘sep12’,sep12_miles,sep12_gas,‘aug12’,aug12_miles,aug12_gas,‘jul12’,jul12_miles,jul12_gas,‘jun12’,jun12_miles,jun12_gas,‘may12’,may12_miles,may12_gas,‘apr12’,apr12_miles,apr12_gas,‘mar12’,mar12_miles,mar12_gas,‘feb12’,feb12_miles,feb12_gas,‘jan12’,jan12_miles,jan12_gas,‘dec11’,dec11_miles,dec11_gas,‘nov11’,nov11_miles,nov11_gas,‘oct11’,oct11_miles,oct11_gas,‘sep11’,sep11_miles,sep11_gas,‘aug11’,aug11_miles,aug11_gas,‘jul11’,jul11_miles,jul11_gas,‘jun11’,jun11_miles,jun11_gas,‘may11’,may11_miles,may11_gas,‘apr11’,apr11_miles,apr11_gas,‘mar11’,mar11_miles,mar11_gas,‘feb11’,feb11_miles,feb11_gas,‘jan11’,jan11_miles,jan11_gas,‘dec10’,dec10_miles,dec10_gas,‘nov10’,nov10_miles,nov10_gas,‘oct10’,oct10_miles,oct10_gas,‘sep10’,sep10_miles,sep10_gas,‘aug10’,aug10_miles,aug10_gas,‘jul10’,jul10_miles,jul10_gas,‘jun10’,jun10_miles,jun10_gas,‘may10’,may10_miles,may10_gas,‘apr10’,apr10_miles,apr10_gas,‘mar10’,mar10_miles,mar10_gas,‘feb10’,feb10_miles,feb10_gas,‘jan10’,jan10_miles,jan10_gas,‘dec09’,dec09_miles,dec09_gas,‘nov09’,nov09_miles,nov09_gas,‘oct09’,oct09_miles,oct09_gas,‘sep09’,sep09_miles,sep09_gas,‘aug09’,aug09_miles,aug09_gas,‘jul09’,jul09_miles,jul09_gas,‘jun09’,jun09_miles,jun09_gas,‘may09’,may09_miles,may09_gas,‘apr09’,apr09_miles,apr09_gas,‘mar09’,mar09_miles,mar09_gas,‘feb09’,feb09_miles,feb09_gas,‘jan09’,jan09_miles,jan09_gas )dummyalias AS rdate, miles, gas;


  1. To view the data generated by the script, click Load Sample Data icon in the Database Explorer next to truck_mileage. After clicking the next button once, you should see a table that list each trip made by a truck and driver: Lab2_23

Use the Content Assist to build a query

  1. Create a new SQL Worksheet.
  2. Start typing in the SELECT SQL command, but only enter the first two letters:


  3. Press Ctrl+space to view the following content assist pop-up dialog window: Lab2_24
  4. Type in the following query, using Ctrl+space throughout your typing so that you can get an idea of what content assist can do and how it works:

    SELECT truckid, avg(mpg) avgmpg FROM truck_mileage GROUP BY truckid;


  1. Click the Save as button to save the query as average mpg: Lab2_26
  2. Notice your query now shows up in the list of “Saved Queries”, which is one of the tabs at the top of the Hive User View.
  3. Execute the average mpg query and view its results.
  4. Now lets explore the various explain features to better understand the execution of a query: Text Explain, Visual Explain and Tez Explain. Click on the Explain button: Lab2_27
  5. Verify this added the EXPLAIN command at the beginning of the query: Lab2_25
  6. Execute the query. The results should look like the following:Lab2_29
  7. Click on STAGE PLANS: to view its output, which displays the flow of the resulting Tez job: Lab2_30
  8. To see the Visual Explain click on the Visual Explain icon on the right tabs. This is a much more readable summary of the explain plan:Lab2_31
  9. If you click on the TEZ tab on the right-hand column, you can see DAG details associated with the query. Lab2_32
  10. However, you can also view the DAG by going to the Ambari Tez User View. Select the Tez View: Cluster Instance” User View from the list of User Views. Screen Shot 2015-07-21 at 10.22.56 AM Select the first DAG as it represents the last job that was executed.Lab2_34
  11. There are six tabs at the top right please take a few minutes to explore the various tabs and then click on the Graphical View tab and hover over one of the nodes with your cursor to get more details on the processing in that node. Lab2_35
  12. Go back to the Hive UV and save the query by
  13. To persist these results into a table, This is a fairly common pattern in Hive and it is called Create Table As Select) (CTAS ).  Paste the following script into a new Worksheet, then click the Execute button: – Create table truck avg_mileage from existing trucks_mileage data

    CREATE TABLE avg_mileage
    SELECT truckid, avg(mpg) avgmpg
    FROM truck_mileage
    GROUP BY truckid;

  14. To view the data generated by the script, click Load sample data icon in the Database Explorer next to avg_mileage. You see our table is now a list of each trip made by a truck.Lab2_36

Lab 3: Pig – Risk Factor

Use Pig to compute Driver Risk Factor


In this tutorial you will be introduced to Apache Pig. In the earlier section of lab you learned how to load data into HDFS and then manipulate it using Hive. We are using the Truck sensor data to better understand  risk associated with every driver. This section will teach you to compute risk using Apache Pig.


  • Pig basics
  • Step 3.1: Define Table schema
  • Step 3.2: Create Pig Script
  • Step 3.3: Quick Recap
  • Step 3.4: Execute Pig Script on Tez

Pig Basics:

Pig is a high level scripting language that is used with Apache Hadoop. Pig enables data workers to write complex data transformations without knowing Java. Pig’s simple SQL-like scripting language is called Pig Latin, and appeals to developers already familiar with scripting languages and SQL.

Pig is complete, so you can do all required data manipulations in Apache Hadoop with Pig. Through the User Defined Functions(UDF) facility in Pig, Pig can invoke code in many languages like JRuby, Jython and Java. You can also embed Pig scripts in other languages. The result is that you can use Pig as a component to build larger and more complex applications that tackle real business problems.

Pig works with data from many sources, including structured and unstructured data, and store the results into the Hadoop Distributed File System.

Pig scripts are translated into a series of MapReduce jobs that are run on the Apache Hadoop cluster.

Step 3.1: Define table schema

Now we have refined the truck data to get the average mpg  for each truck. The next task is to compute the risk factor for each driver which is the total miles driven/abnormal events. We can get the event information from the geolocation table.


If we look at the truck_mileage table, we we have the driverid and the number of miles for each trip. To get the total miles for each driver, we can group those records by driverid and then sum the miles.

  1. We will start by creating a table named driver_mileage that is created from a query of the columns we want from truck_mileage. The following query groups the records by driverid and sums the miles in the select statement. Execute this query in a new Worksheet:

— Create table DriverMileage from existing truck_mileage data

CREATE TABLE DriverMileage STORED AS ORC AS SELECT driverid, sum(miles) totmiles FROM truck_mileage GROUP BY driverid;
  1.  View the data generated by the script by clicking the Load sample data icon in the Database Explorer next to drivermileage. The results should look like:


  1.  Next, you will use Pig to compute the risk factor of each driver. Before we can run the Pig code, one of the requirements for the HCatStorer() class is that the table must already exist in Hive. The Pig code expects the following structure for a table named riskfactor. Execute the following DDL command:

— Create table avg_mileage from existing trucks_mileage data

CREATE TABLE riskfactor (driverid string,events bigint,totmiles bigint,riskfactor float)STORED AS ORC;
  1.  Verify the riskfactor table was created successfully. It will be empty now, but you will populate it from a Pig script. You are now ready to compute the risk factor using Pig. Let’s take a look at Pig and how to execute Pig scripts from within Ambari.

Step 3.2: Create Pig Script

In this tutorial we create and run a Pig script. We will use the Ambari Pig User View. Let’s get started…

For more information on Pig scripting, you can view the link here for some documentation

 a.  Log in to Ambari Pig User Views

To get to the Ambari Pig User View, click on the User Views icon at top right and select Pig:

Screen Shot 2015-07-21 at 10.12.41 AM
This will bring up the Ambari Pig User View interface. Your Pig View does not have any scripts to display, so it will look like the following:


On the left is a list of your scripts, and on the right is a composition box for writing scripts. A special feature of the interface is the Pig helper at the bottom. The Pig helper will provide us with templates for the statements, functions, I/O statements, HCatLoader() and Python user defined functions. At the very bottom are status areas that will show the results of our script and log files.

The following screenshot shows and describes the various components and features of the Pig User View:


b. Create a New Script

Let’s enter a Pig script. Click the New Script button in the upper-right corner of the view:


Name the script riskfactor.pig, then click the Create button:


c. Load Data in Pig using Hcatalog

We are going to use HCatalog to load data into Pig. HCatalog allows us to share schema across tools and users within our Hadoop environment. It also allows us to factor out schema and location information from our queries and scripts and centralize them in a common repository. Since it is in HCatalog we can use the HCatLoader() function. Pig makes it easy by allowing us to give the table a name or alias and not have to worry about allocating space and defining the structure. We just have to worry about how we are processing the table.

  • We can use the Pig helper at the bottom of the screen to give us a template for the line. Click on Pig helper -> HCatalog->load template
  • The entry %TABLE% is highlighted in red for us. Type the name of the table which is geolocation.
  • Remember to add the a = before the template. This saves the results into a. Note the ‘=’ has to have a space before and after it.
  • Our completed line of code will look like:

    a = LOAD ‘geolocation’ using org.apache.hive.hcatalog.pig.HCatLoader();

Copy-and-paste the above Pig code into the riskfactor.pig window.

NOTE sign

  • You can use the command DUMP %VAR% if you want to view the data inside.
  • Just replace %VAR% with the variable you wish to view.

    d.  Filter your data set

The next step is to select a subset of the records so that we just have the records of drivers for which the event is not normal. To do this in Pig we use the Filter operator. We tell Pig to Filter our table and keep all records where event !=“normal” and store this in b. With this one simple statement Pig will look at each record in the table and filter out all the ones that do not meet our criteria.

  • We can use Pig Help again by clicking on Pig helper->Relational Operators->FILTER template
  • We can replace %VAR% with “a” (hint: tab jumps you to the next field)
  • Our %COND% is “event !=’normal’; ” (note: single quotes are needed around normal and don’t forget the trailing semi-colon)
  • Complete line of code will look like:

    b = filter a by event != ‘normal’;

Copy-and-paste the above Pig code into the riskfactor.pig window.

    e.  Iterate your data set

Now that we have the right set of records we can iterate through them. We use the “foreach” operator on the grouped data to iterate through all the records. We would also like to know how many times a driver has a non normal event associated with him. to achieve this we add ‘1’ to every row in the data set.

  • Pig helper ->Relational Operators->FOREACH template will get us the code
  • Our %DATA% is b and the second %NEW_DATA% is “driverid,event,(int) ‘1’ as occurance;
  • Complete line of code will look like:

    c = foreach b generate driverid, event, (int) ‘1’ as occurance;

Copy-and-paste the above Pig code into the riskfactor.pig window:

    f.  Calculate the total non normal events for each driver

The group statement is important because it groups the records by one or more relations. In this case we would like to group by driver id and iterate over each row again to sum the non normal events.

  • Pig helper ->Relational Operators->GROUP %VAR% BY %VAR% template will get us the code
  • First %VAR% takes “c” and second %VAR% takes “driverid;
  • Complete line of code will look like:

    d = group c by driverid;

Copy-and-paste the above Pig code into the riskfactor.pig window.

  • Next use Foreach statement again to add the occurance.

    e = foreach d generate group as driverid, SUM(c.occurance) as t_occ;

    g.  Load drivermileage table and perform a join operation

In this section we will load drivermileage table into Pig using Hcatlog and perform a join operation on driverid. The resulting data set will give us total miles and total non normal events for a particular driver.

  • Load drivermileage using HcatLoader()

    g = LOAD ‘drivermileage’ using org.apache.hive.hcatalog.pig.HCatLoader();

  • Pig helper ->Relational Operators->JOIN %VAR% BY template will get us the code
  • Replace %VAR% by ‘e’ and after BY put ‘driverid, g by driverid;
  • Complete line of code will look like:

    h = join e by driverid, g by driverid;

Copy-and-paste the above two Pig codes into the riskfactor.pig window.

    h.  Compute Driver Risk factor

In this section we will associate a driver risk factor with every driver. Driver risk factor will be calculated by dividing total miles travelled by non normal event occurrences.

  • We will use Foreach statement again to compute driver risk factor for each driver.
  • Use the following code and paste it into your Pig script.

    final_data = foreach h generate $0 as driverid, $1 as events, $3 as totmiles, (float) $3/$1 as riskfactor;

  • As a final step store the data into a table using Hcatalog.

store final_data into ‘riskfactor’ using

Here is the final code and what it will look like once you paste it into the editor.

— Geolocation has data stored in ORC format

a = LOAD 'geolocation' using org.apache.hive.hcatalog.pig.HCatLoader();  
b = filter a by event != 'normal';  
c = foreach b generate driverid, event, (int) '1' as occurance;  
d = group c by driverid;  
e = foreach d generate group as driverid, SUM(c.occurance) as t_occ;  
g = LOAD 'drivermileage' using org.apache.hive.hcatalog.pig.HCatLoader();  
h = join e by driverid, g by driverid;  
final_data = foreach h generate $0 as driverid, $1 as events, $3 as totmiles, (float) $3/$1 as riskfactor;  
store final_data into 'riskfactor' using org.apache.hive.hcatalog.pig.HCatStorer();


Save the file riskfactor.pig by clicking the Save button in the left-hand column.

Step 3.3: Quick Recap

Before we execute the code, let’s review the code again:

  • The line a= loads the geolocation table from HCatalog.
  • The line b= filters out all the rows where the event is not ‘Normal’.
  • Then we add a column called occurrence and assign it a value of 1.
  • We then group the records by driverid and sum up the occurrences for each driver.
  • At this point we need the miles driven by each driver, so we load the table we created using Hive.
  • To get our final result, we join by the driverid the count of events in e with the mileage data in g.
  • Now it is real simple to calculate the risk factor by dividing the miles driven by the number of events

You need to configure the Pig Editor to use HCatalog so that the Pig script can load the proper libraries. In the Pig arguments text box, enter -useHCatalog   and click the Add button:

Please note that the argument -useHCatalog is case sensistive


The Arguments section of the Pig View should now look like the following:

Step 3.4: Execute Pig Script on Tez

  1. You are now ready to execute the script. Click Execute on Tez checkbox and finally hit the blue Execute button to submit the job. Pig job will be submitted to the cluster. This will generate a new tab with a status of the running of the Pig job and at the top you will find a progress bar that shows the job status.


  1.  Wait for the job to complete. The output of the job is displayed in the Results section. Your script does not output any result – it stores the result into a Hive table – so your Results section will be empty.



Click on the Logs twisty to see what happened when your script ran. This is where you will see any error messages. The log may scroll below the edge of your window so you may have to scroll down.

  1.   Go back to the Ambari Hive User View and browse the data in the riskfactor table to verify that your Pig job successfully populated this table. Here is what is should look like:


At this point we now have our truck miles per gallon table and our risk factor table. The next step is to pull this data into Excel to create the charts for the visualization step.


July 26, 2015 at 10:36 am

in section titled “Load data in Pib using HCatalog”

The example code line is correct:
a = LOAD ‘geolocation’ using org.apache.hive.hcatalog.pig.HCatLoader();

but the codeline generated by PIG Helper is missing the word “hive” after “org.apache.” and before “.hcatalog”.

Maybe a warning in the tutorial would help to double check code generated by automated features etc

    Zachary Blanco
    September 13, 2015 at 1:32 pm

    Thanks for the tip Steven. We’ve taken this into account and should update it shortly.

steven white
July 26, 2015 at 5:07 pm

section : Step 4.1: Configuring Spark services using Ambari
2. Close the Ambari browser and we will get running with some codes on Spark. ssh into the sandbox using root as login and hadoop as password.

I found this step (2) confusing. I recommend the following:
In order to run some example code on Spark you need to open a window or tool that allows LINUX command line syntax to be executed e.g. SSH, Terminal etc. There is no need to close the Ambari browser window.

steven white
July 26, 2015 at 5:08 pm


Load data into ORC table
hiveContext.sql(“select * from finalresults”)

should be
hiveContext.sql(“select * from finalresults”)

(note the double quotes are straight and not curved)

    steven white
    July 26, 2015 at 5:10 pm

    Ok, I cant seem to get the double quotes straight on this web page.

    Anubhav Awasthi
    August 6, 2015 at 11:16 am

    Thank you for pointing this out. We fixed it.

steven white
July 26, 2015 at 5:23 pm


Step 5.b.2: Visualize Data with Microsoft Excel

Step 4 “4. For a map we need location information and a data point” and step 5
It needs to be made clearer that the user is expected to go to Hive to do these steps. The tutorial is deep in Excel and then suddenly assumes the user will know that they need to go back to using Hive.

Aniket Sao
July 27, 2015 at 10:04 pm

riskfactor.pig file executed successfully.Got the following message after executing riskfactor.pig file (Step 3.4) under the Logs. The data was never copied under the riskfactor table


WARNING: Use “yarn jar” to launch YARN applications.
15/07/28 04:57:07 INFO pig.ExecTypeProvider: Trying ExecType : LOCAL
15/07/28 04:57:07 INFO pig.ExecTypeProvider: Trying ExecType : MAPREDUCE
15/07/28 04:57:07 INFO pig.ExecTypeProvider: Picked MAPREDUCE as the ExecType
2015-07-28 04:57:07,883 [main] INFO org.apache.pig.Main – Apache Pig version (rexported) compiled Jul 14 2015, 10:10:23
2015-07-28 04:57:07,885 [main] INFO org.apache.pig.Main – Logging error messages to: /hadoop/yarn/local/usercache/admin/appcache/application_1438051512308_0005/container_e12_1438051512308_0005_01_000002/pig_1438059427878.log
2015-07-28 04:57:09,208 [main] ERROR org.apache.pig.Main – ERROR 2997: Encountered IOException. File –useHCatalog does not exist
Details at logfile: /hadoop/yarn/local/usercache/admin/appcache/application_1438051512308_0005/container_e12_1438051512308_0005_01_000002/pig_1438059427878.log
2015-07-28 04:57:09,276 [main] INFO org.apache.pig.Main – Pig script completed in 1 second and 980 milliseconds (1980 ms)

    July 30, 2015 at 1:39 pm

    I am having the same problem. Also even if I save the pig script when I go back to it, it is empty and not saved.

    August 3, 2015 at 8:13 am

    I got the same problem and found the solution. Don’t copy the –useHCatalog, instead, type it. The “-” maybe not a correct character in the web page, so you’d best hand type it to make sure.

      Lev Sigal
      August 9, 2015 at 12:17 am

      My execution of riskfactor.pig – FAILED with result: File /tmp/.pigjobs/riskfactorpig_09-08-2015-06-48-39/stdout not found. The stack trace begins from: java.lang.IllegalArgumentException: Path segment is null.
      Please advise,
      Thanks, Lev

July 28, 2015 at 3:46 pm

The copy that says “Here is a short video introduction on Tez.” should instead say, “Here is a long video on Tez that includes a short deep dive.” The average length of a youtube video is a little over 3 minutes long, so calling a 47 minute video “short” is inaccurate.

BTW, longest “Hello World” tutorial ever.

July 29, 2015 at 4:02 am

Do you have any shell tutorial for HIVE and PIG?

July 31, 2015 at 5:26 pm

i think
b = filter a by event != ‘normal’;

should be changed to
b = filter a by event == ‘normal’;

assuming high risk = high risk factor

you want to divide total miles by normal occurrences. (higher abnormal occurrences would increase the risk factor in this case.)

so if total miles is 1000 and you have 10 normal, 2 abnormal
risk factor would be 1000/10 = 100
which would be lower than someone who has 11 abnormal and 1 normal
risk factor would be 1000/1 = 1000

    Anubhav Awasthi
    August 6, 2015 at 10:41 am

    Thank you for the suggestion. The idea is to communicate the possibilities of computation that could be done using Pig. You can very well build your own logic and draw inference through it.

July 31, 2015 at 6:45 pm

Here is the problem I ran into, Created tables in xademo database . Then try to calcuate riskfactor using PIG script. Got following error.

ERROR org.apache.pig.tools.grunt.Grunt – ERROR 1115: Table not found : default.geolocation table not found

gelocation table is created in xademo database.

How can I specify PIG script to look for database xademo instead of deafult database ?

Thanks in advance.
Keep doing good work.

    July 31, 2015 at 7:23 pm

    Found the solution. When you are using non-default database. you have to use ‘dbname.tablename’.

    Here is Script.
    a = LOAD ‘xademo.geolocation’ using org.apache.hive.hcatalog.pig.HCatLoader();

August 2, 2015 at 12:41 am

I am unable to connect to ambari server. I am using with username and password as admin. The services are up and running.

Can somebody please help me log into ambari server?


    michel Osborne
    August 3, 2015 at 12:54 pm

    Use the ifconfig Unix command to get in the VM sandbox and pick-up the IP address that will be displayed. The use this IP address in the browser (it didn’t worked with IE v10 & v11 nor with Firefox, had to use chrome).

    Make sure your VMWare is properly configure to be able to be have access to your VMWare instance (nat config)


    August 3, 2015 at 6:50 pm

    Hi Soumik, is normally used with the virtualbox image. So I assume you are either on VMware or Hypervisor. For either of those, you should see the console and it should display the ip address. Do you see an ip adress mentioned in the console?


kaustubh patil
August 10, 2015 at 10:46 am

Thank you for such a detailed and comprehensive article. It let me get started with Hadoop.

August 28, 2015 at 5:03 pm

I am trying to upload file to HDFS and New Directory and Upload button are not enabled for me. ALso when i try to use -copyFromLocal command, i get error “no such file exists….”

looks like some permission missing. Kindly help

Rafael Coss
September 4, 2015 at 11:00 am

@Apurv Can you please post a little more details in the Sandbox forum?

Do you have read/write access to the directory where you are trying to upload the file to?

> ALso when i try to use -copyFromLocal command,
Which step is this coming from?

Dave S
September 4, 2015 at 12:10 pm

Perhaps you people should be promoting LibreOffice instead of ms office. Open source is where it’s at – or haven’t you been paying attention?

September 6, 2015 at 6:46 am


I am trying to execute this below query from grunt shell :
a = LOAD ‘geolocation’ using org.apache.hive.hcatalog.pig.HCatLoader();

i am facing this error :
[main] ERROR org.apache.pig.tools.grunt.Grunt – ERROR 1070: Could not resolve org.apache.hive.hcatalog.pig.HCatLoader using imports: [, java.lang., org.apache.pig.builtin., org.apache.pig.impl.builtin.]

tried starting the pig with -useHcatalog agrument but no success.
Please help me to resolve this problem.


September 7, 2015 at 10:03 am

I am having trouble getting the example (risk factor – Lab 3) to run. Here is a cut/paste of my script:
a = LOAD ‘geolocation’ using org.apache.hive.hcatalog.pig.HCatLoader();
b = filter a by event != ‘normal’;
c = foreach b generate driverid, event, (int) ‘1’ as occurance;
d = group c by driverid;
e = foreach d generate group as driverid, SUM(c.occurance) as t_occ;
g = LOAD ‘drivermileage’ using org.apache.hive.hcatalog.pig.HCatLoader();
h = join e by driverid, g by driverid;
final_data = foreach h generate $0 as driverid, $1 as events, $3 as totmiles, (float) $3/$1 as riskfactor;
store final_data into ‘riskfactor’ using org.apache.hive.hcatalog.pig.HCatStorer();
Here is a cut/paste of the resulting log:

WARNING: Use “yarn jar” to launch YARN applications.
15/09/07 16:59:10 INFO pig.Main: Pig script completed in 142 milliseconds (142 ms)

I have the -useHCATALOG argumant set.

Any help would be appreciated. Thanks!

September 7, 2015 at 10:08 am

Ah, well, never mind…changed the argument to -useHCatalog and it worked.


    Zachary Blanco
    September 13, 2015 at 1:34 pm

    Hey Jeff, thanks for the response. The tutorial now makes a note that the argument “-useHCatalog” is case sensistive

September 12, 2015 at 9:47 pm

Great tutorial, few minor challenges listed below.
(1) the positional fields seems incorrect, the $3 should be changed to $5, describe h, would be great help

final_data = foreach h generate $0 as driverid, $1 as events, $5 as totmiles, (float) $5/$1 as riskfactor;

(2) In Lab 2, for hive, we created truck_mileage, so can’t figure out where drivermileage came from
(3) In hadoop 2.3 sandbox, following correction was needed, I.e “hive” was missing
a = LOAD ‘geolocation’ USING org.apache.hive.hcatalog.pig.HCatLoader();

PB Singh
September 23, 2015 at 8:58 am

I am loading file geolocation.csv in /tmp/admin/data
The original file has 8001 rows (1 header + 8000 data)
After loading file in /tmp/admin/data, on download I see 8012 rows. Rows from 7986 to 7996 are repeated with error as rows 8002 start with
1 -117.949508 La Puente California 0 1 1
If anyone else has faced same issue and suggestion to fix.

    PB Singh
    September 25, 2015 at 8:50 am

    I ended up loading data using command line.
    Made copy of geolocation.csv as dummy1.csv
    Created shared disc to make dummy1.csv to accessible in unix.
    hdfs dfs -put dummy1.csv /tmp/admin/data/
    At this step dummy1.csv has correct rows and no corruption.
    Loaded geolocation_stage.csv from dummy1.csv.

October 1, 2015 at 6:31 pm

Step : “c. Load Data in Pig using Hcatalog”
You mention much later in step “Step 3.3: Quick Recap” that you need to set PIG argument “-useHCatalog” but thats after you show several code lines e.g. LOAD, STORE etc that a user would typically want to run immediately to test that they run. So basically put the information about “-useHCatalog” before the first line of PIG code that you expect a user to run or else they are going to be very frustrated that their code doesn’t run and start Googling answers

October 2, 2015 at 6:24 pm

in step “f. Calculate the total non normal events for each driver” it shows code line ” e = foreach d generate group as driverid, SUM(c.occurance) as t_occ;”.

I think its worth highlighting the fact that the “c.” in “c.occurance” is necessary because when code line “d = group c by driverid;” generated table “d” a field called “c.occurance” i.e. that “c” qualifier is not a direct reference to table “c” itself but is simply part of the field name with table “d”.

October 2, 2015 at 6:40 pm

step ” h. Compute Driver Risk factor” seems to have some very disjointed text “store final_data into ‘riskfactor’ using” missing text after “using”? and “— Geolocation has data stored in ORC format” just suddenly makes a statement about ORC format which seems out of place with PIG and the examples the user just worked on

October 5, 2015 at 5:12 pm


I am running the HDP Sandbox on Microsoft Azure cloud, I am not able to SSH into the Linux OS (putty or via web) using the “root” identity with “hadoop” as password, I can SSH using my Azure cloud username and password….will I ever need “root” access to the OS for this entire tutorial/ exercise ?


siri t
October 11, 2015 at 8:36 pm

while SELECT truckid, avg(mpg) avgmpg FROM truck_mileage GROUP BY truckid;
This is error, i am getting , S020 Data storage error. I tried to google it and find the solution, did get much help. I am running hdp sandbox vm on azure with pay as you go with A4 requirement settings. Still trying to solve it.

Need help
org.apache.ambari.view.PersistenceException: Caught exception trying to store view entity org.apache.ambari.view.hive.resources.jobs.viewJobs.JobImpl@683

siri t
October 11, 2015 at 8:47 pm

while executing SELECT truckid, avg(mpg) avgmpg FROM truck_mileage GROUP BY truckid;

This is error, i am getting , S020 Data storage error.

I tried to google it and find the solution, didn’t get much help. I am running hdp sandbox vm on azure with pay as you go with A4 requirement settings. Still trying to solve it.

Need help
org.apache.ambari.view.PersistenceException: Caught exception trying to store view entity org.apache.ambari.view.hive.resources.jobs.viewJobs.JobImpl@683

siri t
October 15, 2015 at 8:52 am

Hi Kuan Butts,
Same problem , no advance .Same errors , still trying to solve

Farhan Iqbal
October 22, 2015 at 3:41 pm

In step 2.6 when I go to 13. I don’t see

rather I see
Plan not optimized by CBO
Vertex dependency in root stage
Reducer 2 <- Map 1 (SIMPLE_EDGE)

Is anyone else also facing this issue and can explain me whats causing this.

October 25, 2015 at 3:11 am

I am facing below error while executing the SQL Query to create tables in HIVE View:

E090 HDFS020 Could not write file /user/admin/hive/jobs/hive-job-4-2015-10-25_03-43/query.hql [HdfsApiException]

Can you please suggest ??

October 28, 2015 at 5:41 am

guys, now that this tutorial is no longer divided in sections the layout is completely screwed up. Was there a text conversion? Text now contains weird characters (where a special character is expected or perhaps a list). The scripts that we should copy paste contains wrong quote characters and uncommented text (using –) is not uncommented any more when copied because the two — are combined in a singular longer –. Just like ms word

October 30, 2015 at 10:44 pm


this not working for me taking too much and time results failed with some error message geolocation table created successfully please help to get rid off this step problem to continue

    November 2, 2015 at 12:36 am

    I’ve got the same issue Namachivayam. trucks table cannot be created as ORC. Not sure what happened with this guide. It worked a month ago just fine but wanted to start over…

    Nestor Saavedra
    November 2, 2015 at 3:04 pm

    Same problem here, not sure what to do.

    Nestor Saavedra
    November 2, 2015 at 7:45 pm
    November 10, 2015 at 7:42 pm

    Hi guys,
    Try setting orc.compress.size to a value of 1024. Let me know if that works.

      Wahyu Saputra
      November 24, 2015 at 8:57 am

      Hello Robert,

      I tried your suggestion and it worked for me.

      CREATE TABLE trucks STORED AS ORC TBLPROPERTIES (“orc.compress.size”=”1024”) AS SELECT * FROM trucks_stage;

      Many thanks.

November 4, 2015 at 4:56 am

Hi Nevstor, I checked that page they mentioned to change the storage type.. where and how to change that please let me know….

November 19, 2015 at 7:19 am

Which credentials should I use to login into the Shell box (http://host:4200)

November 23, 2015 at 10:11 am

When running CREATE TABLE trucks STORED AS ORC AS SELECT * FROM trucks_stage;

Got an error S020 Data storage error like
org.apache.ambari.view.PersistenceException: Caught exception trying to store view entity org.apache.ambari.view.hive.resources.jobs.viewJobs.JobImpl@666

Please advise.

November 26, 2015 at 5:07 am

i can not download file geolocation.zip , unable to connect to the site. I googled it and i find something about file “robot.txt” wich is on site. I dont know what´s going on, can you help me pleas? Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

If you have specific technical questions, please post them in the Forums

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">