use of com.yahoo.document.BucketId in project vespa by vespa-engine.
the class BucketSelectorTestCase method assertBucket.
public void assertBucket(String expr, BucketId bucket) throws Exception {
BucketIdFactory factory = new BucketIdFactory();
BucketSelector selector = new BucketSelector(factory);
Set<BucketId> buckets = selector.getBucketList(expr);
assertEquals(1, buckets == null ? 0 : buckets.size());
assertEquals(bucket, buckets.toArray()[0]);
}
use of com.yahoo.document.BucketId in project vespa by vespa-engine.
the class BucketSelectorTestCase method testExpressions.
@Test
public void testExpressions() throws Exception {
assertBucketCount("id = \"userdoc:ns:123:foobar\"", 1);
assertBucketCount("id = \"userdoc:ns:123:foo*\"", 0);
assertBucketCount("id == \"userdoc:ns:123:f?oo*\"", 1);
assertBucketCount("id =~ \"userdoc:ns:123:foo*\"", 0);
assertBucketCount("id =~ \"userdoc:ns:123:foo?\"", 0);
assertBucketCount("id.user = 123", 1);
assertBucketCount("id.user == 123", 1);
assertBucketCount("id.group = \"yahoo.com\"", 1);
assertBucketCount("id.group = \"yahoo.com\" or id.user=123", 2);
assertBucketCount("id.group = \"yahoo.com\" and id.user=123", 0);
assertBucketCount("id.group = \"yahoo.com\" and testdoctype1.hstringval=\"Doe\"", 1);
assertBucketCount("not id.group = \"yahoo.com\"", 0);
assertBucketCount("id.group != \"yahoo.com\"", 0);
assertBucketCount("id.group <= \"yahoo.com\"", 0);
// Bucket 16:12312
assertBucketCount("id.bucket = 0x4000000000003018", 1);
// Bucket 16:600
assertBucketCount("id.bucket == 0x4000000000000258", 1);
assertBucketCount("searchcolumn.3 == 1", 21845);
// Check that the correct buckets is found
assertBucket("id.bucket = 0x4000000000003018", new BucketId(16, 12312));
assertBucket("id.bucket == 0x4000000000000258", new BucketId(16, 600));
assertBucket("id = \"userdoc:ns:123:foobar\"", new BucketId(0xeafff5320000007bL));
assertBucket("id.user = 123", new BucketId(32, 123));
assertBucket("id.group = \"yahoo.com\"", new BucketId(32, 0x035837189a1acd50L));
// Check that overlapping works
Set<BucketId> expected = new TreeSet<BucketId>();
expected.add(new BucketId(32, 123));
expected.add(new BucketId(16, 123));
assertBuckets("id.user == 123 or id.bucket == 0x400000000000007b", expected);
}
use of com.yahoo.document.BucketId in project vespa by vespa-engine.
the class BucketSelectorTestCase method assertBuckets.
public void assertBuckets(String expr, Set<BucketId> expected) throws Exception {
BucketIdFactory factory = new BucketIdFactory();
BucketSelector selector = new BucketSelector(factory);
Set<BucketId> actual = new TreeSet<BucketId>(selector.getBucketList(expr));
assertEquals(expected, actual);
}
use of com.yahoo.document.BucketId in project vespa by vespa-engine.
the class VisitorIterator method getNext.
/**
* @return The pair [superbucket, progress] that specifies the next iterable
* bucket. When a superbucket is initially returned, the pair is equal to
* that of [superbucket, 0], as there has been no progress into its sub-buckets
* yet (if they exist).
*
* Precondition: <code>hasNext() == true</code>
*/
public BucketProgress getNext() {
assert (progressToken.getDistributionBitCount() == bucketSource.getDistributionBitCount()) : "inconsistent distribution bit counts for progress and source";
assert (hasNext());
// the map too much
if (progressToken.hasPending()) {
// Find first pending bucket in token
TreeMap<ProgressToken.BucketKeyWrapper, ProgressToken.BucketEntry> buckets = progressToken.getBuckets();
ProgressToken.BucketEntry pending = null;
BucketId superbucket = null;
for (Map.Entry<ProgressToken.BucketKeyWrapper, ProgressToken.BucketEntry> entry : buckets.entrySet()) {
if (entry.getValue().getState() == ProgressToken.BucketState.BUCKET_PENDING) {
pending = entry.getValue();
superbucket = new BucketId(ProgressToken.keyToBucketId(entry.getKey().getKey()));
break;
}
}
assert (pending != null) : "getNext() called with inconsistent state";
// Set bucket to active, since it's not awaiting an update
pending.setState(ProgressToken.BucketState.BUCKET_ACTIVE);
progressToken.setActiveBucketCount(progressToken.getActiveBucketCount() + 1);
progressToken.setPendingBucketCount(progressToken.getPendingBucketCount() - 1);
return new BucketProgress(superbucket, pending.getProgress());
} else {
BucketProgress ret = bucketSource.getNext();
progressToken.addBucket(ret.getSuperbucket(), ret.getProgress(), ProgressToken.BucketState.BUCKET_ACTIVE);
return ret;
}
}
use of com.yahoo.document.BucketId in project vespa by vespa-engine.
the class VisitorIterator method createFromDocumentSelection.
/**
* Create a new <code>VisitorIterator</code> instance based on the given document
* selection string.
*
* @param documentSelection Document selection string used to create the
* <code>VisitorIterator</code> instance. Depending on the characteristics of the
* selection, the iterator may iterate over only a small subset of the buckets or
* every bucket in the system. Both cases will be handled efficiently.
* @param idFactory {@link BucketId} factory specifying the number of distribution bits
* to use et al.
* @param progress A unique {@link ProgressToken} instance which is used for maintaining the state
* of the iterator. Can <em>not</em> be shared with other iterator instances at the same time.
* If <code>progress</code> contains work done in an earlier iteration run, the iterator will pick
* up from where it left off
* @return A new <code>VisitorIterator</code> instance
* @throws ParseException if <code>documentSelection</code> fails to properly parse
*/
public static VisitorIterator createFromDocumentSelection(String documentSelection, BucketIdFactory idFactory, int distributionBitCount, ProgressToken progress) throws ParseException {
BucketSelector bucketSel = new BucketSelector(idFactory);
Set<BucketId> rawBuckets = bucketSel.getBucketList(documentSelection);
BucketSource src;
// bit-based range source
if (rawBuckets == null) {
// Range source
src = new DistributionRangeBucketSource(distributionBitCount, progress);
} else {
// Explicit source
src = new ExplicitBucketSource(rawBuckets, distributionBitCount, progress);
}
return new VisitorIterator(progress, src);
}
Aggregations