title: Hadoop map-reduce : Order of records while grouping
body: <p>I have a record in each line of input and each record has around 10 fields. First, I group the records by three fields <code>(field1, field2, field3)</code> thus one mapper/reducer is responsible for one unique group (based on the three fields). Within each group, I sort the records based on another integer field <code>timestamp</code> and I tag each record in the group with the same tag <code>aTag</code> by adding another field.</p>
  
  <p>Lets say that in mapper#1, I tag a sorted group as <code>aTag</code> and in mapper#2, I tag another group (a different group because I initially grouped the records based on the three fields) with the same tag <code>aTag</code>.</p>
  
  <p>Now, if I group the records based on the tag field (i.e., grouping the groups in different mappers), I notice that the ordering within each group is no more preserved. I was expecting that since each mapper has a group with all records having the same tag, grouping by the tag name should just involve getting the relevant groups from other mappers and just concatenating them without re-ordering each individual group.</p>
  
  <p>Is it because I am trying to store the records in gzip format and hence it tries to re-order the records for better compression? Also I would like to know how to preserve the order after grouping by the tag name. </p>