use of org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner in project hadoop by apache.
the class TestTFileSplit method readRowSplits.
/* Similar to readFile(), tests the scanner created
* by record numbers rather than the offsets.
*/
void readRowSplits(int numSplits) throws IOException {
Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
long totalRecords = reader.getEntryCount();
for (int i = 0; i < numSplits; i++) {
long startRec = i * totalRecords / numSplits;
long endRec = (i + 1) * totalRecords / numSplits;
if (i == numSplits - 1) {
endRec = totalRecords;
}
Scanner scanner = reader.createScannerByRecordNum(startRec, endRec);
int count = 0;
BytesWritable key = new BytesWritable();
BytesWritable value = new BytesWritable();
long x = startRec;
while (!scanner.atEnd()) {
assertEquals("Incorrect RecNum returned by scanner", scanner.getRecordNum(), x);
scanner.entry().get(key, value);
++count;
assertEquals("Incorrect RecNum returned by scanner", scanner.getRecordNum(), x);
scanner.advance();
++x;
}
scanner.close();
assertTrue(count == (endRec - startRec));
}
// make sure specifying range at the end gives zero records.
Scanner scanner = reader.createScannerByRecordNum(totalRecords, -1);
assertTrue(scanner.atEnd());
}
use of org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner in project hadoop by apache.
the class TestTFileStreams method testFailureNegativeOffset.
@Test
public void testFailureNegativeOffset() throws IOException {
if (skip)
return;
writeRecords(2, true, true);
Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
Scanner scanner = reader.createScanner();
byte[] buf = new byte[K];
try {
scanner.entry().getKey(buf, -1);
fail("Failed to handle key negative offset.");
} catch (Exception e) {
// noop, expecting exceptions
} finally {
}
scanner.close();
reader.close();
}
Aggregations