Pig Data flow language (abstraction for MR jobs)

Slides:



Advertisements
Similar presentations
Hui Li Pig Tutorial Hui Li Some material adapted from slides by Adam Kawa the 3rd meeting of WHUG June 21, 2012.
Advertisements

Hadoop Pig By Ravikrishna Adepu.
CS525: Special Topics in DBs Large-Scale Data Management MapReduce High-Level Langauges Spring 2013 WPI, Mohamed Eltabakh 1.
© Hortonworks Inc Daniel Dai Thejas Nair Page 1 Making Pig Fly Optimizing Data Processing on Hadoop.
Working with pig Cloud computing lecture. Purpose  Get familiar with the pig environment  Advanced features  Walk though some examples.
High Level Language: Pig Latin Hui Li Judy Qiu Some material adapted from slides by Adam Kawa the 3 rd meeting of WHUG June 21, 2012.
CC P ROCESAMIENTO M ASIVO DE D ATOS O TOÑO 2014 Aidan Hogan Lecture VII: 2014/04/21.
Pig Latin: A Not-So-Foreign Language for Data Processing Christopher Olsten, Benjamin Reed, Utkarsh Srivastava, Ravi Kumar, Andrew Tomkins Acknowledgement.
Design of Pig B. Ramamurthy. Pig’s data model Scalar types: int, long, float (early versions, recently float has been dropped), double, chararray, bytearray.
(Hadoop) Pig Dataflow Language B. Ramamurthy Based on Cloudera’s tutorials and Apache’s Pig Manual 6/27/2015.
CS525: Big Data Analytics MapReduce Languages Fall 2013 Elke A. Rundensteiner 1.
Hive: A data warehouse on Hadoop Based on Facebook Team’s paperon Facebook Team’s paper 8/18/20151.
HADOOP ADMIN: Session -2
USING HADOOP & HBASE TO BUILD CONTENT RELEVANCE & PERSONALIZATION Tools to build your big data application Ameya Kanitkar.
Pig: Making Hadoop Easy Wednesday, June 10, 2009 Santa Clara Marriott.
Introduction to database systems
Big Data Analytics Training
Introduction to Hadoop and HDFS
Hive Facebook 2009.
Making Hadoop Easy pig
Storage and Analysis of Tera-scale Data : 2 of Database Class 11/24/09
MapReduce High-Level Languages Spring 2014 WPI, Mohamed Eltabakh 1.
An Introduction to HDInsight June 27 th,
Presented by Priagung Khusumanegara Prof. Kyungbaek Kim
Large scale IP filtering using Apache Pig and case study Kaushik Chandrasekaran Nabeel Akheel.
Large scale IP filtering using Apache Pig and case study Kaushik Chandrasekaran Nabeel Akheel.
MAP-REDUCE ABSTRACTIONS 1. Abstractions On Top Of Hadoop We’ve decomposed some algorithms into a map-reduce “workflow” (series of map-reduce steps) –
Design of Pig B. Ramamurthy. Pig’s data model Scalar types: int, long, float (early versions, recently float has been dropped), double, chararray, bytearray.
Apache PIG rev Tools for Data Analysis with Hadoop Hadoop HDFS MapReduce Pig Statistical Software Hive.
What is Pig ???. Why Pig ??? MapReduce is difficult to program. It only has two phases. Put the logic at the phase. Too many lines of code even for simple.
Data Cleansing with Pig Latin. Neubot Tests Data Structure.
MapReduce Compilers-Apache Pig
CS 405G: Introduction to Database Systems
Mail call Us: / / Hadoop Training Sathya technologies is one of the best Software Training Institute.
Advanced Computer Systems
Pig, Making Hadoop Easy Alan F. Gates Yahoo!.
Hadoop.
Unit 5 Working with pig.
HADOOP ADMIN: Session -2
INTRODUCTION TO PIG, HIVE, HBASE and ZOOKEEPER
MSBIC Hadoop Series Processing Data with Pig
SOFTWARE DESIGN AND ARCHITECTURE
Design of Pig B. Ramamurthy.
Spark Presentation.
Hive Mr. Sriram
SQOOP.
NOSQL databases and Big Data Storage Systems
Overview of Hadoop MapReduce MapReduce is a soft work framework for easily writing applications which process vast amounts of.
Pig Latin - A Not-So-Foreign Language for Data Processing
Pig Data flow language (abstraction for MR jobs)
Introduction to PIG, HIVE, HBASE & ZOOKEEPER
Server & Tools Business
Slides borrowed from Adam Shook
Overview of big data tools
Pig from Alan Gates’ book (In preparation for exam2)
The Idea of Pig Or Pig Concepts
Pig - Hive - HBase - Zookeeper
CSE 491/891 Lecture 21 (Pig).
Pig Data flow language (abstraction for MR jobs)
Smart Integration Express
CSE 491/891 Lecture 24 (Hive).
A QUICK START TO OPL IBM ILOG OPL V6.3 > Starting Kit >
Charles Tappert Seidenberg School of CSIS, Pace University
Cloud Computing for Data Analysis Pig|Hive|Hbase|Zookeeper
(Hadoop) Pig Dataflow Language
Hadoop – PIG.
(Hadoop) Pig Dataflow Language
04 | Processing Big Data with Pig
Big Data Technology: Introduction to Hadoop
Pig Hive HBase Zookeeper
Presentation transcript:

