ACCUMULO-665 update AndIterator to seek to the right column families git-svn-id: https://svn.apache.org/repos/asf/accumulo/branches/1.4@1358206 13f79535-47bb-0310-9956-ffa450edef68
Project: http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/commit/a3ca5a7b Tree: http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/tree/a3ca5a7b Diff: http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/diff/a3ca5a7b Branch: refs/heads/master Commit: a3ca5a7bb22976b67809d21e959835ce38323d08 Parents: 86aedda Author: Eric C. Newton <e...@apache.org> Authored: Fri Jul 6 13:41:02 2012 +0000 Committer: Eric C. Newton <e...@apache.org> Committed: Fri Jul 6 13:41:02 2012 +0000 ---------------------------------------------------------------------- .../wikisearch/iterator/AndIterator.java | 54 ++++++++------------ 1 file changed, 21 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/blob/a3ca5a7b/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java ---------------------------------------------------------------------- diff --git a/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java b/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java index b469625..eafc4dd 100644 --- a/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java +++ b/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java @@ -17,8 +17,8 @@ package org.apache.accumulo.examples.wikisearch.iterator; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Map; import org.apache.accumulo.core.data.ArrayByteSequence; @@ -48,8 +48,8 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { private Text currentTerm = new Text(emptyByteArray); private Text currentDocID = new Text(emptyByteArray); private Collection<ByteSequence> seekColumnFamilies; - private boolean inclusive; private Text parentEndRow; + private static boolean SEEK_INCLUSIVE = true; /** * Used in representing a Term that is intersected on. @@ -60,24 +60,21 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { public Text dataLocation; public Text term; public boolean notFlag; + private Collection<ByteSequence> seekColumnFamilies; - public TermSource(TermSource other) { - this.iter = other.iter; - this.dataLocation = other.dataLocation; - this.term = other.term; - this.notFlag = other.notFlag; + private TermSource(TermSource other) { + this(other.iter, other.dataLocation, other.term, other.notFlag); } public TermSource(SortedKeyValueIterator<Key,Value> iter, Text dataLocation, Text term) { - this.iter = iter; - this.dataLocation = dataLocation; - this.term = term; - this.notFlag = false; + this(iter, dataLocation, term, false); } public TermSource(SortedKeyValueIterator<Key,Value> iter, Text dataLocation, Text term, boolean notFlag) { this.iter = iter; this.dataLocation = dataLocation; + ByteSequence bs = new ArrayByteSequence(dataLocation.getBytes(), 0, dataLocation.getLength()); + this.seekColumnFamilies = Collections.singletonList(bs); this.term = term; this.notFlag = notFlag; } @@ -305,8 +302,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { if (log.isDebugEnabled()) { log.debug("Seeking to: " + seekKey); } - - ts.iter.seek(new Range(seekKey, true, null, false), seekColumnFamilies, inclusive); + ts.iter.seek(new Range(seekKey, true, null, false), ts.seekColumnFamilies, SEEK_INCLUSIVE); continue; } @@ -352,7 +348,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { log.debug("Seeking to: " + seekKey); } - ts.iter.seek(new Range(seekKey, true, null, false), seekColumnFamilies, inclusive); + ts.iter.seek(new Range(seekKey, true, null, false), ts.seekColumnFamilies, SEEK_INCLUSIVE); if (!ts.iter.hasTop()) { currentRow = null; return true; @@ -385,8 +381,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { if (log.isDebugEnabled()) { log.debug("Seeking to: " + seekKey); } - - ts.iter.seek(new Range(seekKey, true, null, false), seekColumnFamilies, inclusive); + ts.iter.seek(new Range(seekKey, true, null, false), ts.seekColumnFamilies, SEEK_INCLUSIVE); if (!ts.iter.hasTop()) { currentRow = null; return true; @@ -407,14 +402,13 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { if (log.isDebugEnabled()) { log.debug("Need to seek to the right term"); } - Key seekKey = buildKey(currentRow, ts.dataLocation, new Text(ts.term + "\0"));// new Text(ts.term + "\0" + currentDocID)); if (log.isDebugEnabled()) { log.debug("Seeking to: " + seekKey); } - ts.iter.seek(new Range(seekKey, true, null, false), seekColumnFamilies, inclusive); + ts.iter.seek(new Range(seekKey, true, null, false), ts.seekColumnFamilies, SEEK_INCLUSIVE); if (!ts.iter.hasTop()) { currentRow = null; return true; @@ -451,7 +445,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { log.debug("Seeking to: " + seekKey); } - ts.iter.seek(new Range(seekKey, true, null, false), seekColumnFamilies, inclusive); + ts.iter.seek(new Range(seekKey, true, null, false), ts.seekColumnFamilies, SEEK_INCLUSIVE); if (!ts.iter.hasTop()) { currentRow = null; @@ -486,7 +480,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { log.debug("Seeking to: " + seekKey); } - ts.iter.seek(new Range(seekKey, true, null, false), seekColumnFamilies, inclusive); + ts.iter.seek(new Range(seekKey, true, null, false), ts.seekColumnFamilies, SEEK_INCLUSIVE); continue; } @@ -749,8 +743,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { // Build up the array of sources that are to be intersected sources = new TermSource[dataLocations.length]; - sources[0] = new TermSource(source, dataLocations[0], terms[0]); - for (int i = 1; i < dataLocations.length; i++) { + for (int i = 0; i < dataLocations.length; i++) { sources[i] = new TermSource(source.deepCopy(env), dataLocations[i], terms[i], notFlags[i]); } @@ -764,10 +757,10 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { } currentRow = new Text(); currentDocID.set(emptyByteArray); - doSeek(range, seekColumnFamilies, inclusive); + doSeek(range); } - private void doSeek(Range range, Collection<ByteSequence> seekColumnFamilies, boolean inclusive) throws IOException { + private void doSeek(Range range) throws IOException { overallRange = new Range(range); @@ -775,18 +768,13 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { this.parentEndRow = range.getEndKey().getRow(); } - this.seekColumnFamilies = seekColumnFamilies; - this.inclusive = inclusive; - // seek each of the sources to the right column family within the row given by key for (int i = 0; i < sourcesCount; i++) { Key sourceKey; Text dataLocation = (sources[i].dataLocation == null) ? nullText : sources[i].dataLocation; - Collection<ByteSequence> columnFamilies = new ArrayList<ByteSequence>(); - columnFamilies.add(new ArrayByteSequence(dataLocation.getBytes(), 0, dataLocation.getLength())); if (range.getStartKey() != null) { // Build a key with the DocID if one is given - if (range.getStartKey().getColumnFamily() != null) { + if (range.getStartKey().getColumnFamily() != null) { sourceKey = buildKey(getPartition(range.getStartKey()), dataLocation, (sources[i].term == null) ? nullText : new Text(sources[i].term + "\0" + range.getStartKey().getColumnFamily())); } // Build a key with just the term. @@ -796,9 +784,9 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { } if (!range.isStartKeyInclusive()) sourceKey = sourceKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL); - sources[i].iter.seek(new Range(sourceKey, true, null, false), columnFamilies, inclusive); + sources[i].iter.seek(new Range(sourceKey, true, null, false), sources[i].seekColumnFamilies, SEEK_INCLUSIVE); } else { - sources[i].iter.seek(range, columnFamilies, inclusive); + sources[i].iter.seek(range, sources[i].seekColumnFamilies, SEEK_INCLUSIVE); } } @@ -912,7 +900,7 @@ public class AndIterator implements SortedKeyValueIterator<Key,Value> { this.currentRow = row; this.currentDocID = new Text(this.getUID(jumpKey)); - doSeek(range, seekColumnFamilies, false); + doSeek(range); // make sure it is in the range if we have one. if (hasTop() && parentEndRow != null && topKey.getRow().compareTo(parentEndRow) > 0) {