Return-Path: X-Original-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-mapreduce-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 002AF1010A for ; Thu, 5 Sep 2013 08:28:48 +0000 (UTC) Received: (qmail 93178 invoked by uid 500); 5 Sep 2013 08:28:40 -0000 Delivered-To: apmail-hadoop-mapreduce-user-archive@hadoop.apache.org Received: (qmail 92989 invoked by uid 500); 5 Sep 2013 08:28:39 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 92566 invoked by uid 99); 5 Sep 2013 08:28:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Sep 2013 08:28:37 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Jan.Lukavsky@firma.seznam.cz designates 77.75.74.246 as permitted sender) Received: from [77.75.74.246] (HELO posta.szn.cz) (77.75.74.246) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Sep 2013 08:28:32 +0000 Received: from [10.0.2.22] (10.0.2.22) by posta.szn.cz (10.0.3.149) with Microsoft SMTP Server (TLS) id 14.3.123.3; Thu, 5 Sep 2013 10:28:10 +0200 Message-ID: <5228409A.5040801@firma.seznam.cz> Date: Thu, 5 Sep 2013 10:28:10 +0200 From: =?ISO-8859-1?Q?Jan_Lukavsk=FD?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 MIME-Version: 1.0 To: Subject: Re: M/R API and Writable semantics in reducer References: <522492C4.80000@firma.seznam.cz> In-Reply-To: <522492C4.80000@firma.seznam.cz> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.0.2.22] X-Virus-Checked: Checked by ClamAV on apache.org Hi, is there anyone interested in this topic? Basically, what I'm trying to find out is, whether it is 'safe' to rely on the side-effect of updating key during iterating values. I believe that there must be someone who is also interested in this, the secondary sort pattern is very common (at least in our jobs). So far, we have been emulating the GroupingComparator by holding state in the Reducer class and therefore being able to keep track of 'groups' of keys among several calls to reduce() method. This method seems quite safe in the sense of API, but in the sense of code is not as pretty (and vulnerable to ugly bugs if you forget to reset the state correctly for instance). On the other hand, if the way key gets updated while iterating the values is to be considered contract of the MapReduce API, I think it should be implemented in MRUnit (or you basically cannot use MRUnit to unittest your job) and if it isn't, than it is probably a bug. If this is internal behavior and might be subject to change anytime, than it clearly seems that keeping the state in Reducer is the only option. Does anyone else have similar considerations? How do others implement the secondary sort? Thanks, Jan On 09/02/2013 03:29 PM, Jan Lukavsk� wrote: > Hi all, > > some time ago, I wrote a note to this conference, that it would be > nice if it would be possible to get the *real* key emitted from mapper > to reducer, when using the GroupingComparator. I got the answer, that > it is possible, because of the Writable semantics and that currently > the following holds: > > @Override > protected void reduce(Key key, Iterable values, Context context) > { > for (Value v : values) { > // The key MIGHT change its value in this cycle, because > readFields() will be called on it. > // When using GroupingComparator that groups only by some part of > the key, > // many different keys might be considered single group, so the > *real* data matters. > } > } > > When you use GroupingComparator the contents of the key can matter, > because if you cannot access it, you have to duplicate the data in > value (which means more network traffic in shuffle phase, and more I/O > generally). > > Now, the question is, how much is this a matter of API that is > reliable, or how much it is likely, that relying on this feature might > break in future versions. To me, it seems more like a side effect, > that is not guaranteed to be maintained in the future. There already > exists a suggestion, that this is probably very fragile, because > MRUnit seems not to update the key during the iteration. > > Does anyone have any suggested way around? Is the 'official' preferred > way of accessing the original key to call context.getCurrentKey()? > Isn't this the same case? Wouldn't it be nice, if the API itself had > some guaranties or suggestions how it works? I can imagine modified > reduce() metod, with a signature like > > protected void reduce(Key key, Iterable> keyValues, > Context context); > > This seems easily transformable to the old call (which could be > default implementation of this method). > > Any opinion on this? > > Thanks, > Jan