Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
courses:mapreduce-tutorial:step-27 [2012/01/28 18:45] straka |
courses:mapreduce-tutorial:step-27 [2012/01/31 14:39] (current) straka |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== MapReduce Tutorial : Custom data types ====== | + | ====== MapReduce Tutorial : Running multiple Hadoop jobs in one source file ====== |
| - | An important feature of the Java API is that custom data and format types can be provided. In this step we implement two custom data types. | + | The Java API offers possibility to submit multiple Hadoop job in one source file. A job can be submitted either using |
| + | * [[http:// | ||
| + | * [[http:// | ||
| - | ===== BERIntWritable | + | ===== Exercise 1 ===== |
| + | Improve the [[.: | ||
| - | We want to implement BERIntWritable, | + | ===== Exercise 2 ===== |
| - | The new class must implement | + | Implement |
| - | <code java> | ||
| - | public class BERIntWritable implements Writable { | ||
| - | private int value; | ||
| - | public void readFields(DataInput in) throws IOException { | + | ---- |
| - | value = 0; | + | |
| - | byte next; | + | < |
| - | while (((next | + | <table style=" |
| - | value = (value | + | <tr> |
| - | } | + | <td style=" |
| - | value = (value | + | <td style=" |
| - | } | + | <td style=" |
| - | + | </tr> | |
| - | public void write(DataOutput out) throws IOException { | + | </table> |
| - | int highest_pos | + | </html> |
| - | while (highest_pos | + | |
| - | while (highest_pos > 0) { | + | |
| - | out.writeByte(0x80 | + | |
| - | | + | |
| - | } | + | |
| - | out.writeByte(value & 0x7F); | + | |
| - | } | + | |
| - | </code> | + | |
| - | Accessory methods '' | + | |
| - | <code java> | + | |
| - | | + | |
| - | public void set(int value) { this.value | + | |
| - | public String toString() { return String.valueOf(value); } | + | |
| - | } | + | |
| - | </code> | + | |
| - | + | ||
| - | Such implementation can be used as a type of //values//. If we wanted to use it as a type of //keys//, we need to implement | + | |
| - | <code java> | + | |
| - | public class BERIntWritable implements WritableComparable { | + | |
| - | ... //Same as before | + | |
| - | + | ||
| - | public int compareTo(Object other) { | + | |
| - | int otherValue = ((BERIntWritable)other).get(); | + | |
| - | | + | |
| - | } | + | |
| - | } | + | |
| - | </code> | + | |
| - | + | ||
| - | ===== PairWritable<A, B> ===== | + | |
