public void testNoDataEntry() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertTrue(reader.isSorted()); Scanner scanner = reader.createScanner(); Assert.assertTrue(scanner.atEnd()); scanner.close(); reader.close(); }
private void readEmptyRecords(Scanner scanner, int n) throws IOException { byte[] key = new byte[0]; byte[] value = new byte[0]; byte[] readKey = null; byte[] readValue = null; for (int i = 0; i < n; i++) { readKey = readKey(scanner); readValue = readValue(scanner); assertTrue("failed to match keys", Arrays.equals(readKey, key)); assertTrue("failed to match values", Arrays.equals(readValue, value)); assertTrue("failed to advance cursor", scanner.advance()); } }
public byte[] readLongValue(Scanner scanner, int len) throws IOException { DataInputStream din = scanner.entry().getValueStream(); byte[] b = new byte[len]; din.readFully(b); din.close(); return b; }
scanner.seekTo(getSomeKey(50)); assertTrue("location lookup failed", scanner.seekTo(getSomeKey(50))); readKey)); scanner.seekTo(new byte[0]); byte[] val1 = readValue(scanner); scanner.seekTo(new byte[0]); byte[] val2 = readValue(scanner); assertTrue(Arrays.equals(val1, val2)); scanner.lowerBound(getSomeKey(50)); assertTrue("locaton lookup failed", scanner.currentLocation .compareTo(reader.end()) < 0); scanner.upperBound(getSomeKey(50)); assertTrue("location lookup failed", scanner.currentLocation .compareTo(reader.end()) < 0); getSomeKey(51))); scanner.close(); assertFalse(scanner.advance()); scanner.close(); reader.close(); fin.close();
scanner.seekTo(getSomeKey(50)); assertTrue("location lookup failed", scanner.seekTo(getSomeKey(50))); readKey)); scanner.seekTo(new byte[0]); byte[] val1 = readValue(scanner); scanner.seekTo(new byte[0]); byte[] val2 = readValue(scanner); assertTrue(Arrays.equals(val1, val2)); scanner.lowerBound(getSomeKey(50)); assertTrue("locaton lookup failed", scanner.currentLocation .compareTo(reader.end()) < 0); scanner.upperBound(getSomeKey(50)); assertTrue("location lookup failed", scanner.currentLocation .compareTo(reader.end()) < 0); getSomeKey(51))); scanner.close(); assertFalse(scanner.advance()); scanner.close(); reader.close(); fin.close();
scanner.lowerBound("keyN".getBytes()); Assert.fail("Cannot search in a unsorted TFile!"); scanner.upperBound("keyA".getBytes()); Assert.fail("Cannot search higher in a unsorted TFile!"); scanner.seekTo("keyM".getBytes()); Assert.fail("Cannot search a unsorted TFile!"); scanner.close(); reader.close();
scanner.lowerBound("keyN".getBytes()); Assert.fail("Cannot search in a unsorted TFile!"); scanner.upperBound("keyA".getBytes()); Assert.fail("Cannot search higher in a unsorted TFile!"); scanner.seekTo("keyM".getBytes()); Assert.fail("Cannot search a unsorted TFile!"); scanner.close(); reader.close();
scanner.seekTo(getSomeKey(50)); assertTrue("location lookup failed", scanner.seekTo(getSomeKey(50))); readKey)); scanner.seekTo(new byte[0]); byte[] val1 = readValue(scanner); scanner.seekTo(new byte[0]); byte[] val2 = readValue(scanner); assertTrue(Arrays.equals(val1, val2)); scanner.lowerBound(getSomeKey(50)); assertTrue("locaton lookup failed", scanner.currentLocation .compareTo(reader.end()) < 0); scanner.upperBound(getSomeKey(50)); assertTrue("location lookup failed", scanner.currentLocation .compareTo(reader.end()) < 0); getSomeKey(51))); scanner.close(); assertFalse(scanner.advance()); scanner.close(); reader.close(); fin.close();
scanner.lowerBound("keyN".getBytes()); Assert.fail("Cannot search in a unsorted TFile!"); scanner.upperBound("keyA".getBytes()); Assert.fail("Cannot search higher in a unsorted TFile!"); scanner.seekTo("keyM".getBytes()); Assert.fail("Cannot search a unsorted TFile!"); scanner.close(); reader.close();
for (int i = 0; i < options.seekCount; ++i) { kSampler.next(key); scanner.lowerBound(key.get(), 0, key.getSize()); if (!scanner.atEnd()) { scanner.entry().get(key, val); totalBytes += key.getSize(); totalBytes += val.getSize();
for (int i = 0; i < options.seekCount; ++i) { kSampler.next(key); scanner.lowerBound(key.get(), 0, key.getSize()); if (!scanner.atEnd()) { scanner.entry().get(key, val); totalBytes += key.getSize(); totalBytes += val.getSize();
public void testFailureNegativeOffset_2() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { scanner.lowerBound("keyX".getBytes(), -1, 4); Assert.fail("Error on handling negative offset."); } catch (Exception e) { // noop, expecting exceptions } finally { reader.close(); scanner.close(); } closeOutput(); }
@Test public void testFailureNegativeLength_2() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { scanner.lowerBound("keyX".getBytes(), 0, -1); Assert.fail("Error on handling negative length."); } catch (Exception e) { // noop, expecting exceptions } finally { scanner.close(); reader.close(); } closeOutput(); }
@Test public void testFailureNegativeOffset_2() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { scanner.lowerBound("keyX".getBytes(), -1, 4); Assert.fail("Error on handling negative offset."); } catch (Exception e) { // noop, expecting exceptions } finally { reader.close(); scanner.close(); } closeOutput(); }
public void testFailureNegativeLength_2() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { scanner.lowerBound("keyX".getBytes(), 0, -1); Assert.fail("Error on handling negative length."); } catch (Exception e) { // noop, expecting exceptions } finally { scanner.close(); reader.close(); } closeOutput(); }
@Test public void testFailureNegativeLength_2() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { scanner.lowerBound("keyX".getBytes(), 0, -1); Assert.fail("Error on handling negative length."); } catch (Exception e) { // noop, expecting exceptions } finally { scanner.close(); reader.close(); } closeOutput(); }
@Test public void testFailureNegativeOffset_2() throws IOException { if (skip) return; closeOutput(); Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { scanner.lowerBound("keyX".getBytes(), -1, 4); Assert.fail("Error on handling negative offset."); } catch (Exception e) { // noop, expecting exceptions } finally { reader.close(); scanner.close(); } closeOutput(); }
/** * Get a scanner that covers a portion of TFile based on byte offsets. * * @param offset * The beginning byte offset in the TFile. * @param length * The length of the region. * @return The actual coverage of the returned scanner tries to match the * specified byte-region but always round up to the compression * block boundaries. It is possible that the returned scanner * contains zero key-value pairs even if length is positive. * @throws IOException */ public Scanner createScannerByByteRange(long offset, long length) throws IOException { return new Scanner(this, offset, offset + length); }
/** * Advance cursor by n positions within the block. * * @param n * Number of key-value pairs to skip in block. * @throws IOException */ private void inBlockAdvance(long n) throws IOException { for (long i = 0; i < n; ++i) { checkKey(); if (!valueBufferInputStream.isClosed()) { valueBufferInputStream.close(); } klen = -1; currentLocation.incRecordIndex(); } }
/** * Get a scanner that covers a portion of TFile based on byte offsets. * * @param offset * The beginning byte offset in the TFile. * @param length * The length of the region. * @return The actual coverage of the returned scanner tries to match the * specified byte-region but always round up to the compression * block boundaries. It is possible that the returned scanner * contains zero key-value pairs even if length is positive. * @throws IOException */ public Scanner createScannerByByteRange(long offset, long length) throws IOException { return new Scanner(this, offset, offset + length); }