You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ec...@apache.org on 2012/07/06 15:41:02 UTC
svn commit: r1358206 -
/accumulo/branches/1.4/src/examples/wikisearch/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java
Author: ecn
Date: Fri Jul 6 13:41:02 2012
New Revision: 1358206
URL: http://svn.apache.org/viewvc?rev=1358206&view=rev
Log:
ACCUMULO-665 update AndIterator to seek to the right column families
Modified:
accumulo/branches/1.4/src/examples/wikisearch/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java
Modified: accumulo/branches/1.4/src/examples/wikisearch/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/examples/wikisearch/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java?rev=1358206&r1=1358205&r2=1358206&view=diff
==============================================================================
--- accumulo/branches/1.4/src/examples/wikisearch/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java (original)
+++ accumulo/branches/1.4/src/examples/wikisearch/query/src/main/java/org/apache/accumulo/examples/wikisearch/iterator/AndIterator.java Fri Jul 6 13:41:02 2012
@@ -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 Sort
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 Sort
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 Sort
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 Sort
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 Sort
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 Sort
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 Sort
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 Sort
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 Sort
// 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 Sort
}
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 Sort
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 Sort
}
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 Sort
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) {