Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5D27F200C54 for ; Wed, 12 Apr 2017 16:45:29 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5BC28160B95; Wed, 12 Apr 2017 14:45:29 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A0A42160B8A for ; Wed, 12 Apr 2017 16:45:28 +0200 (CEST) Received: (qmail 95839 invoked by uid 500); 12 Apr 2017 14:45:26 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 95483 invoked by uid 99); 12 Apr 2017 14:45:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Apr 2017 14:45:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E20A0DFC00; Wed, 12 Apr 2017 14:45:25 +0000 (UTC) From: joshelser To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo pull request #247: ACCUMULO-3208 Integration test for the OrIterato... Content-Type: text/plain Message-Id: <20170412144525.E20A0DFC00@git1-us-west.apache.org> Date: Wed, 12 Apr 2017 14:45:25 +0000 (UTC) archived-at: Wed, 12 Apr 2017 14:45:29 -0000 Github user joshelser commented on a diff in the pull request: https://github.com/apache/accumulo/pull/247#discussion_r111170295 --- Diff: core/src/main/java/org/apache/accumulo/core/iterators/OrIterator.java --- @@ -80,59 +128,103 @@ public int compareTo(TermSource o) { // sorted after they have been determined to be valid. return this.iter.getTopKey().compareColumnQualifier(o.iter.getTopKey().getColumnQualifier()); } + + /** + * Converts the given {@code Range} into the correct {@code Range} for this TermSource (per this expected table structure) and then seeks this TermSource's + * SKVI. + */ + public void seek(Range originalRange) throws IOException { + // the infinite start key is equivalent to a null startKey on the Range. + if (!originalRange.isInfiniteStartKey()) { + Key originalStartKey = originalRange.getStartKey(); + // Pivot the provided range into the range for this term + Key newKey = new Key(originalStartKey.getRow(), term, originalStartKey.getColumnQualifier(), originalStartKey.getTimestamp()); + // Construct the new range, preserving the other attributes on the provided range. + currentRange = new Range(newKey, originalRange.isStartKeyInclusive(), originalRange.getEndKey(), originalRange.isEndKeyInclusive()); + } else { + currentRange = originalRange; + } + LOG.trace("Seeking {} to {}", this, currentRange); + iter.seek(currentRange, seekColfams, true); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("TermSource{term=").append(term).append(", currentRange=").append(currentRange).append("}"); + return sb.toString(); + } + + /** + * @return True if there is a valid topKey which falls into the range this TermSource's iterator was last seeked to, false otherwise. + */ + boolean hasEntryForTerm() { + if (!iter.hasTop()) { + return false; + } + return currentRange.contains(iter.getTopKey()); + } } public OrIterator() { - this.sources = new ArrayList<>(); + this.sources = Collections.emptyList(); } private OrIterator(OrIterator other, IteratorEnvironment env) { - this.sources = new ArrayList<>(); + ArrayList copiedSources = new ArrayList<>(); for (TermSource TS : other.sources) - this.sources.add(new TermSource(TS.iter.deepCopy(env), TS.term)); + copiedSources.add(new TermSource(TS.iter.deepCopy(env), new Text(TS.term))); + this.sources = Collections.unmodifiableList(copiedSources); } @Override public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { return new OrIterator(this, env); } - public void addTerm(SortedKeyValueIterator source, Text term, IteratorEnvironment env) { - this.sources.add(new TermSource(source.deepCopy(env), term)); + public void setTerms(SortedKeyValueIterator source, Collection terms, IteratorEnvironment env) { + ArrayList newTerms = new ArrayList<>(); + for (String term : terms) { + newTerms.add(new TermSource(source.deepCopy(env), new Text(term))); + } + this.sources = Collections.unmodifiableList(newTerms); } @Override final public void next() throws IOException { - + LOG.trace("next()"); if (currentTerm == null) return; // Advance currentTerm currentTerm.iter.next(); --- End diff -- I'm not aware of any exceptions bubbling up out of an iterator if we call `next()` at the end of the iteration. Whether or not `currentTerm` is `null` is essentially making the same check (we never preserve the `TermSource` as `currentTerm` or in the heap after it's been exhausted). Down below, we do that check proactively (do we have more entries for this TermSource) before preserving it. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---