Showing posts with label hdfs. Show all posts
Showing posts with label hdfs. Show all posts

Friday, January 23, 2015

How-To : Setup Development Environment for Hadoop MapReduce

This post is intended for folks who are looking out for a quick start on developing a basic Hadoop MapReduce application. We will see how to set up a basic MR application for WordCount using Java, Maven and Eclipse and run a basic MR program in local mode , which is easy for debugging at … Continue reading How-To : Setup Development Environment for Hadoop MapReduce →


The post How-To : Setup Development Environment for Hadoop MapReduce appeared first on Saurz{Code}.


Sunday, June 29, 2014

Hadoop : Getting Started with Pig

What is Pig?


Pig is a high level scripting language that is used with Apache Hadoop. Pig enables data analysts 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 Scripts are converted into MapReduce Jobs which runs on data stored in HDFS (refer to the diagram below).


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 Architecture


Pig Achitecture



How Pig is being Used ?



  • Rapid prototyping of algorithms for processing large data sets.

  • Data Processing for web search platforms.

  • Ad Hoc queries across large data sets.

  • Web log processing.


Pig Elements


Pig consists of three elements -




  • Pig Latin

    • High level scripting language

    • No Schema

    • Translated to MapReduce Jobs



  • Pig Grunt Shell

    • Interactive shell for executing pig commands.



  • PiggyBank

    • Shared repository for User defined functions (explained later).




Pig Latin Statements 


Pig Latin statements are the basic constructs you use to process data using Pig. A Pig Latin statement is an operator that takes a relation as input and produces another relation as output(except LOAD and STORE statements).


Pig Latin statements are generally organized as follows:




  • A LOAD statement to read data from the file system.

  • A series of "transformation" statements to process the data.

  • A DUMP statement to view results or a STORE statement to save the results.


Note that a DUMP or STORE statement is required to generate output.




  • In this example Pig will validate, but not execute, the LOAD and FOREACH statements.
    A = LOAD 'student' USING PigStorage() AS (name:chararray, age:int, gpa:float);
    B = FOREACH A GENERATE name;


  • In this example, Pig will validate and then execute the LOAD, FOREACH, and DUMP statements.
    A = LOAD 'student' USING PigStorage() AS (name:chararray, age:int, gpa:float);
    B = FOREACH A GENERATE name;
    DUMP B;
    (John)
    (Mary)
    (Bill)
    (Joe)



Storing Intermediate Results


Pig stores the intermediate data generated between MapReduce jobs in a temporary location on HDFS. This location must already exist on HDFS prior to use. This location can be configured using the pig.temp.dir property.



Storing Final Results


Use the STORE operator and the load/store functions to write results to the file system ( PigStorage is the default store function).


Note: During the testing/debugging phase of your implementation, you can use DUMP to display results to your terminal screen. However, in a production environment you always want to use the STORE operator to save your results.



Debugging Pig Latin


Pig Latin provides operators that can help you debug your Pig Latin statements:




  • Use the DUMP operator to display results to your terminal screen.

  • Use the DESCRIBE operator to review the schema of a relation.

  • Use the EXPLAIN operator to view the logical, physical, or map reduce execution plans to compute a relation.

  • Use the ILLUSTRATE operator to view the step-by-step execution of a series of statements.


What is Pig User Defined Functions (UDFs) ?


Pig provides extensive support for user-defined functions (UDFs) as a way to specify custom processing. Functions can be a part of almost every operator in Pig.UDF is very powerful functionality to do many complex operations on data.The Piggy Bank is a place for Pig users to share their functions(UDFs).


Example:



REGISTER saurzcodeUDF.jar;
A = LOAD 'employee_data' AS (name: chararray, age: int, designation: chararray);
B = FOREACH A GENERATE saurzcodeUDF.UPPER(name);
DUMP B;

This article was just a Getting Started Article on Pig , I will cover further details about How to to Write Pig Latin commands for some basic operations like JOIN,FILTER,GROUP, ORDER etc. , also how to make your own UDFs for processing on Hadoop cluster.


References :-




  • http://pig.apache.org






 Related articles :


Monday, April 21, 2014

Free Online Hadoop Trainings

Hadoop and Big Data are becoming the new hot trends of the industry , being the most sought out skills in the market.There are various vendors and online training providers coming up with a nice explanation of some of the core concepts underlying Hadoop frameworks like Mapreduce,HDFS and various components involved in Hadoop Ecosystem.I will try to list down some of these resources here -

1. Udacity - Cloudera came with this nice course named "Intro to Hadoop and MapReduce" .This provides a nice explanation of the core concepts and internal working of hadoop components embedded with quizzes around each concept and some good handson exercies.They also provide VM for training purpose, which can be used to run example questions and to solve quizzes and exams for the courses.

Goals -

  • How Hadoop fits into the world (recognize the problems it solves)
  • Understand the concepts of HDFS and MapReduce (find out how it solves the problems)
  • Write MapReduce programs (see how we solve the problems)
  • Practice solving problems on your own