Pig Data flow language (abstraction for MR jobs) B. Ramamurthy 9/17/2018

Abstraction layer for MR Raw MR is difficult to install and program (Do we know about this? Then why did I ask you do this?) There are many models that simplify designing MR applications: MR made easy from Google App Engine MRJob for python developers Elastic Map Reduce (EMR) from amazon aws Pig from Apache via Yahoo Hive from Apache via Facebook And others We will look at Pig in detail.. It is data flow language, so conceptually closer to the way we solve problems… 9/17/2018

References http://chimera.labs.oreilly.com/tags/featured The new learning environment from O’Reilly Lots of books free for online reading. Pig is also available: search for it on the site mentioned above. 9/17/2018

What is Pig?: example Pig is a scripting language that helps in designing big data solutions using high level primitives. Pig script can be executed locally; it is typically translated into MR job/task workflow and executed on Hadoop Pig itself is a MR job on Hadoop You can access local file system using pig –x local (eg. file:/…) Other file system accessible are hdfs:// and s3:// from grunt> of non-local pig You can transfer data into local file system from s3: hadoop dfs –copyToLocal s3n://cse487/pig1/ps5.pig /home/hadoop/pig1/ps5.pig hadoop dfs –copyToLocal s3n://cse487/pig1/data2 /home/hadoop/pig1/data2 Then run ps5.pig in the local mode pig –x local run ps5.pig 9/17/2018

9/17/2018

Simple pig scripts: wordcount A = load 'data2' as (line); words = foreach A generate flatten(TOKENIZE(line)) as word; grpd = group words by word; cntd = foreach grpd generate group, COUNT(words); store cntd into 'pig1out'; 9/17/2018

Sample Pig script: simple data analysis 2 4 5 -2 3 4 3 5 6 -4 5 7 -7 4 6 4 5 A = LOAD 'data3' AS (x,y,z); B = FILTER A by x> 0; C = GROUP B BY x; D = FOREACH C GENERATE group,COUNT(B); STORE D INTO 'p6out'; 9/17/2018

See the pattern? LOAD FILTER GROUP GENERATE (apply some function from piggybank) STORE (DUMP for interactive debugging) 9/17/2018

Pig Latin Is the language pig script is written in. Is a parallel data flow language Mathematically pig latin describes a directed acyclic graph (DAG) where edges are data flow and the nodes are operators that process data It is data flow not control flow language: no if statements and for loops! (traditional OO programming describes control flow not data flow.) 9/17/2018

Pig and query language How about Pig and SQL? SQL describes “what” or what is the user’s question and it does NOT describes how it is to be solved. SQL is built around answering one question: lots of subqueries and temporary tables resulting in one thing: inverted process remember from our earlier discussions if these temp table are NOT in-memory their random access is expensive Pig describes the data pipeline from first step to final step. HDFS vs RDBMS Tables Pig vs Hive Yahoo vs Facebook 9/17/2018

SQL (vs. Pig) CREATE TEMP TABLE t1 AS SELECT customer, sum(purchase) AS total_purchases FROM transactions GROUP BY customer; SELECT customer, total_purchases,zipcode FROM t1, customer_profile WHERE t1.customer = customer_profile.customer; 9/17/2018

(SQL vs.) Pig txns = load ‘transactions’ as (customer, purchase) grouped = group txns customer; total = foreach grouped generate group, SUM(txns.purchase) as tp; profile = load ‘customer_profile’ as (customer, zipcode); answer = join total by group, profile by customer; dump answer; 9/17/2018

