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:46] 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=" |
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | public void write(DataOutput out) throws IOException { | ||
- | int highest_pos = 28; | ||
- | while (highest_pos > 0 && (value & (0x7F << highest_pos)) == 0) highest_pos -= 7; | ||
- | while (highest_pos > 0) { | ||
- | out.writeByte(0x80 | ((value >> highest_pos) & 0x7F)); | ||
- | highest_pos -= 7; | ||
- | } | ||
- | out.writeByte(value & 0x7F); | ||
- | } | ||
- | </ | ||
- | Accessory methods '' | ||
- | <code java> | ||
- | public int get() { return value; } | ||
- | public void set(int value) { this.value = value; } | ||
- | public String toString() { return String.valueOf(value); | ||
- | } | ||
- | </ | ||
- | |||
- | 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 [[http:// | ||
- | <code java> | ||
- | public class BERIntWritable implements WritableComparable { | ||
- | ... //Same as before | ||
- | |||
- | public int compareTo(Object other) { | ||
- | int otherValue = ((BERIntWritable)other).get(); | ||
- | return value < otherValue ? -1 : (value == otherValue ? 0 : 1); | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | ===== PairWritable< | ||
- | |||
- | As another example, we implement a type storing two user-defined '' |