@Override public boolean reseek(Cell seekCell) { while(iter.hasNext()){ Cell next = iter.next(); int ret = comparator.compare(next, seekCell); if(ret >= 0){ current = next; return true; } } return false; }
@Override public boolean reseek(KeyValue seekKv) { while(iter.hasNext()){ KeyValue next = iter.next(); int ret = comparator.compare(next, seekKv); if(ret >= 0){ current = next; return true; } } return false; }
@Override public int compareKey(KVComparator comparator, Cell key) { ByteBuffer bb = getKeyDeepCopy(); return comparator.compare(key, new KeyValue.KeyOnlyKeyValue(bb.array(), bb.arrayOffset(), bb.limit())); } /**
@Override public boolean seek(Cell next) throws IOException { // check to see if the next kv is after the current key, in which case we can use reseek, // which will be more efficient Cell peek = kvScanner.peek(); // there is another value and its before the requested one - we can do a reseek! if (peek != null) { int compare = KeyValue.COMPARATOR.compare(peek, next); if (compare < 0) { return kvScanner.reseek(next); } else if (compare == 0) { // we are already at the given key! return true; } } return kvScanner.seek(next); }
public HFileSortedIterator(HFileScanner scan, byte[] from, boolean fromInclusive, byte[] to, boolean toInclusive) throws IOException { this.scan = scan; this.from = from; this.fromInclusive = fromInclusive; this.to = to; this.toInclusive = toInclusive; scanStat = (stats == null) ? new SortedOplogStatistics("", "").new ScanOperation( 0, 0, 0, 0, 0, 0, 0) : stats.getScan(); scanStart = scanStat.begin(); if (scan == null) { return; } assert from == null || to == null || scan.getReader().getComparator().compare( from, 0, from.length, to, 0, to.length) <= 0; initIterator(); }
@Override public int compareKey(KVComparator comparator, Cell key) { ByteBuffer bb = getKeyDeepCopy(); return comparator.compare(key, new KeyValue.KeyOnlyKeyValue(bb.array(), bb.arrayOffset(), bb.limit())); } /**
/** * Check whether scan as expected order * @param prevKV * @param kv * @param comparator * @throws IOException */ protected void checkScanOrder(Cell prevKV, Cell kv, KeyValue.KVComparator comparator) throws IOException { // Check that the heap gives us KVs in an increasing order. assert prevKV == null || comparator == null || comparator.compare(prevKV, kv) <= 0 : "Key " + prevKV + " followed by a " + "smaller key " + kv + " in cf " + store; }
@Override public int compare(BytesWritable left, BytesWritable right) { return KeyValue.COMPARATOR.compare( new KeyValue(left.getBytes(), 4, left.getLength() - 4), new KeyValue(right.getBytes(), 4, right.getLength() - 4)); } }
private KeyValue getHighest(KeyValue first, KeyValue second) { if (first == null && second == null) { return null; } if (first != null && second != null) { int compare = comparator.compare(first, second); return (compare > 0 ? first : second); } return (first != null ? first : second); }
private KeyValue getLowest(KeyValue first, KeyValue second) { if (first == null && second == null) { return null; } if (first != null && second != null) { int compare = comparator.compare(first, second); return (compare <= 0 ? first : second); } return (first != null ? first : second); }
/** * Compares two KeyValue * @param left * @param right * @return less than 0 if left is smaller, 0 if equal etc.. */ public int compare(KeyValue left, KeyValue right) { return this.kvComparator.compare(left, right); } /**
@Override protected void checkScanOrder(Cell prevKV, Cell kv, KeyValue.KVComparator comparator) throws IOException { // Check that the heap gives us KVs in an increasing order for same row and // decreasing order for different rows. assert prevKV == null || comparator == null || comparator.compareRows(kv, prevKV) < 0 || (comparator.matchingRows(kv, prevKV) && comparator.compare(kv, prevKV) >= 0) : "Key " + prevKV + " followed by a " + "error order key " + kv + " in cf " + store + " in reversed scan"; }
/** * Compares two KeyValue * @param left * @param right * @return less than 0 if left is smaller, 0 if equal etc.. */ public int compare(Cell left, Cell right) { return this.kvComparator.compare(left, right); } /**
private Cell getHighest(Cell first, Cell second) { if (first == null && second == null) { return null; } if (first != null && second != null) { int compare = comparator.compare(first, second); return (compare > 0 ? first : second); } return (first != null ? first : second); }
private Cell getLowest(Cell first, Cell second) { if (first == null && second == null) { return null; } if (first != null && second != null) { int compare = comparator.compare(first, second); return (compare <= 0 ? first : second); } return (first != null ? first : second); }
@Override public int compare(BytesWritable left, BytesWritable right) { return KeyValue.COMPARATOR.compare( new KeyValue(left.getBytes(), 4, left.getLength() - 4), new KeyValue(right.getBytes(), 4, right.getLength() - 4)); } }
@Override public boolean seek(Cell next) throws IOException { // check to see if the next kv is after the current key, in which case we can use reseek, // which will be more efficient Cell peek = kvScanner.peek(); // there is another value and its before the requested one - we can do a reseek! if (peek != null) { int compare = KeyValue.COMPARATOR.compare(peek, next); if (compare < 0) { return kvScanner.reseek(next); } else if (compare == 0) { // we are already at the given key! return true; } } return kvScanner.seek(next); }
/** * Test that when we do a column delete at a given timestamp that we delete the entire column. * @throws Exception */ @Test public void testCoverForDeleteColumn() throws Exception { ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET); KeyValue dc = createKvForType(Type.DeleteColumn, 11); KeyValue put = createKvForType(Type.Put, 10); assertEquals("Didn't filter out delete column.", ReturnCode.SKIP, filter.filterKeyValue(dc)); assertEquals("Didn't get a seek hint for the deleted column", ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(put)); // seek past the given put Cell seek = filter.getNextCellHint(put); assertTrue("Seeked key wasn't past the expected put - didn't skip the column", KeyValue.COMPARATOR.compare(seek, put) > 0); }
@Override public boolean seek(KeyValue next) throws IOException { // check to see if the next kv is after the current key, in which case we can use reseek, // which will be more efficient KeyValue peek = kvScanner.peek(); // there is another value and its before the requested one - we can do a reseek! if (peek != null) { int compare = KeyValue.COMPARATOR.compare(peek, next); if (compare < 0) { return kvScanner.reseek(next); } else if (compare == 0) { // we are already at the given key! return true; } } return kvScanner.seek(next); }
/** * Test that when we do a column delete at a given timestamp that we delete the entire column. * @throws Exception */ @Test public void testCoverForDeleteColumn() throws Exception { ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET); KeyValue dc = createKvForType(Type.DeleteColumn, 11); KeyValue put = createKvForType(Type.Put, 10); assertEquals("Didn't filter out delete column.", ReturnCode.SKIP, filter.filterKeyValue(dc)); assertEquals("Didn't get a seek hint for the deleted column", ReturnCode.SEEK_NEXT_USING_HINT, filter.filterKeyValue(put)); // seek past the given put KeyValue seek = filter.getNextKeyHint(put); assertTrue("Seeked key wasn't past the expected put - didn't skip the column", KeyValue.COMPARATOR.compare(seek, put) > 0); }