Note that there are some explanatory texts on larger screens.

plurals
  1. POimplement customized rawcomparator
    primarykey
    data
    text
    <p>i need to improve my MR jobs, one thing i think about is implement a customized rawComparator, however my key class have lots of fields as string besides some int fields, i not sure how to parse out the string fields out of the byte[], </p> <p>my key class</p> <pre><code>public GeneralKey { private int day; private int hour; private String type; private String name; .. } </code></pre> <p>my customized rawComparator:</p> <pre><code>public class GeneralKeyComparator extends WritableComparator { private static final Text.Comparator TEXT_COMPARATOR = new Text.Comparator(); protected GeneralKeyComparator() { super(GeneralKey.class); } @Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { int day1 = readInt(b1, s1); int day2 = readInt(b2, s2); int comp = (intDay1 &lt; intDay2) ? -1 : (intDay1 == intDay2) ? 0 : 1; if (0 != comp) { return comp; } int hr1 = readInt(b1, s1+4); int hr2 = readInt(b2, s2+4); comp = (hr1 &lt; hr2) ? -1 : (hr1 == hr2) ? 0 : 1; .... how to compare the String fields here??? return comp; } </code></pre> <p>google around i found people tried this :</p> <pre><code>try { int firstL1 = WritableUtils.decodeVIntSize(b1[s1]) + readInt(b1, s1+8); int firstL2 = WritableUtils.decodeVIntSize(b2[s2]) + readVInt(b2, s2+8); comp = TEXT_COMPARATOR.compare(b1, s1, firstL1, b2, s2, firstL2); } catch (IOException e) { throw new IllegalArgumentException(e); } </code></pre> <p>but i don't understand how this work and don't think it works in my case, anyone can help? thanks</p> <p>added readField() and write() methods here:</p> <pre><code>public void readFields(DataInput input) throws IOException { intDay = input.readInt(); hr = input.readInt(); type = input.readUTF(); name = input.readUTF(); ... } @Override public void write(DataOutput output) throws IOException { output.writeInt(intDay); output.writeInt(hr); output.writeUTF(type); output.writeUTF(name); ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload