diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java index fa97cfaf1e2..e4887fe4beb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/ImportTsv.java @@ -349,6 +349,13 @@ public class ImportTsv extends Configured implements Tool { private static final long serialVersionUID = 1L; } + /** + * Return starting position and length of row key from the specified line bytes. + * @param lineBytes + * @param length + * @return Pair of row key offset and length. + * @throws BadTsvLineException + */ public Pair parseRowKey(byte[] lineBytes, int length) throws BadTsvLineException { int rkColumnIndex = 0; @@ -371,7 +378,7 @@ public class ImportTsv extends Configured implements Tool { + " are less than row key position."); } } - return new Pair(startPos, endPos); + return new Pair(startPos, endPos - startPos + 1); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsvParser.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsvParser.java index 04d57f60776..912a9a8e975 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsvParser.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mapreduce/TestImportTsvParser.java @@ -220,7 +220,7 @@ public class TestImportTsvParser { byte[] line = Bytes.toBytes("rowkey\tval_a\t1234"); Pair rowKeyOffsets = parser.parseRowKey(line, line.length); assertEquals(0, rowKeyOffsets.getFirst().intValue()); - assertEquals(5, rowKeyOffsets.getSecond().intValue()); + assertEquals(6, rowKeyOffsets.getSecond().intValue()); try { line = Bytes.toBytes("\t\tval_a\t1234"); parser.parseRowKey(line, line.length); @@ -233,7 +233,7 @@ public class TestImportTsvParser { line = Bytes.toBytes("val_a\trowkey\t1234"); rowKeyOffsets = parser.parseRowKey(line, line.length); assertEquals(6, rowKeyOffsets.getFirst().intValue()); - assertEquals(11, rowKeyOffsets.getSecond().intValue()); + assertEquals(6, rowKeyOffsets.getSecond().intValue()); try { line = Bytes.toBytes("val_a"); rowKeyOffsets = parser.parseRowKey(line, line.length); @@ -246,7 +246,7 @@ public class TestImportTsvParser { line = Bytes.toBytes("val_a\t1234\trowkey"); rowKeyOffsets = parser.parseRowKey(line, line.length); assertEquals(11, rowKeyOffsets.getFirst().intValue()); - assertEquals(16, rowKeyOffsets.getSecond().intValue()); + assertEquals(6, rowKeyOffsets.getSecond().intValue()); } @Test