Java Code Examples for org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner#advance()
The following examples show how to use
org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner#advance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestTFile.java From RDFS with Apache License 2.0 | 6 votes |
private int readPrepWithUnknownLength(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < start; i++) { String key = String.format(localFormatter, i); byte[] read = readKey(scanner); assertTrue("keys not equal", Arrays.equals(key.getBytes(), read)); try { read = readValue(scanner); assertTrue(false); } catch (IOException ie) { // should have thrown exception } String value = "value" + key; read = readLongValue(scanner, value.getBytes().length); assertTrue("values nto equal", Arrays.equals(read, value.getBytes())); scanner.advance(); } return (start + n); }
Example 2
Source File: TestTFileByteArrays.java From hadoop with Apache License 2.0 | 6 votes |
private void readValueWithoutKey(int recordIndex) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScannerByKey(composeSortedKey(KEY, recordIndex) .getBytes(), null); byte[] vbuf1 = new byte[BUF_SIZE]; int vlen1 = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf1); Assert.assertEquals(new String(vbuf1, 0, vlen1), VALUE + recordIndex); if (scanner.advance() && !scanner.atEnd()) { byte[] vbuf2 = new byte[BUF_SIZE]; int vlen2 = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf2); Assert.assertEquals(new String(vbuf2, 0, vlen2), VALUE + (recordIndex + 1)); } scanner.close(); reader.close(); }
Example 3
Source File: TestTFileByteArrays.java From hadoop-gpu with Apache License 2.0 | 6 votes |
private void readValueWithoutKey(int count, int recordIndex) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(composeSortedKey(KEY, count, recordIndex) .getBytes(), null); byte[] vbuf1 = new byte[BUF_SIZE]; int vlen1 = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf1); Assert.assertEquals(new String(vbuf1, 0, vlen1), VALUE + recordIndex); if (scanner.advance() && !scanner.atEnd()) { byte[] vbuf2 = new byte[BUF_SIZE]; int vlen2 = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf2); Assert.assertEquals(new String(vbuf2, 0, vlen2), VALUE + (recordIndex + 1)); } scanner.close(); reader.close(); }
Example 4
Source File: TestTFile.java From big-c with Apache License 2.0 | 6 votes |
private int readPrepWithUnknownLength(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < start; i++) { String key = String.format(localFormatter, i); byte[] read = readKey(scanner); assertTrue("keys not equal", Arrays.equals(key.getBytes(), read)); try { read = readValue(scanner); assertTrue(false); } catch (IOException ie) { // should have thrown exception } String value = "value" + key; read = readLongValue(scanner, value.getBytes().length); assertTrue("values nto equal", Arrays.equals(read, value.getBytes())); scanner.advance(); } return (start + n); }
Example 5
Source File: TestTFileByteArrays.java From RDFS with Apache License 2.0 | 5 votes |
static void readRecords(FileSystem fs, Path path, int count, Configuration conf) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { for (int nx = 0; nx < count; nx++, scanner.advance()) { Assert.assertFalse(scanner.atEnd()); // Assert.assertTrue(scanner.next()); byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), composeSortedKey(KEY, nx)); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), VALUE + nx); } Assert.assertTrue(scanner.atEnd()); Assert.assertFalse(scanner.advance()); } finally { scanner.close(); reader.close(); } }
Example 6
Source File: TestTFile.java From hadoop with Apache License 2.0 | 5 votes |
private int readLargeRecords(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < (start + n); i++) { byte[] key = readKey(scanner); String keyStr = String.format(localFormatter, i); assertTrue("btyes for keys do not match", Arrays.equals( keyStr.getBytes(), key)); scanner.advance(); key = readKey(scanner); assertTrue("btyes for keys do not match", Arrays.equals( keyStr.getBytes(), key)); scanner.advance(); } return (start + n); }
Example 7
Source File: TestTFile.java From RDFS with Apache License 2.0 | 5 votes |
private int readPrepWithKnownLength(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < (start + n); i++) { String key = String.format(localFormatter, i); byte[] read = readKey(scanner); assertTrue("keys not equal", Arrays.equals(key.getBytes(), read)); String value = "value" + key; read = readValue(scanner); assertTrue("values not equal", Arrays.equals(value.getBytes(), read)); scanner.advance(); } return (start + n); }
Example 8
Source File: TestTFileUnsortedByteArrays.java From RDFS with Apache License 2.0 | 5 votes |
public void testScan() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); Scanner scanner = reader.createScanner(); try { // read key and value byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyZ"); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ"); scanner.advance(); // now try get value first vbuf = new byte[BUF_SIZE]; vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueM"); kbuf = new byte[BUF_SIZE]; klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyM"); } finally { scanner.close(); reader.close(); } }
Example 9
Source File: TestTFileUnsortedByteArrays.java From hadoop-gpu with Apache License 2.0 | 5 votes |
public void testScanRange() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); Scanner scanner = reader.createScanner(); try { // read key and value byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyZ"); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ"); scanner.advance(); // now try get value first vbuf = new byte[BUF_SIZE]; vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueM"); kbuf = new byte[BUF_SIZE]; klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyM"); } finally { scanner.close(); reader.close(); } }
Example 10
Source File: TestTFileUnsortedByteArrays.java From big-c with Apache License 2.0 | 5 votes |
public void testScan() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); Scanner scanner = reader.createScanner(); try { // read key and value byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyZ"); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ"); scanner.advance(); // now try get value first vbuf = new byte[BUF_SIZE]; vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueM"); kbuf = new byte[BUF_SIZE]; klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyM"); } finally { scanner.close(); reader.close(); } }
Example 11
Source File: TestTFileUnsortedByteArrays.java From RDFS with Apache License 2.0 | 5 votes |
public void testScanRange() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); Scanner scanner = reader.createScanner(); try { // read key and value byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyZ"); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ"); scanner.advance(); // now try get value first vbuf = new byte[BUF_SIZE]; vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueM"); kbuf = new byte[BUF_SIZE]; klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyM"); } finally { scanner.close(); reader.close(); } }
Example 12
Source File: TestTFileByteArrays.java From big-c with Apache License 2.0 | 5 votes |
private void readKeyWithoutValue(int recordIndex) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScannerByKey(composeSortedKey(KEY, recordIndex) .getBytes(), null); try { // read the indexed key byte[] kbuf1 = new byte[BUF_SIZE]; int klen1 = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf1); Assert.assertEquals(new String(kbuf1, 0, klen1), composeSortedKey(KEY, recordIndex)); if (scanner.advance() && !scanner.atEnd()) { // read the next key following the indexed byte[] kbuf2 = new byte[BUF_SIZE]; int klen2 = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf2); Assert.assertEquals(new String(kbuf2, 0, klen2), composeSortedKey(KEY, recordIndex + 1)); } } finally { scanner.close(); reader.close(); } }
Example 13
Source File: TestTFile.java From hadoop-gpu with Apache License 2.0 | 5 votes |
private int readPrepWithKnownLength(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < (start + n); i++) { String key = String.format(localFormatter, i); byte[] read = readKey(scanner); assertTrue("keys not equal", Arrays.equals(key.getBytes(), read)); String value = "value" + key; read = readValue(scanner); assertTrue("values not equal", Arrays.equals(value.getBytes(), read)); scanner.advance(); } return (start + n); }
Example 14
Source File: TestTFile.java From big-c with Apache License 2.0 | 5 votes |
private int readPrepWithKnownLength(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < (start + n); i++) { String key = String.format(localFormatter, i); byte[] read = readKey(scanner); assertTrue("keys not equal", Arrays.equals(key.getBytes(), read)); String value = "value" + key; read = readValue(scanner); assertTrue("values not equal", Arrays.equals(value.getBytes(), read)); scanner.advance(); } return (start + n); }
Example 15
Source File: TestTFileUnsortedByteArrays.java From hadoop-gpu with Apache License 2.0 | 5 votes |
public void testScan() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); Scanner scanner = reader.createScanner(); try { // read key and value byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyZ"); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ"); scanner.advance(); // now try get value first vbuf = new byte[BUF_SIZE]; vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueM"); kbuf = new byte[BUF_SIZE]; klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyM"); } finally { scanner.close(); reader.close(); } }
Example 16
Source File: TestTFileUnsortedByteArrays.java From hadoop with Apache License 2.0 | 5 votes |
public void testScan() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); Scanner scanner = reader.createScanner(); try { // read key and value byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyZ"); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ"); scanner.advance(); // now try get value first vbuf = new byte[BUF_SIZE]; vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), "valueM"); kbuf = new byte[BUF_SIZE]; klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), "keyM"); } finally { scanner.close(); reader.close(); } }
Example 17
Source File: TestTFileByteArrays.java From hadoop with Apache License 2.0 | 5 votes |
private void readKeyWithoutValue(int recordIndex) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScannerByKey(composeSortedKey(KEY, recordIndex) .getBytes(), null); try { // read the indexed key byte[] kbuf1 = new byte[BUF_SIZE]; int klen1 = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf1); Assert.assertEquals(new String(kbuf1, 0, klen1), composeSortedKey(KEY, recordIndex)); if (scanner.advance() && !scanner.atEnd()) { // read the next key following the indexed byte[] kbuf2 = new byte[BUF_SIZE]; int klen2 = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf2); Assert.assertEquals(new String(kbuf2, 0, klen2), composeSortedKey(KEY, recordIndex + 1)); } } finally { scanner.close(); reader.close(); } }
Example 18
Source File: TestTFileByteArrays.java From hadoop with Apache License 2.0 | 5 votes |
static void readRecords(FileSystem fs, Path path, int count, Configuration conf) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(); try { for (int nx = 0; nx < count; nx++, scanner.advance()) { Assert.assertFalse(scanner.atEnd()); // Assert.assertTrue(scanner.next()); byte[] kbuf = new byte[BUF_SIZE]; int klen = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf); Assert.assertEquals(new String(kbuf, 0, klen), composeSortedKey(KEY, nx)); byte[] vbuf = new byte[BUF_SIZE]; int vlen = scanner.entry().getValueLength(); scanner.entry().getValue(vbuf); Assert.assertEquals(new String(vbuf, 0, vlen), VALUE + nx); } Assert.assertTrue(scanner.atEnd()); Assert.assertFalse(scanner.advance()); } finally { scanner.close(); reader.close(); } }
Example 19
Source File: TestTFileByteArrays.java From hadoop-gpu with Apache License 2.0 | 5 votes |
private void readKeyWithoutValue(int count, int recordIndex) throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Scanner scanner = reader.createScanner(composeSortedKey(KEY, count, recordIndex) .getBytes(), null); try { // read the indexed key byte[] kbuf1 = new byte[BUF_SIZE]; int klen1 = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf1); Assert.assertEquals(new String(kbuf1, 0, klen1), composeSortedKey(KEY, count, recordIndex)); if (scanner.advance() && !scanner.atEnd()) { // read the next key following the indexed byte[] kbuf2 = new byte[BUF_SIZE]; int klen2 = scanner.entry().getKeyLength(); scanner.entry().getKey(kbuf2); Assert.assertEquals(new String(kbuf2, 0, klen2), composeSortedKey(KEY, count, recordIndex + 1)); } } finally { scanner.close(); reader.close(); } }
Example 20
Source File: TestTFile.java From hadoop-gpu with Apache License 2.0 | 5 votes |
private int readLargeRecords(Scanner scanner, int start, int n) throws IOException { for (int i = start; i < (start + n); i++) { byte[] key = readKey(scanner); String keyStr = String.format(localFormatter, i); assertTrue("btyes for keys do not match", Arrays.equals( keyStr.getBytes(), key)); scanner.advance(); key = readKey(scanner); assertTrue("btyes for keys do not match", Arrays.equals( keyStr.getBytes(), key)); scanner.advance(); } return (start + n); }