Return-Path: Delivered-To: apmail-hadoop-core-commits-archive@www.apache.org Received: (qmail 35639 invoked from network); 26 Jun 2009 08:40:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Jun 2009 08:40:59 -0000 Received: (qmail 43605 invoked by uid 500); 26 Jun 2009 08:41:10 -0000 Delivered-To: apmail-hadoop-core-commits-archive@hadoop.apache.org Received: (qmail 43545 invoked by uid 500); 26 Jun 2009 08:41:10 -0000 Mailing-List: contact core-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: core-dev@hadoop.apache.org Delivered-To: mailing list core-commits@hadoop.apache.org Received: (qmail 43523 invoked by uid 99); 26 Jun 2009 08:41:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jun 2009 08:41:10 +0000 X-ASF-Spam-Status: No, hits=-1999.6 required=10.0 tests=ALL_TRUSTED,SUBJECT_FUZZY_TION X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Jun 2009 08:41:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 93C4223888D0; Fri, 26 Jun 2009 08:40:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r788632 - in /hadoop/common/branches/branch-0.20: CHANGES.txt src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedPartitioner.java src/test/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java Date: Fri, 26 Jun 2009 08:40:45 -0000 To: core-commits@hadoop.apache.org From: sharad@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090626084045.93C4223888D0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sharad Date: Fri Jun 26 08:40:45 2009 New Revision: 788632 URL: http://svn.apache.org/viewvc?rev=788632&view=rev Log: MAPREDUCE-2. Fixes a bug in KeyFieldBasedPartitioner in handling empty keys. Contributed by Amar Kamat. Added: hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java Modified: hadoop/common/branches/branch-0.20/CHANGES.txt hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedPartitioner.java Modified: hadoop/common/branches/branch-0.20/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/CHANGES.txt?rev=788632&r1=788631&r2=788632&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.20/CHANGES.txt Fri Jun 26 08:40:45 2009 @@ -144,6 +144,9 @@ lack of quota. Allow quota to be set even if the limit is lower than current consumption. (Boris Shkolnik via rangadi) + MAPREDUCE-2. Fixes a bug in KeyFieldBasedPartitioner in handling empty + keys. (Amar Kamat via sharad) + Release 0.20.0 - 2009-04-15 INCOMPATIBLE CHANGES Modified: hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedPartitioner.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedPartitioner.java?rev=788632&r1=788631&r2=788632&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedPartitioner.java (original) +++ hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedPartitioner.java Fri Jun 26 08:40:45 2009 @@ -76,12 +76,21 @@ throw new RuntimeException("The current system does not " + "support UTF-8 encoding!", e); } + // return 0 if the key is empty + if (keyBytes.length == 0) { + return 0; + } + int []lengthIndicesFirst = keyFieldHelper.getWordLengths(keyBytes, 0, keyBytes.length); int currentHash = 0; for (KeyDescription keySpec : allKeySpecs) { int startChar = keyFieldHelper.getStartOffset(keyBytes, 0, keyBytes.length, lengthIndicesFirst, keySpec); + // no key found! continue + if (startChar < 0) { + continue; + } int endChar = keyFieldHelper.getEndOffset(keyBytes, 0, keyBytes.length, lengthIndicesFirst, keySpec); currentHash = hashCode(keyBytes, startChar, endChar, Added: hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java?rev=788632&view=auto ============================================================================== --- hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java (added) +++ hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java Fri Jun 26 08:40:45 2009 @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.mapred.lib; + +import org.apache.hadoop.io.Text; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapred.lib.KeyFieldBasedPartitioner; + +import junit.framework.TestCase; + +public class TestKeyFieldBasedPartitioner extends TestCase { + + /** + * Test is key-field-based partitioned works with empty key. + */ + public void testEmptyKey() throws Exception { + KeyFieldBasedPartitioner kfbp = + new KeyFieldBasedPartitioner(); + JobConf conf = new JobConf(); + conf.setInt("num.key.fields.for.partition", 10); + kfbp.configure(conf); + assertEquals("Empty key should map to 0th partition", + 0, kfbp.getPartition(new Text(), new Text(), 10)); + } +} \ No newline at end of file