Sqoop

Apache Sqoop is a tool designed for efficiently transferring bulk data between Apache Hadoop and structured datastores such as relational databases. Sqoop imports data from external structured datastores into HDFS or related systems like Hive and HBase. Sqoop can also be used to extract data from Hadoop and export it to external structured datastores such as relational databases and enterprise data warehouses. Sqoop works with relational databases such as: Teradata, Netezza, Oracle, MySQL, Postgres, and HSQLDB.

What Sqoop Does

Designed to efficiently transfer bulk data between Apache Hadoop and structured datastores such as relational databases, Apache Sqoop:

  • Allows data imports from external datastores and enterprise data warehouses into Hadoop
  • Parallelizes data transfer for fast performance and optimal system utilization
  • Copies data quickly from external systems to Hadoop
  • Makes data analysis more efficient 
  • Mitigates excessive loads to external systems.

How Sqoop Works

Sqoop provides a pluggable connector mechanism for optimal connectivity to external systems. The Sqoop extension API provides a convenient framework for building new connectors which can be dropped into Sqoop installations to provide connectivity to various systems. Sqoop itself comes bundled with various connectors that can be used for popular database and data warehousing systems.


References
http://hortonworks.com

Introduction to Apache Pig

Pig is a large scale data analysis platform with a high level data description and manipulation language.  A common use of MapReduce is aggregating information from large
text files such as log files or HTML documents.

This means that the programmer no longer has to write MapReduce programs in Java,but instead can write shorter Pig Latin queries or batch scripts to accomplish the data manipulation tasks needed. The Pig platform then generates, optimizes and compiles MapReduce tasks from the Pig Latin statements and commits them to Hadoop for execution. Pig Latin queries can also be run in local mode without parallelism.

What is Pig?

Pig provides a higher level of abstraction for users, giving them access to the power and flexibility of Hadoop without requiring them to write extensive data-processing applications in low-level Java code.

Pig operates as a layer of abstraction on top of the MapReduce programming model. It
frees programmers from having to write MapReduce functions for each low level data
processing operation and instead allows them to simply describe, how data should be
analyzed using higher level data definition and manipulation statements. Additionally,
because Pig still uses MapReduce, it retains all its useful traits, such as automatic
parallelism, fault tolerance and good scalability, which are essential when working with
very large data sets.

  • Provides an engine for executing data flows in parallel on Hadoop.
  • Includes a language, Pig Latin, for expressing these data flows.

Pig Latin includes operators for many of the traditional data operations (join, sort, filter, etc.), as well as the ability for users to develop their own functions for reading, processing, and writing data.

Pig on Hadoop

Pig runs on Hadoop. It makes use of both the Hadoop Distributed File System, HDFS, and Hadoop’s processing system, MapReduce.

Pig Latin is a dataflow language. This means it allows users to describe how data from one or more inputs should be read, processed, and then stored to one or more outputs in parallel.

Unlike traditional SQL, Pig, is designed with a long series of data operations in mind, so there is no need to write the data pipeline in an inverted set of confusing sub-queries or to worry about storing data in temporary tables.

Advantages over using MapReduce directly   

Pig Latin is much lower cost to write and maintain than Java code for MapReduce.

Input and Output

The first step to any data flow is to specify your input. In Pig Latin this is done with the load statement.

divs = load ‘/data/examples/NYSE_dividends’ as (exchange, symbol, date, dividends);

will look for a file called NYSE_dividends in the directory /data/examples assuming the columns are tab separated.

After you have finished processing your data, you will want to write it out somewhere. Pig provides the store statement for this purpose. In many ways it is the mirror image of the load statement. By default, Pig stores your data on HDFS in a tab-delimited file:

store processed into ‘/data/examples/processed’;

Relational Operations

Relational operators are the main tools Pig Latin provides to operate on your data. They allow you to transform it by sorting, grouping, joining, projecting, and filtering.

foreach

foreach takes a set of expressions and applies them to every record in the data pipeline.

For example, the following code loads an entire record, but then removes all but the user and id fields from each record:

A = load ‘input’ as (user:chararray, id:long, address:chararray, phone:chararray,preferences:map[]);

B = foreach A generate user, id;

User Defined Functions (UDFs) can be also invoked in foreach.

Filter

The filter statement allows you to select which records will be retained in your data pipeline. A filter contains a predicate. If that predicate evaluates to true for a given record, that record will be passed down the pipeline. Otherwise, it will not.

