# Comp150CPA: Clouds and Power-Aware Computing Classroom Exercise 8 Pig and Data Transformation Spring 2011

### group member 5: ____________________________ login: ______________

In class we have studied the Pig language for Map/Reduce and its basic transformations. Let's explore the latter in more detail. Suppose that inside Pig, we have
 ``` grunt> DUMP x; ... Success!! (George,Bear) (Frank,Dog) (George,Bear) (Bill,Cat) (Amy,Bear) grunt> DESCRIBE x x: {name: chararray, species: chararray} ``` ``` grunt> DUMP y; ... Success!! (Bear,Hugs) (Dog,Barks) (Dog,Growls) (Cat,Purrs) (Bear,Growls) grunt> DESCRIBE y x: {species: chararray, action: chararray} ```

1. What is printed by the following scripts?
1. ```z = FOREACH x GENERATE name,\$0;
DUMP z;
```

```
(George,George)
(Frank,Frank)
(George,George)
(Bill,Bill)
(Amy,Amy)
```
2. ```z = FILTER y BY action=='Growls';
DUMP z;
```

```
(Dog,Growls)
(Bear,Growls)
```
3. ```z = GROUP y by species;
DUMP z;
```

```
(Bear,{(Bear,Hugs),(Bear,Growls)})
(Dog,{(Dog,Barks),(Dog,Growls)})
(Cat,{(Cat,Purrs)})
```
4. ```z = JOIN x BY species,y BY species;
DUMP z;
```

```
(George,Bear,Bear,Hugs)
(George,Bear,Bear,Growls)
(Frank,Dog,Dog,Barks)
(Frank,Dog,Dog,Growls)
(George,Bear,Bear,Hugs)
(George,Bear,Bear,Growls)
(Bill,Cat,Cat,Purrs)
(Amy,Bear,Bear,Hugs)
(Amy,Bear,Bear,Growls)
```
5. ```z = JOIN x BY species,y BY species;
w = FOREACH z GENERATE \$0,\$3;
DUMP w;
```

```