Pig and HDFS and MR Pig does not require HDFS. Pig can run on any file system as long as you transfer the data flow and the data appropriately. This is great since you can use not just file:// or hdfs:// but also other systems to be developed in the future. Similarly Pig Latin has several advantages over MR (see chapter 1 Programming Pig book) during the conceptual phase.. For later execution on MR 9/17/2018

Uses of Pig Traditional Extract, Transform, Load (ETL) data pipelines Research on raw data Iterative processing Prototyping (debugging) on small data and local system before launching a big data, multi-node MR jobs Good for EDA!! Largest use case: data pipelines: raw data , cleanse, load into data warehouse Ad-hoc queries from data where the scheme is unknown What it is not good for? For workloads that will update a few records, the will look up data in some random order, Pig is not a good choice. In 2009, 50% yahoo! Jobs executed were using Pig. Lets execute some Pig scripts on local installation and then on amazon installation. 9/17/2018

Apache Pig Apache Pig is a platform for analyzing large data sets that consists of a high-level language for expressing data analysis programs, coupled with infrastructure for evaluating these programs. Pig's infrastructure layer consists of a compiler that produces sequences of Map-Reduce programs, Pig's language layer currently consists of a textual language called Pig Latin, which has the following key properties: Ease of programming. It is trivial to achieve parallel execution of simple, "embarrassingly parallel" data analysis tasks. Complex tasks comprised of multiple interrelated data transformations are explicitly encoded as data flow sequences, making them easy to write, understand, and maintain. Optimization opportunities. The way in which tasks are encoded permits the system to optimize their execution automatically, allowing the user to focus on semantics rather than efficiency. Extensibility. Users can create their own functions to do special-purpose processing. 9/17/2018

Running Pig You can execute Pig Latin statements: Using grunt shell or command line $ pig ... - Connecting to ... grunt> A = load 'data'; grunt> B = ... ; In local mode or hadoop mapreduce mode $ pig myscript.pig Command Line - batch, local mode mode $ pig -x local myscript.pig Either interactively or in batch 9/17/2018

Program/flow organization A LOAD statement reads data from the file system. A series of "transformation" statements process the data. A STORE statement writes output to the file system; or, a DUMP statement displays output to the screen. 9/17/2018

Interpretation In general, Pig processes Pig Latin statements as follows: First, Pig validates the syntax and semantics of all statements. Next, if Pig encounters a DUMP or STORE, Pig will execute the statements. A = LOAD 'student' USING PigStorage() AS (name:chararray, age:int, gpa:float); B = FOREACH A GENERATE name; DUMP B; (John) (Mary) (Bill) (Joe) Store operator will store it in a file 9/17/2018

Simple Examples A = LOAD 'input' AS (x, y, z); B = FILTER A BY x > 5; DUMP B; C = FOREACH B GENERATE y, z; STORE C INTO 'output'; ----------------------------------------------------------------------------- STORE B INTO 'output1'; STORE C INTO 'output2' 9/17/2018

Lets run Pig Script on AWS See tutorial at http://aws.amazon.com/articles/2729 This is about parsing web log for frequent external referrers, IPs, frequent terms etc. You place the data and pig script on s3 Then start the pig workflow on aws The output also goes back into the s3 space 9/17/2018