divs = load ‘NYSE_dividends’ as (exchange:chararray, symbol:chararray, date:chararray, dividends:float);

startswithcm = filter divs by symbol matches ‘CM.*’;

Group

The group statement collects together records with the same key. Group collects all records with the

same value for the provided key together into a bag. You can then pass this to an aggregate function if you want or do other things with it:

daily = load ‘NYSE_daily’ as (exchange, stock);

grpd = group daily by stock;

cnt = foreach grpd generate group, COUNT(daily);

You can also group on multiple keys.

Order by

The order statement sorts your data for you, producing a total order of your output data.

daily = load ‘NYSE_daily’ as (exchange:chararray, symbol:chararray, date:chararray, open:float, high:float, low:float, close:float,

volume:int, adj_close:float);

bydate = order daily by date;

Distinct

The distinct statement is very simple. It removes duplicate records. It works only on entire records, not on individual fields:

— find a distinct list of ticker symbols for each exchange
— This load will truncate the records, picking up just the first two fields.
daily = load ‘NYSE_daily’ as (exchange:chararray, symbol:chararray);
uniq = distinct daily;

Join

join is one of the workhorses of data processing, and it is likely to be in many of your Pig Latin scripts. join selects records from one input to put together with records from another input. This is done by indicating keys for each input. When those keys are equal, the two rows are joined. Records for which no match is found are dropped:

daily = load ‘NYSE_daily’ as (exchange, symbol, date, open, high, low, close, volume, adj_close);
divs = load ‘NYSE_dividends’ as (exchange, symbol, date, dividends);
jnd = join daily by symbol, divs by symbol;

You can also join on multiple keys. In all cases you must have the same number of keys, and they must be of the same or compatible types

Limit

Sometimes you want to see only a limited number of results. Limit allows you do this:

divs = load ‘NYSE_dividends’;

first10 = limit divs 10;

Sample

sample offers a simple way to get a sample of your data. It reads through all of your data but returns only a percentage of rows. So, in the following example, 0.1 indicates 10%:

divs = load ‘NYSE_dividends’;
some = sample divs 0.1;

References
Programming Pig by Alan Gates

 

 

 

 

 

 

 

 

Hive Introduction

Introduction

The driving force behind conceptualizing Hive was that creating MapReduce programs was not easy for many users.
Writing a custom MapReduce program for Word Count takes 63 lines of code. Having Hive perform the same task only takes 7 easy lines of code!
Hive uses familiar database concepts in Hadoop’s unstructured world.

So what is Hive?

  1. Data warehouse system built on top of Hadoop.
  2. Facilitates easy data summarization, ad-hoc queries, and the analysis of very large datasets stored in Hadoop.
  3. Provides SQL interface, known as HiveQL or HQL allowing easy querying of data in Hadoop. HQL has its own Data Definition and Data Manipulation languages similar to the DML and DDL many of us already have experience with.
  4. In Hive, the HQL queries are implicitly translated into one or more MapReduce jobs, shielding the user from much more advanced and time consuming programming.
  5. Hive provides a mechanism to project structure (like tables and partitions) onto the data in Hadoop and uses a metastore to map file structure to tabular form.

And What Hive is not?

  1. Hive is not a full database.
  2. Hive is not a real-time processing system rather best suited for batch jobs and huge datasets. Think heavy analytics and large aggregations.
  3. Latencies are often much higher than in a traditional database system. Hive is schema on read which provides for fast loads and flexibility, at the sacrifice of query time.
  4. Lacks full SQL support and does not provide row level inserts, updates or deletes.
  5. Does not support transactions and has limited subquery support.

Applications and organizations using Hive include (alphabetically):

CNET-We use Hive for data mining, internal log analysis and ad hoc queries.
Digg- We use Hive for data mining, internal log analysis, R&D, and reporting/analytics.
Grooveshark- We use Hive for user analytics, dataset cleaning, and machine learning R&D.
Papertrail- We use Hive as a customer-facing analysis destination for our hosted syslog and app log management service.
Scribd- We use hive for machine learning, data mining, ad-hoc querying, and both internal and user-facing analytics
VideoEgg- We use Hive as the core database for our data warehouse where we track and analyze all the usage data of the ads across our network.

References

https://cwiki.apache.org/confluence/display/Hive/PoweredBy
http://bigdatauniversity.com/

Create your own website, free on WordPress.com.Create your own website.
Start free