Prerequisites -

Some basic programming knowledge and a good interest in learning :)

2. Introduction to Mapreduce Programming

3. Moving Data in to Hadoop

Monday, October 28, 2013

Hadoop Shell Commands



Hadoop-hdfs-post


mkdir



Create directory in the given path:



hadoop fs -mkdir <paths>


Example : hadoop fs -mkdir  /user/saurzcode/dir1




ls



List the file for the given path:




hadoop fs -ls <args>


Example: hadoop fs -ls /user/saurzcode

lsr



Similar to lsr in Unix shell.




hadoop fs -lsr <args>


Ex: hadoop fs -lsr /user/saurzcode


touchz



Creates file in the given path:



hadoop fs -touchz <path[filename]>


Ex: hadoop fs -touchz /user/saurzcode/dir1/abc.txt


cat



Same as unix cat command:



hadoop fs -cat <path[filename]>


Ex: hadoop fs -cat /user/saurzcode/dir1/abc.txt

cp


Copy files from source to destination. This command allows multiple sources as well in which case the destination must be a directory.



hadoop fs -cp <source> <dest>


Ex: hadoop fs -cp /user/saurzcode/dir1/abc.txt /user/saurzcode/dir2

put




Copy single src, or multiple srcs from local file system to the destination filesystem. Also reads input from stdin and writes to destination filesystem.


hadoop fs -put <source:localFile> <destination>


Ex: hadoop fs -put /home/hduser/def.txt  /user/saurzcode/dir1

get



Copy files to the local file system


hadoop fs -get  <source> <dest:localFileSystem>


Ex: hadoop fs -get /user/saurzcode/dir1 /home/hduser/def.txt

copyFromLocal


Similar to put except that the source is limited to local files.



hadoop fs -copyFromLocal <src:localFileSystem> <dest:Hdfs>


Ex: hadoop fs -put /home/hduser/def.txt  /user/saurzcode/dir1

copyToLocal


Similar to get except that the destination is limited to local files.



hadoop fs -copyToLocal <src:Hdfs> <dest:localFileSystem>


Ex: hadoop fs -get /user/saurzcode/dir1 /home/hduser/def.txt

mv


Move file from source to destination. Except moving files across filesystem is not permitted.


hadoop fs -mv <src> <dest>


Ex: hadoop fs -mv /user/saurzcode/dir1/abc.txt /user/saurzcode/dir2

rm


Remove files specified as argument. Deletes directory only when it is empty


hadoop fs -rm <arg>


Ex: hadoop fs -rm /user/saurzcode/dir1/abc.txt

rmr


Recursive version of delete.


hadoop fs -rmr <arg>


Ex: hadoop fs -rmr /user/saurzcode/

stat


Retruns the stat inofrmation on the path.


hadoop fs -stat <path>


Ex: hadoop fs -stat /user/saurzcode/dir1

tail


Similar to tail in Unix Command.


hadoop fs -tail <path[filename]>


Ex: hadoop fs -tail /user/saurzcode/dir1/abc.txt

test


Test comes with the following options:
-e check to see if the file exists. Return 0 if true.
-z check to see if the file is zero length. Return 0 if true
-d check return 1 if the path is directory else return 0.



hadoop fs -test -[ezd]<path>


Ex: hadoop fs -test -e /user/saurzcode/dir1/abc.txt

text


Takes a source file and outputs the file in text format. The allowed formats are zip and TextRecordInputStream.




hadoop fs -text <src>


Ex: hadoop fs -text /user/saurzcode/dir1/abc.txt

du


Display the aggregate length of a file.


hadoop fs -du <path>


Ex: hadoop fs -du /user/saurzcode/dir1/abc.txt

dus


Displays the summary of a file length.


hadoop fs -dus <args>


Ex: hadoop fs -dus /user/saurzcode/dir1/abc.txt

expung


Empty the trash.


hadoop fs -expunge


chgrp


Change group association of files. With -R, make the change recursively through the directory structure. The user must be the owner of files, or else a super-user.


hadoop fs -chgrp [-R] GROUP <path>


chmod


Change the permissions of files. With -R, make the change recursively through the directory structure. The user must be the owner of the file, or else a super-user.


hadoop fs -chmod [-R] <MODE[,MODE]  | OCTALMODE> <path>


chown


Change the owner of files. With -R, make the change recursively through the directory structure. The user must be a super-user.


hadoop fs -chown [-R] [OWNER][:[GROUP]] <path>


getmerge


Takes a source directory and a destination file as input and concatenates files in src into the destination local file. Optionally addnl can be set to enable adding a newline character at the end of each file.


hadoop fs -getmerge <src> <localdst> [addnl]


setrep


Changes the replication factor of a file. -R option is for recursively increasing the replication factor of files within a directory.


hadoop fs -setrep [-R] <path>

[polldaddy poll=7511631]