Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I assign sequece number to the records in reducer
    primarykey
    data
    text
    <p>I wish to assign a sequence number to the events coming from the Mapper class based on the time the events happened.</p> <p>For example, I have 100 events which have a time in them. I wish to sort them based on the time and then in the reducer phase assign a sequence number to them. Also, remove the duplicate records in the reducer phase if they are duplicate (Same events happening at the same time).</p> <p>Mapper method:</p> <pre><code>public class EventMapper extends Mapper&lt;LongWritable, Text, Text, Event&gt; { public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String line = value.toString(); Text newKey; Event e = new Event(); e.setAllValues(line); newKey = new Text(e.getKey()); context.write(newKey, e); } } </code></pre> <p>Reducer Method (Something what I wish for):</p> <pre><code>public class EventReducer extends Reducer&lt;Text, Event, Text, Text&gt; { public void reduce(Text key, Iterator&lt;Event&gt; itrtr, Context context) throws IOException, InterruptedException { Event e; List&lt;Event&gt; l = new ArrayList&lt;Event&gt;(); while(itrtr.hasNext()){ e = itrtr.next(); l.add(e); } Collections.sort(l); long i = 1; for (Event event : l) { event.setId(++i); context.write(key, new Text(event.toString())); } } } </code></pre> <p>I get all the ids as 0. How can I achieve this? Am I following a wrong approach.</p> <p>Here is the Event class:</p> <pre><code>public class Event implements Writable, WritableComparable&lt;Event&gt; { //Some variables and getter + setters @Override public String toString() { String delimiter1 = "|"; return this.date + delimiter1 + this.evName + delimiter1 + this.evType + delimiter1 + this.evValue + delimiter1 + this.name + delimiter1 + this.id; } @Override public void readFields(DataInput in) throws IOException { try { this.date = converStringToDate((WritableUtils.readString(in)).toString(), dateFormat); } catch (ParseException ex) { System.out.println("Wront date . Pe"); } this.evName = WritableUtils.readString(in); this.evType = WritableUtils.readString(in); this.evValue = WritableUtils.readString(in); this.name = WritableUtils.readString(in); this.id = WritableUtils.readVLong(in); } @Override public void write(DataOutput out) throws IOException { // TODO Auto-generated method stub WritableUtils.writeString(out, this.convertDateToString(date)); WritableUtils.writeString(out, evName); WritableUtils.writeString(out, evType); WritableUtils.writeString(out, evValue); WritableUtils.writeString(out, name); WritableUtils.writeVLong(out, id); } public int compareTo(Event o) { long value = this.getDate().getTime() - o.getDate().getTime(); if (value == 0) { return 0; } else if (value &gt; 1) { return -1; } else { return 1; } } public void setAllValues(String input) { String[] arrValues = input.split(delimiter); System.out.println("No of Values = " + arrValues.length); try { this.date = converStringToDate(arrValues[0], dateFormat); } catch (ParseException pe) { System.out.println("pe&gt; Error in date"); } if (arrValues.length &gt;= 2) { this.evName = arrValues[1]; } if (arrValues.length &gt;= 3) { this.evType = arrValues[2]; } if (arrValues.length &gt;= 4) { this.evValue = arrValues[3]; } if (arrValues.length &gt;= 5) { this.name = arrValues[4]; } } public String getKey() { //return convertDateToString(this.date) + this.evName + this.evType; return this.evName; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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