From 0eadfcfcf55bbc616cfba36988c78a8d46814624 Mon Sep 17 00:00:00 2001 From: Robert Joseph Evans Date: Mon, 5 Nov 2012 21:52:06 +0000 Subject: [PATCH] MAPREDUCE-4771. KeyFieldBasedPartitioner not partitioning properly when configured (jlowe via bobby) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1405975 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../partition/KeyFieldBasedPartitioner.java | 1 + .../lib/TestKeyFieldBasedPartitioner.java | 23 +++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index e7e7ef12193..644796d4bd8 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -631,6 +631,9 @@ Release 0.23.5 - UNRELEASED MAPREDUCE-4763 repair test TestUmbilicalProtocolWithJobToken (Ivan A. Veselovsky via bobby) + + MAPREDUCE-4771. KeyFieldBasedPartitioner not partitioning properly when + configured (jlowe via bobby) Release 0.23.4 - UNRELEASED diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/partition/KeyFieldBasedPartitioner.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/partition/KeyFieldBasedPartitioner.java index 0927c1a1766..44cb624c5a8 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/partition/KeyFieldBasedPartitioner.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/partition/KeyFieldBasedPartitioner.java @@ -63,6 +63,7 @@ public class KeyFieldBasedPartitioner extends Partitioner public void setConf(Configuration conf) { this.conf = conf; + keyFieldHelper = new KeyFieldHelper(); String keyFieldSeparator = conf.get(MRJobConfig.MAP_OUTPUT_KEY_FIELD_SEPERATOR, "\t"); keyFieldHelper.setKeyFieldSeparator(keyFieldSeparator); diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java index 2ac80d2bba0..02b0507742a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/lib/TestKeyFieldBasedPartitioner.java @@ -17,17 +17,18 @@ */ package org.apache.hadoop.mapred.lib; +import static org.junit.Assert.assertEquals; + import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.JobConf; -import org.apache.hadoop.mapred.lib.KeyFieldBasedPartitioner; +import org.junit.Test; -import junit.framework.TestCase; - -public class TestKeyFieldBasedPartitioner extends TestCase { +public class TestKeyFieldBasedPartitioner { /** * Test is key-field-based partitioned works with empty key. */ + @Test public void testEmptyKey() throws Exception { KeyFieldBasedPartitioner kfbp = new KeyFieldBasedPartitioner(); @@ -37,4 +38,18 @@ public void testEmptyKey() throws Exception { assertEquals("Empty key should map to 0th partition", 0, kfbp.getPartition(new Text(), new Text(), 10)); } + + @Test + public void testMultiConfigure() { + KeyFieldBasedPartitioner kfbp = + new KeyFieldBasedPartitioner(); + JobConf conf = new JobConf(); + conf.set(KeyFieldBasedPartitioner.PARTITIONER_OPTIONS, "-k1,1"); + kfbp.setConf(conf); + Text key = new Text("foo\tbar"); + Text val = new Text("val"); + int partNum = kfbp.getPartition(key, val, 4096); + kfbp.configure(conf); + assertEquals(partNum, kfbp.getPartition(key,val, 4096)); + } } \ No newline at end of file