/** * Get a Comparator object to compare Entries. It is useful when you want * stores the entries in a collection (such as PriorityQueue) and perform * sorting or comparison among entries based on the keys without copying out * the key. * * @return An Entry Comparator.. */ public Comparator<Scanner.Entry> getEntryComparator() { if (!isSorted()) { throw new RuntimeException( "Entries are not comparable for unsorted TFiles"); } return new Comparator<Scanner.Entry>() { /** * Provide a customized comparator for Entries. This is useful if we * have a collection of Entry objects. However, if the Entry objects * come from different TFiles, users must ensure that those TFiles share * the same RawComparator. */ @Override public int compare(Scanner.Entry o1, Scanner.Entry o2) { return comparator.compare(o1.getKeyBuffer(), 0, o1.getKeyLength(), o2 .getKeyBuffer(), 0, o2.getKeyLength()); } }; }
int compareKeys(RawComparable a, RawComparable b) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, b); }
int compareKeys(byte[] a, int o1, int l1, byte[] b, int o2, int l2) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, o1, l1, b, o2, l2); }
public void testFailureScannerWithKeys() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); try { Scanner scanner = reader.createScannerByKey("aaa".getBytes(), "zzz".getBytes()); Assert .fail("Failed to catch creating scanner with keys on unsorted file."); } catch (RuntimeException e) { } finally { reader.close(); } }
public void testFailureScannerWithKeys() throws IOException { Reader reader = new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf); Assert.assertFalse(reader.isSorted()); Assert.assertEquals((int) reader.getEntryCount(), 4); try { Scanner scanner = reader.createScannerByKey("aaa".getBytes(), "zzz".getBytes()); Assert .fail("Failed to catch creating scanner with keys on unsorted file."); } catch (RuntimeException e) { } finally { reader.close(); } }
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(); }
int compareKeys(byte[] a, int o1, int l1, byte[] b, int o2, int l2) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, o1, l1, b, o2, l2); }
int compareKeys(byte[] a, int o1, int l1, byte[] b, int o2, int l2) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, o1, l1, b, o2, l2); }
int compareKeys(RawComparable a, RawComparable b) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, b); }
int compareKeys(RawComparable a, RawComparable b) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, b); }
int compareKeys(byte[] a, int o1, int l1, byte[] b, int o2, int l2) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, o1, l1, b, o2, l2); }
int compareKeys(byte[] a, int o1, int l1, byte[] b, int o2, int l2) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, o1, l1, b, o2, l2); }
@Test 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(); }
int compareKeys(RawComparable a, RawComparable b) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, b); }
int compareKeys(RawComparable a, RawComparable b) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, b); }
@Test 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(); }
int compareKeys(byte[] a, int o1, int l1, byte[] b, int o2, int l2) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, o1, l1, b, o2, l2); }
int compareKeys(RawComparable a, RawComparable b) { if (!isSorted()) { throw new RuntimeException("Cannot compare keys for unsorted TFiles."); } return comparator.compare(a, b); }
/** * if greater is true then returns the beginning location of the block * containing the key strictly greater than input key. if greater is false * then returns the beginning location of the block greater than equal to * the input key * * @param key * the input key * @param greater * boolean flag * @return * @throws IOException */ Location getBlockContainsKey(RawComparable key, boolean greater) throws IOException { if (!isSorted()) { throw new RuntimeException("Seeking in unsorted TFile"); } checkTFileDataIndex(); int blkIndex = (greater) ? tfileIndex.upperBound(key) : tfileIndex.lowerBound(key); if (blkIndex < 0) return end; return new Location(blkIndex, 0); }