Skip to content

Commit

Permalink
HBASE-25115 HFilePrettyPrinter can't seek to the row which is the fir…
Browse files Browse the repository at this point in the history
…st row of a hfile

Closes #2473

Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
  • Loading branch information
nyl3532016 authored and virajjasani committed Oct 4, 2020
1 parent b0170d0 commit 3226c17
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ public int processFile(Path file, boolean checkRootDir) throws IOException {
// scan over file and read key/value's and check if requested
HFileScanner scanner = reader.getScanner(false, false, false);
fileStats = new KeyValueStatsCollector();
boolean shouldScanKeysValues = false;
if (this.isSeekToRow) {
boolean shouldScanKeysValues;
if (this.isSeekToRow && !Bytes.equals(row, reader.getFirstRowKey().orElse(null))) {
// seek to the first kv on this row
shouldScanKeysValues =
(scanner.seekTo(PrivateCellUtil.createFirstOnRow(this.row)) != -1);
shouldScanKeysValues = (scanner.seekTo(PrivateCellUtil.createFirstOnRow(this.row)) != -1);
} else {
shouldScanKeysValues = scanner.seekTo();
}
if (shouldScanKeysValues)
if (shouldScanKeysValues) {
scanKeysValues(file, fileStats, scanner, row);
}
}

// print meta data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,23 @@ public void testHFilePrettyPrinterRootDir() throws Exception {
String expectedResult = "Scanning -> " + fileInRootDir + "\n" + "Scanned kv count -> 1000\n";
assertEquals(expectedResult, result);
}

@Test
public void testHFilePrettyPrinterSeekFirstRow() throws Exception {
Path fileNotInRootDir = UTIL.getDataTestDir("hfile");
TestHRegionServerBulkLoad.createHFile(fs, fileNotInRootDir, cf, fam, value, 1000);
assertNotEquals("directory used is not an HBase root dir", UTIL.getDefaultRootDirPath(),
fileNotInRootDir);

HFile.Reader reader =
HFile.createReader(fs, fileNotInRootDir, CacheConfig.DISABLED, true, conf);
String firstRowKey = new String(reader.getFirstRowKey().get());

System.setOut(ps);
new HFilePrettyPrinter(conf)
.run(new String[] { "-v", "-w" + firstRowKey, String.valueOf(fileNotInRootDir) });
String result = new String(stream.toByteArray());
String expectedResult = "Scanning -> " + fileNotInRootDir + "\n" + "Scanned kv count -> 1\n";
assertEquals(expectedResult, result);
}
}

0 comments on commit 3226c17

Please sign in to comment.