From aa05ad1291130919383455d39a7b3679c7b636d6 Mon Sep 17 00:00:00 2001 From: stack Date: Thu, 4 Sep 2014 21:25:54 -0700 Subject: [PATCH] HBASE-11877 Make TableSplit more readable (Liu Shaohui) --- .../hadoop/hbase/mapred/TableSplit.java | 10 ++++++++-- .../hadoop/hbase/mapreduce/TableSplit.java | 11 ++++++++-- .../hadoop/hbase/mapred/TestSplitTable.java | 20 +++++++++++++++++++ .../hbase/mapreduce/TestTableSplit.java | 16 +++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java index b3c8b82aab9..8a1beee430b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapred/TableSplit.java @@ -119,8 +119,14 @@ public class TableSplit implements InputSplit, Comparable { @Override public String toString() { - return m_regionLocation + ":" + - Bytes.toStringBinary(m_startRow) + "," + Bytes.toStringBinary(m_endRow); + StringBuilder sb = new StringBuilder(); + sb.append("HBase table split("); + sb.append("table name: ").append(m_tableName); + sb.append(", start row: ").append(Bytes.toStringBinary(m_startRow)); + sb.append(", end row: ").append(Bytes.toStringBinary(m_endRow)); + sb.append(", region location: ").append(m_regionLocation); + sb.append(")"); + return sb.toString(); } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableSplit.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableSplit.java index 5e3aeef7f1a..b43e870ed5d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableSplit.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/TableSplit.java @@ -314,8 +314,15 @@ implements Writable, Comparable { */ @Override public String toString() { - return regionLocation + ":" + - Bytes.toStringBinary(startRow) + "," + Bytes.toStringBinary(endRow); + StringBuilder sb = new StringBuilder(); + sb.append("HBase table split("); + sb.append("table name: ").append(tableName); + sb.append(", scan: ").append(scan); + sb.append(", start row: ").append(Bytes.toStringBinary(startRow)); + sb.append(", end row: ").append(Bytes.toStringBinary(endRow)); + sb.append(", region location: ").append(regionLocation); + sb.append(")"); + return sb.toString(); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java index 86f62723d85..d60a5e7edc2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapred/TestSplitTable.java @@ -23,7 +23,9 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import org.apache.hadoop.hbase.SmallTests; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -88,4 +90,22 @@ public class TestSplitTable { assertEquals(tablesplit.hashCode(), same.hashCode()); assertEquals(tablesplit, same); } + + @Test + @SuppressWarnings("deprecation") + public void testToString() { + TableSplit split = + new TableSplit(TableName.valueOf("table"), "row-start".getBytes(), "row-end".getBytes(), + "location"); + String str = + "HBase table split(table name: table, start row: row-start, " + + "end row: row-end, region location: location)"; + Assert.assertEquals(str, split.toString()); + + split = new TableSplit((TableName) null, null, null, null); + str = + "HBase table split(table name: null, start row: null, " + + "end row: null, region location: null)"; + Assert.assertEquals(str, split.toString()); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableSplit.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableSplit.java index 9daef9a0152..e40c5fcf4cc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableSplit.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestTableSplit.java @@ -85,5 +85,21 @@ public class TestTableSplit { Assert.assertEquals(666, deserialized.getLength()); } + @Test + public void testToString() { + TableSplit split = + new TableSplit(TableName.valueOf("table"), "row-start".getBytes(), "row-end".getBytes(), + "location"); + String str = + "HBase table split(table name: table, scan: , start row: row-start, " + + "end row: row-end, region location: location)"; + Assert.assertEquals(str, split.toString()); + + split = new TableSplit((TableName) null, null, null, null); + str = + "HBase table split(table name: null, scan: , start row: null, " + + "end row: null, region location: null)"; + Assert.assertEquals(str, split.toString()); + } }