use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.
the class AbstractRTreeExamplesTest method rangeSearch.
protected void rangeSearch(IBinaryComparatorFactory[] cmpFactories, IIndexAccessor indexAccessor, ISerializerDeserializer[] fieldSerdes, ITupleReference key, ITupleReference minFilterTuple, ITupleReference maxFilterTuple) throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
String kString = TupleUtils.printTuple(key, fieldSerdes);
LOGGER.info("Range-Search using key: " + kString);
}
ITreeIndexCursor rangeCursor = (ITreeIndexCursor) indexAccessor.createSearchCursor(false);
MultiComparator cmp = RTreeUtils.getSearchMultiComparator(cmpFactories, key);
SearchPredicate rangePred;
if (minFilterTuple != null && maxFilterTuple != null) {
rangePred = new SearchPredicate(key, cmp, minFilterTuple, maxFilterTuple);
} else {
rangePred = new SearchPredicate(key, cmp);
}
indexAccessor.search(rangeCursor, rangePred);
try {
while (rangeCursor.hasNext()) {
rangeCursor.next();
ITupleReference frameTuple = rangeCursor.getTuple();
String rec = TupleUtils.printTuple(frameTuple, fieldSerdes);
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(rec);
}
}
} finally {
rangeCursor.close();
}
}
use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.
the class RTreeTestUtils method checkExpectedResults.
@Override
public void checkExpectedResults(ITreeIndexCursor cursor, Collection checkTuples, ISerializerDeserializer[] fieldSerdes, int keyFieldCount, Iterator<CheckTuple> checkIter) throws Exception {
int actualCount = 0;
try {
while (cursor.hasNext()) {
cursor.next();
ITupleReference tuple = cursor.getTuple();
RTreeCheckTuple checkTuple = (RTreeCheckTuple) createCheckTupleFromTuple(tuple, fieldSerdes, keyFieldCount);
if (!checkTuples.contains(checkTuple)) {
fail("Scan or range search returned unexpected answer: " + checkTuple.toString());
}
actualCount++;
}
if (actualCount < checkTuples.size()) {
fail("Scan or range search returned fewer answers than expected.\nExpected: " + checkTuples.size() + "\nActual : " + actualCount);
}
if (actualCount > checkTuples.size()) {
fail("Scan or range search returned more answers than expected.\nExpected: " + checkTuples.size() + "\nActual : " + actualCount);
}
} finally {
cursor.close();
}
}
use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.
the class OrderedIndexTestDriver method oneStringKeyAndValue.
@Test
public void oneStringKeyAndValue() throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("BTree " + getTestOpName() + " Test With One String Key And Value.");
}
ISerializerDeserializer[] fieldSerdes = { new UTF8StringSerializerDeserializer(), new UTF8StringSerializerDeserializer() };
// Range search in ["cbf", cc7"]
ITupleReference lowKey = TupleUtils.createTuple(fieldSerdes, "cbf");
ITupleReference highKey = TupleUtils.createTuple(fieldSerdes, "cc7");
for (BTreeLeafFrameType leafFrameType : leafFrameTypesToTest) {
runTest(fieldSerdes, 1, leafFrameType, lowKey, highKey, null, null);
}
}
use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.
the class OrderedIndexTestUtils method checkExpectedResults.
@Override
public void checkExpectedResults(ITreeIndexCursor cursor, Collection checkTuples, ISerializerDeserializer[] fieldSerdes, int keyFieldCount, Iterator<CheckTuple> checkIter) throws Exception {
int actualCount = 0;
try {
while (cursor.hasNext()) {
if (!checkIter.hasNext()) {
fail("Ordered scan returned more answers than expected.\nExpected: " + checkTuples.size());
}
cursor.next();
CheckTuple expectedTuple = checkIter.next();
ITupleReference tuple = cursor.getTuple();
compareActualAndExpected(tuple, expectedTuple, fieldSerdes);
actualCount++;
}
if (actualCount < checkTuples.size()) {
fail("Ordered scan returned fewer answers than expected.\nExpected: " + checkTuples.size() + "\nActual : " + actualCount);
}
} finally {
cursor.close();
}
}
use of org.apache.hyracks.dataflow.common.data.accessors.ITupleReference in project asterixdb by apache.
the class OrderedIndexTestUtils method checkPointSearches.
public void checkPointSearches(IIndexTestContext ictx) throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Testing Point Searches On All Expected Keys.");
}
OrderedIndexTestContext ctx = (OrderedIndexTestContext) ictx;
IIndexCursor searchCursor = ctx.getIndexAccessor().createSearchCursor(false);
ArrayTupleBuilder lowKeyBuilder = new ArrayTupleBuilder(ctx.getKeyFieldCount());
ArrayTupleReference lowKey = new ArrayTupleReference();
ArrayTupleBuilder highKeyBuilder = new ArrayTupleBuilder(ctx.getKeyFieldCount());
ArrayTupleReference highKey = new ArrayTupleReference();
RangePredicate rangePred = new RangePredicate(lowKey, highKey, true, true, null, null);
// BTree to verify the tuple can be reached.
for (CheckTuple checkTuple : ctx.getCheckTuples()) {
createTupleFromCheckTuple(checkTuple, lowKeyBuilder, lowKey, ctx.getFieldSerdes());
createTupleFromCheckTuple(checkTuple, highKeyBuilder, highKey, ctx.getFieldSerdes());
MultiComparator lowKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), lowKey);
MultiComparator highKeyCmp = BTreeUtils.getSearchMultiComparator(ctx.getComparatorFactories(), highKey);
rangePred.setLowKey(lowKey, true);
rangePred.setHighKey(highKey, true);
rangePred.setLowKeyComparator(lowKeyCmp);
rangePred.setHighKeyComparator(highKeyCmp);
ctx.getIndexAccessor().search(searchCursor, rangePred);
try {
// We expect exactly one answer.
if (searchCursor.hasNext()) {
searchCursor.next();
ITupleReference tuple = searchCursor.getTuple();
compareActualAndExpected(tuple, checkTuple, ctx.getFieldSerdes());
}
if (searchCursor.hasNext()) {
fail("Point search returned more than one answer.");
}
} finally {
searchCursor.close();
}
}
}
Aggregations