/** * Iterates over the source until an acceptable key/value pair is found. */ private void findTop() throws IOException { while (source.hasTop()) { Key top = source.getTopKey(); if (top.isDeleted() || (accept(top, source.getTopValue()))) { break; } source.next(); } }
@Override public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { source.seek(range, columnFamilies, inclusive); }
private MultiIterator(MultiIterator other, IteratorEnvironment env) { super(other.iters.size()); this.iters = new ArrayList<>(); this.fence = other.fence; for (SortedKeyValueIterator<Key,Value> iter : other.iters) { iters.add(iter.deepCopy(env)); } }
@Override protected void advanceToIntersection() throws IOException { super.advanceToIntersection(); if (topKey == null) return; if (log.isTraceEnabled()) log.trace("using top key to seek for doc: {}", topKey); Key docKey = buildDocKey(); docSource.seek(new Range(docKey, true, null, false), docColfSet, true); log.debug("got doc key: {}", docSource.getTopKey()); if (docSource.hasTop() && docKey.equals(docSource.getTopKey(), PartialKey.ROW_COLFAM_COLQUAL)) { value = docSource.getTopValue(); } log.debug("got doc value: {}", value); }
@Override public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { reader.seek(range, columnFamilies, inclusive); this.range = range; hasTop = reader.hasTop() && !range.afterEndKey(reader.getTopKey()); while (hasTop() && range.beforeStartKey(getTopKey())) { next(); } }
@Override public Entry<Key,Value> next() { try { Entry<Key,Value> result = new KeyValue(new Key(inner.getTopKey()), new Value(inner.getTopValue()).get()); inner.next(); return result; } catch (IOException ex) { throw new NoSuchElementException(); } }
void next(Collection<SortedKeyValueIterator<Key,Value>> iterators) throws IOException { for (SortedKeyValueIterator<Key,Value> iter : iterators) { iter.next(); } } }
@Override public Value getTopValue() { return source.getTopValue(); }
boolean allHasTop(Collection<SortedKeyValueIterator<Key,Value>> iterators) { for (SortedKeyValueIterator<Key,Value> iter : iterators) { if (!iter.hasTop()) { return false; } } return true; }
@Override public Key getTopKey() { if (!hasTop) throw new IllegalStateException(); return reader.getTopKey(); }
@Override public Value next() { if (!hasNext) throw new NoSuchElementException(); Value topValue = new Value(source.getTopValue()); try { source.next(); hasNext = _hasNext(); } catch (IOException e) { throw new RuntimeException(e); } return topValue; }
private void load() { if (hasTop()) { topKey.set(source.getTopKey()); topValue.set(source.getTopValue().get()); } } }
@Override public IteratorTestOutput test(IteratorTestInput testInput) { final SortedKeyValueIterator<Key,Value> skvi = IteratorTestUtil.instantiateIterator(testInput); final SortedKeyValueIterator<Key,Value> source = IteratorTestUtil.createSource(testInput); try { skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment()); SortedKeyValueIterator<Key,Value> copy = skvi.deepCopy(new SimpleIteratorEnvironment()); copy.seek(testInput.getRange(), testInput.getFamilies(), testInput.isInclusive()); return new IteratorTestOutput(consume(copy)); } catch (IOException e) { return new IteratorTestOutput(e); } }
@Override public IteratorTestOutput test(IteratorTestInput testInput) { final SortedKeyValueIterator<Key,Value> skvi = IteratorTestUtil.instantiateIterator(testInput); final SortedKeyValueIterator<Key,Value> source = IteratorTestUtil.createSource(testInput); try { skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment()); skvi.seek(testInput.getRange(), testInput.getFamilies(), testInput.isInclusive()); return new IteratorTestOutput(consume(skvi)); } catch (IOException e) { return new IteratorTestOutput(e); } }
@Override public IteratorTestOutput test(IteratorTestInput testInput) { final SortedKeyValueIterator<Key,Value> skvi = IteratorTestUtil.instantiateIterator(testInput); final SortedKeyValueIterator<Key,Value> source = IteratorTestUtil.createSource(testInput); try { skvi.init(source, testInput.getIteratorOptions(), new SimpleIteratorEnvironment()); YieldCallback<Key> yield = new YieldCallback<>(); skvi.enableYielding(yield); skvi.seek(testInput.getRange(), testInput.getFamilies(), testInput.isInclusive()); return new IteratorTestOutput(consume(testInput, skvi, yield)); } catch (IOException e) { return new IteratorTestOutput(e); } }