



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































In Java/Python In Pig+Java Today, we'll start with Pig Two kinds of Map/Reduce programming Programming Map/Reduce Wednesday, February 23, 2011 3:45 PM Docsity.com
A Map phase in which we do something to each record. A Reduce phase where we combine results. Map/Reduce consists of The Map/Reduce framework does the rest. We only write what to do to each element, and how to combine a list of things. Recall from last time Recall from last time Wednesday, February 23, 2011 3:46 PM Docsity.com
Filter: map selects, reduce combines. Sort: map selects, reduce merge-sorts. Construct: map creates new data, reduce reports what was done. Common Map/Reduce algorithms Common Map/Reduce algorithms Wednesday, February 23, 2011 3:54 PM Docsity.com
No choice on reducer (combine and eliminate duplicates). Very limited map capabilities. You might have noticed that there are severe limits on what you can do with MapReduce directly inside AppEngine: If you write a mapper, it has to be propogated to each map node. This is moving code, not data. This is relatively expensive and somewhat dangerous. Otherwise, you cannot inject code into the cloud. This has security and other implications. Why? Understanding limits of AppEngine MapReduce Tuesday, February 22, 2011 11:46 AM Docsity.com
Map and Reduce are pre-coded. There is no need to propogate code. Google MR is fast because Must propogate jarfile for Map, Combine, Reduce classes to each Hadoop node. Up to 30 seconds for a large array. So, basically no one uses it for real time queries. Hadoop MR has a very slow startup time because Myths and Realities of MR Myths and Realities of MR Tuesday, February 22, 2011 12:26 PM Docsity.com
Often, can compute and pre-store results of commonly needed queries. These run much faster on Hadoop than serially. Then we query the results normally. So, what is Hadoop MR good for? So, what is Hadoop MR good for? Tuesday, February 22, 2011 12:29 PM Docsity.com
A data restructuring subsystem of Hadoop Input is a database. Output is a table. SQL is intended for queries. Input is a set of distributed files. Output is another distributed file. Pig Latin is intended for restructuring data. With its own language Pig Latin with SQL-like syntax. But Pig Pig Tuesday, February 22, 2011 12:30 PM Docsity.com
In local mode , filenames refer to local files. In MapReduce mode , flenames refer to distributed (HDFS) files. Pig runs in two modes: We'll run in local mode for now, but We'll imagine running in MapReduce mode, and Our programs will be identical in either case. Local and MapReduce mode Tuesday, February 22, 2011 3:23 PM Docsity.com
Register the tutorial JAR file so that the included user-defined functions can be called in the script.
REGISTER ./tutorial.jar; Use the FILTER-BY construction to call the NonURLDetector user-defined function (Java class in tutorial.jar) to remove records if the query field is empty or a URL.
raw = LOAD 'excite.log' USING PigStorage('\t') AS (user, time, query);
clean2 = FOREACH clean1 GENERATE user, time, org.apache.pig.tutorial.ToLower(query) as query; Call the NGramGenerator user-defined function to compose the n-grams of the query.
houred = FOREACH clean2 GENERATE user, org.apache.pig.tutorial.ExtractHour(time) as hour, query;
hour_frequency2 = FOREACH hour_frequency1 GENERATE flatten($0), COUNT($1) as count; For each group, identify the hour in which this n-gram is used with a particularly high frequency. Call the ScoreGenerator user-defined function to calculate a "popularity" score for the n-gram.
uniq_frequency1 = GROUP hour_frequency2 BY group::ngram; uniq_frequency2 = FOREACH uniq_frequency1 GENERATE flatten($0), flatten(org.apache.pig.tutorial.ScoreGenerator($1)); Pig example 1: determine frequency of common search phrases from a webserver logfile. Tuesday, February 22, 2011 12:36 PM Docsity.com
uniq_frequency3 = FOREACH uniq_frequency2 GENERATE $1 as hour, $0 as ngram, $ as score, $3 as count, $4 as mean;
ordered_uniq_frequency = ORDER filtered_uniq_frequency BY (hour, score); STORE ordered_uniq_frequency INTO '/tmp/tutorial-results' USING PigStorage(); Pasted from Docsity.com
Make every class in the jarfile available on the command line. (Note: only static functions are available, not methods.) (Try doing this in SQL!) REGISTER ./something.jar The REGISTER command The REGISTER command Tuesday, February 22, 2011 12:56 PM Docsity.com
A field is a piece of data. e.g. (f1,f2,f3). A tuple is a sequence of 1 or more fields in parentheses, A bag is a set of tuples, e.g., {(1,2),(4,5,6)} An outer bag can be referred to by a top-level alias. An inner bag doesn't have an alias. A relation is an outer bag. Data types in Pig: Data types in Pig Tuesday, February 22, 2011 3:45 PM Docsity.com
What Pig does "could be" done by SQL. But it would be incredibly complex SQL. Aliases allow us to write a Pig command in pieces. The result is still one huge (unreadable) command that gets executed, in the end. Aliases and SQL Aliases and SQL Wednesday, February 23, 2011 11:08 AM Docsity.com
prints a relation's contents as text, after computing it. DUMP __ ; prints its schema (metadata). DESCRIBE __ ; prints an explanation of what Pig will do to get it. EXPLAIN __ ; prints a sample run with a subset of data. ILLUSTRATE __ ; Debugging in pig Debugging in pig Tuesday, February 22, 2011 6:01 PM Docsity.com