














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!















We understand what Pig is for. We have a basic knowledge of the primitives. Now it's time to do something non-trivial with it. So far, So far, Wednesday, February 23, 2011 7:06 PM Docsity.com
filter and order records (without changing the schema): FOREACH-GENERATE, GROUP-BY, JOIN-BY … or transform data schemas: Pig actions can either (…) is a tuple {…} is a bag of tuples a:int is an element named a that is an int. Reading a schema: remember that foo: {a:int, b:chararray} So the schema bar: {a:int, b:{c:int, d:chararray}} refers to an alias foo that generates a tuple space (outer bag) of tuples where the first term is an int and the second term is a chararray (string). while the schema refers to an alias bar that generates a tuple space (outer bag) of tuples, where each tuple has a first term that is an int and a second term that is a bag of two-tuples. You can print schemas with the DESCRIBE command. Pig actions as transformations Thursday, February 24, 2011 1:33 PM Docsity.com
...to that man behind the curtain. Much of the power of Pig comes from user-defined functions (UDFs). In fact, as a user of much more powerful functional programming systems, I think Pig has remarkably few builtin functions (and I miss some of the builtins in FP) For this lecture, I will concentrate on the power of Pig itself, So I will start with data that has already been massaged by UDFs into an appropriate form. Don't pay attention… Don't pay attention… Thursday, February 24, 2011 10:17 AM Docsity.com
"There is always another way to do it." In Perl, we say "There is always an easier way to do it." In Pig, I have learned A general caveat My first conception of how to solve each of the following problems was extremely inefficient , and only by changing my entire approach could I unleash the power of Pig. … even though I am expert in traditional dataflow and functional programming… Pig programs are really short, but if you get on the wrong track , expect to throw the entire program away. You have been warned! So, A general caveat Thursday, February 24, 2011 10:25 AM Docsity.com
Social flow analysis: co-location/correlation of blog posts/tweets/facebook posts about specific products or services. Incident detection: reporting security incidents through correlation between security log entries. A few typical Pig applications A few typical Pig applications Thursday, February 24, 2011 10:27 AM Docsity.com
Input: a set of post events in social networks. Output: a list of times at which there are flurries of activity around specific topics. Detecting social buzz Detecting social buzz Thursday, February 24, 2011 12:15 PM Docsity.com
Our schema is now posts: {time:long, user:chararray, topic:chararray, opinion:chararray} let's concentrate on the negative posts: hates = FILTER posts BY topic=='Honda' and opinion=='negative'; and let's remove those fields, because we don't need them now: hate2 = FOREACH hates GENERATE time, user; Our schema is now hate2: {time:long, user:chararray} Initial filtering Thursday, February 24, 2011 12:24 PM Docsity.com
Our schema is now hate2: {time:long, user:chararray} We are interested in "buzz" events, which are negative posts by multiple users at roughly the same time. First, we select a time interval (e.g., one hour=3600 seconds) and create timestamps every hour: clusters = FOREACH posts GENERATE time-time%3600 as time, user; We are only interested in how many distinct users are involved, so cluster2 = DISTINCT clusters; So far, our schema hasn't changed: cluster2: {time:long, user:chararray}; Binning time Thursday, February 24, 2011 12:30 PM Docsity.com
Input: log entries from a set of machines. Output: suspicious behaviors detected. UDF: Parse log entries, select failed password attempts. bot password cracking attack, many source locations, one user, many login failures, distributed in time. Suspicious pattern to detect: Distributed cracking attempts, long time-scale, huge data scale. Very difficult to detect by standard log scanning methods: Security incident detection: Incident detection Thursday, February 24, 2011 10:43 AM Docsity.com
Input data for our Pig program time user action status subnet 2839203081L couch login success 130.64.23/ time is the time of the incident in seconds since Jan 1 1970 00:00:00 GMT (a.k.a. "the epoch") user is the account in question. action is what they did. status is success or failure. subnet is the address block on the internet from which they tried (grouping related addresses together). (In practice, the log would be collected using HDFS!) where We start with something like: AS (time:long, user:chararray, action:chararray, status:chararray, subnet:chararray); log = LOAD 'log' USING MyLogParser() The man behind the curtain… Thursday, February 24, 2011 10:50 AM Docsity.com
Now we have the schema: failure2: {user:chararray, subnet:chararray} But, an incident is specific to one login name, so we group by that: users = GROUP failure2 by user; Now our schema is users: {group: chararray, failure2: {user:chararray, subnet:chararray}} Now we don't need the user in the subsets, so let's project that out: user2 = FOREACH users GENERATE group as user, failure2.subnet as locations; Now our schema is: user2: {user:chararray, locations:{subnet:chararray}} Grouping Thursday, February 24, 2011 11:50 AM Docsity.com
Now our schema is: user2: {user: chararray, locations: {subnet: chararray}} A bot attack is a lot of failed attempts from many different locations. First, quantify "a lot". lots = FILTER user2 by COUNT(locations)>1000; Then quantify how many locations: places = DISTINCT locations; GENERATE user, COUNT(places) as places; user3 = FOREACH user2 { } user4 = FILTER user3 by places>100; Tell the administrator that these users are under attack by bots: DUMP user4; Final filtering Thursday, February 24, 2011 12:13 PM Docsity.com
log::action=='login'; And then strip the joined field off (it's a duplicate), along with the action field (it's redundant now). vulnerable3 = FOREACH vulnerable GENERATE log::time as time, log::user as user, log::status as status, log::subnet as subnet; Now our schema is vulnerable3: {time:long, user:chararray, status:chararray, subnet:chararray} We used the inner join to delete data. Docsity.com
Now our schema is vulnerable3: {time:long, user:chararray, status:chararray, subnet:chararray} Let's filter out subnets from which the user regularly logs in correctly. Let's make a whitelist. correct = FILTER vulnerable3 BY status=='success'; correct2 = FOREACH correct GENERATE user, subnet; good = GROUP correct2 BY (user,subnet); Now schema is good: {group: (user:chararray, subnet:chararray), correct2: {user:chararray, subnet:chararray}} Let's count the correct logins: whitelist = FOREACH good GENERATE group.user,group.subnet,COUNT(correct2) as count; whitelist2 = FILTER whitelist by counter>100; And throw them out of the log! Determining valid login sites Thursday, February 24, 2011 3:57 PM Docsity.com