Pig Script register file:/home/hadoop/lib/pig/piggybank.jar DEFINE EXTRACT org.apache.pig.piggybank.evaluation.string.EXTRACT(); RAW_LOGS = LOAD '$INPUT' USING TextLoader as (line:chararray); LOGS_BASE = foreach RAW_LOGS generate FLATTEN ( EXTRACT (line, '^(\\S+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] "(.+?)" (\\S+) (\\S+) "([^"]*)" "([^"]*)"') ) as ( remoteAddr:chararray, remoteLogname:chararray, user:chararray, time:chararray, request:chararray, status:int, bytes_string:chararray, referrer:chararray, browser:chararray ; REFERRER_ONLY = FOREACH LOGS_BASE GENERATE referrer; FILTERED = FILTER REFERRER_ONLY BY referrer matches '.*bing.*' OR referrer matches '.*google.*'; SEARCH_TERMS = FOREACH FILTERED GENERATE FLATTEN(EXTRACT(referrer, '.*[&\\?]q=([^&]+).*')) as terms:chararray; SEARCH_TERMS_FILTERED = FILTER SEARCH_TERMS BY NOT $0 IS NULL; SEARCH_TERMS_COUNT = FOREACH (GROUP SEARCH_TERMS_FILTERED BY $0) GENERATE $0, COUNT($1) as num; SEARCH_TERMS_COUNT_SORTED = LIMIT(ORDER SEARCH_TERMS_COUNT BY num DESC) 50; STORE SEARCH_TERMS_COUNT_SORTED into '$OUTPUT'; 9/17/2018

More examples from Cloudera http://www.cloudera.com/wp-content/uploads/2010/01/IntroToPig.pdf A very nice presentation from Cloudera… Also see Apache’s pig page: http://pig.apache.org/docs/r0.9.1/index.html 9/17/2018

Pig’s data model Scalar types: int, long, float (early versions, recently float has been dropped), double, chararray, bytearray Complex types: Map, Tuple, Bag Map: chararray to any pig element; in fact , this <key> to <value> mapping; map constants [‘name’#’bob’, ‘age’#55] will create a map with two keys name and age, first value is chararray and the second value is an integer. Tuple: is a fixed length ordered collection of Pig data elements. Equivalent to a row in SQL. Order, can refer to elements by field position. (‘bob’, 55) is a tuple with two fields. Bag: unordered collection of tuples. Cannot reference tuple by position. Eg. {(‘bob’,55), (‘sally’,52), (‘john’, 25)} is a bog with 3 tuples; bags may become large and may spill into disk from “in-memory” Null: unknown, data missing; any data element can be null; (In Java it is Null pointers… the meaning is different in Pig) 9/17/2018

Pig schema Very relaxed wrt schema. Scheme is defined at the time you load the data Runtime declaration of schemas is really nice. You can operate without meta data. On the other hand, meta data can be stored in a repository Hcatalog and used. For example JSON format… etc. Gently typed: between Java and Perl at two extremes 9/17/2018

Schema Definition divs = load ‘NYSE_dividends’ as (exchange:chararray, symbol:chararray, date:chararray, dividend:double); Or if you are lazy divs = load ‘NYSE_dividends’ as (exchange, symbol, date, dividend); But what if the data input is really complex? Eg. JSON objects? One can keep a scheme in the HCatalog (apache incubation), a meta data repository for facilitating reading/loading input data in other formats. divs = load ‘mydata’ using HCatLoader(); 9/17/2018

Pig Latin Basics: keywords, relation names, field names; Keywords are not case sensitive but relation and fields names are! User defined functions are also case sensitive Comments /* */ or single line comment – Each processing step results in data Relation name = data operation Field names start with alphabet 9/17/2018

More examples No pig-schema No-schema filter daily = load ‘NYSE_daily’; calcs = foreach daily generate $7/100.0, SUBSTRING($0,0,1), $6-$3); Here – is only numeric on Pig) No-schema filter fltrd = filter daily by $6 > $3; Here > is allowed for numeric, bytearray or chararray.. Pig is going to guess the type! Math (float cast) daily = load ‘NYSE_daily’ as (exchange, symbol, date, open, high:float,low:float, close, volume:int, adj_close); rough = foreach daily generate volume * close; -- will convert to float Thus the free “typing” may result in unintended consequences.. Be aware. Pig is sometimes stupid. For a more in-depth view look at also how “casts” are done in Pig. 9/17/2018

Load (input method) Can easily interface to hbase: read from hbase using clause divs = load ‘NYSE_dividends’ using HBaseStorage(); divs = load ‘NYSE_dividends’ using PigStorage(); divs = load ‘NYSE_dividends’ using PigStorage(,); as clause daily = load ‘NYSE_daily’ as (exchange, symbol, date, open, high,low, close, volume); 9/17/2018

Store & dump Default is PigStorage (it writes as tab separated) store processed into ‘/data/example/processed’; For comma separated use: store processed into ‘/data/example/processed’ using PigStorage(,); Can write into hbase using HBaseStorage(): store ‘processed’ using into HBaseStorage(); Dump for interactive debugging, and prototyping 9/17/2018

Relational operations Allow you to transform by sorting, grouping, joining, projecting and filtering foreach supports as array of expressions: simplest is constants and field references. rough = foreach daily generate volume * close; calcs = foreach daily generate $7/100.0, SUBSTRING($0,0,1), $6-$3); UDF (User Defined Functions) can also be used in expressions Filter operation CMsyms = filter divs by symbol matches ‘CM*’; 9/17/2018

Operations (cntd) Group operation collects together records with the same key. grpd = group daily by stock; -- output is <key, bag> counts = foreach grpd generate group, COUNT(daily); Can also group by multiple keys grpd = group daily by (stock, exchange); Group forces the “reduce” phase of MR Pig offers mechanism for addressing data skew and unbalanced use of reducers (we will not worry about this now) Order by: strict ordering Maps, tuples, bags 9/17/2018