diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 2c358bbb9fb..8623a3eaf4a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -19,6 +19,9 @@ Release 2.8.0 - UNRELEASED IMPROVEMENTS + HADOOP-6842. "hadoop fs -text" does not give a useful text representation + of MapWritable objects (Akira Ajisaka via bobby) + HADOOP-11719. [Fsshell] Remove bin/hadoop reference from GenericOptionsParser default help text. diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/MapWritable.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/MapWritable.java index fec168b831e..0379ec2225e 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/MapWritable.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/MapWritable.java @@ -189,4 +189,9 @@ public class MapWritable extends AbstractMapWritable instance.put(key, value); } } + + @Override + public String toString() { + return instance.toString(); + } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestMapWritable.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestMapWritable.java index 92849494eac..4597b909d95 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestMapWritable.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestMapWritable.java @@ -148,5 +148,14 @@ public class TestMapWritable extends TestCase { assertEquals(map1.hashCode(), map2.hashCode()); assertFalse(map1.hashCode() == map3.hashCode()); -} + } + + /** Verify text command outputs a useful representation for MapWritable. */ + public void testToString() { + MapWritable map = new MapWritable(); + final IntWritable key = new IntWritable(5); + final Text value = new Text("value"); + map.put(key, value); + assertEquals("{5=value}", map.toString()); + } }