/**
* Scan the index with a matching expression
*/
IdxScan idxScan = new IdxScan();
idxScan.addFamily(family);
idxScan.setExpression(Comparison.comparison(family, qualLong,
Comparison.Operator.EQ, Bytes.toBytes(42L)));
if (!memStoreEmpty) {
idxScan.setFilter(new SingleColumnValueFilter(family, qualLong,
CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes(42L))));
}
scanner = region.getScanner(idxScan);
res.clear();
//long start = System.nanoTime();
while (scanner.next(res)) ;
//long end = System.nanoTime();
//System.out.println("memStoreEmpty=" + memStoreEmpty + ", time=" + (end - start) / 1000000D);
assertEquals(numColumns, res.size());
for (KeyValue kv : res) {
if (Bytes.equals(kv.getQualifier(), qualLong)) {
assertEquals(42L, Bytes.toLong(kv.getValue()));
}
}
/**
* Scan the index with a non matching expression
*/
idxScan = new IdxScan();
idxScan.addFamily(family);
idxScan.setExpression(Comparison.comparison(family, qualLong,
Comparison.Operator.EQ, Bytes.toBytes(1000000000L)));
if (!memStoreEmpty) {
idxScan.setFilter(new SingleColumnValueFilter(family, qualLong,
CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes(1000000000L))));
}
scanner = region.getScanner(idxScan);
res.clear();
while (scanner.next(res)) ;
assertEquals(0, res.size());
/**
* Scan for all the records which are greater than 49499
*/
idxScan = new IdxScan();
idxScan.addFamily(family);
long min = numRows - 500L;
idxScan.setExpression(Comparison.comparison(family, qualLong,
Comparison.Operator.GTE, Bytes.toBytes(min)));
if (!memStoreEmpty) {
idxScan.setFilter(new SingleColumnValueFilter(family, qualLong,
CompareFilter.CompareOp.GREATER_OR_EQUAL,
new BinaryComparator(Bytes.toBytes(min))));
}
scanner = region.getScanner(idxScan);
res.clear();
//long start = System.nanoTime();
while (scanner.next(res)) ;
//long end = System.nanoTime();
//System.out.println("scan for val >= min memStoreEmpty=" + memStoreEmpty + ", time=" + (end - start)/1000000D);
assertEquals(500 * numColumns, res.size());
/**
* Scan for all the records which are greater than 49499
*/
idxScan = new IdxScan();
idxScan.addFamily(family);
min = numRows / 2;
long delta = 100;
long max = min + delta;
idxScan.setExpression(
And.and(Comparison.comparison(family, qualLong, Comparison.Operator.GTE, Bytes.toBytes(min)),
Comparison.comparison(family, qualLong, Comparison.Operator.LT, Bytes.toBytes(max))));
if (!memStoreEmpty) {
idxScan.setFilter(new FilterList(Arrays.<Filter>asList(
new SingleColumnValueFilter(family, qualLong, CompareFilter.CompareOp.GREATER_OR_EQUAL,
new BinaryComparator(Bytes.toBytes(min))),
new SingleColumnValueFilter(family, qualLong, CompareFilter.CompareOp.LESS,
new BinaryComparator(Bytes.toBytes(max))))
));