use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder 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();
}
}
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder in project asterixdb by apache.
the class TreeIndexTestUtils method deleteTuples.
@SuppressWarnings("unchecked")
public void deleteTuples(IIndexTestContext ctx, int numTuples, Random rnd) throws Exception {
ArrayTupleBuilder deleteTupleBuilder = createDeleteTupleBuilder(ctx);
ArrayTupleReference deleteTuple = new ArrayTupleReference();
int numCheckTuples = ctx.getCheckTuples().size();
// Copy CheckTuple references into array, so we can randomly pick from
// there.
CheckTuple[] checkTuples = new CheckTuple[numCheckTuples];
int idx = 0;
Iterator<CheckTuple> iter = ctx.getCheckTuples().iterator();
while (iter.hasNext()) {
CheckTuple checkTuple = iter.next();
checkTuples[idx++] = checkTuple;
}
for (int i = 0; i < numTuples && numCheckTuples > 0; i++) {
if (LOGGER.isLoggable(Level.INFO)) {
if ((i + 1) % (numTuples / Math.min(10, numTuples)) == 0) {
LOGGER.info("Deleting Tuple " + (i + 1) + "/" + numTuples);
}
}
int checkTupleIdx = Math.abs(rnd.nextInt() % numCheckTuples);
CheckTuple checkTuple = checkTuples[checkTupleIdx];
createTupleFromCheckTuple(checkTuple, deleteTupleBuilder, deleteTuple, ctx.getFieldSerdes());
ctx.getIndexAccessor().delete(deleteTuple);
// Remove check tuple from expected results.
ctx.deleteCheckTuple(checkTuple, ctx.getCheckTuples());
// Swap with last "valid" CheckTuple.
CheckTuple tmp = checkTuples[numCheckTuples - 1];
checkTuples[numCheckTuples - 1] = checkTuple;
checkTuples[checkTupleIdx] = tmp;
numCheckTuples--;
}
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder in project asterixdb by apache.
the class TreeIndexTestUtils method addFilterField.
protected void addFilterField(IIndexTestContext ctx, MutablePair<ITupleReference, ITupleReference> minMax) throws HyracksDataException {
//Duplicate the PK field as a filter field at the end of the tuple to be inserted.
int filterField = ctx.getFieldCount();
ITupleReference currTuple = ctx.getTuple();
ArrayTupleBuilder filterBuilder = new ArrayTupleBuilder(1);
filterBuilder.addField(currTuple.getFieldData(filterField), currTuple.getFieldStart(filterField), currTuple.getFieldLength(filterField));
IBinaryComparator comparator = ctx.getComparatorFactories()[0].createBinaryComparator();
ArrayTupleReference filterOnlyTuple = new ArrayTupleReference();
filterOnlyTuple.reset(filterBuilder.getFieldEndOffsets(), filterBuilder.getByteArray());
if (minMax == null) {
minMax = MutablePair.of(filterOnlyTuple, filterOnlyTuple);
} else if (compareFilterTuples(minMax.getLeft(), filterOnlyTuple, comparator) > 0) {
minMax.setLeft(filterOnlyTuple);
} else if (compareFilterTuples(minMax.getRight(), filterOnlyTuple, comparator) < 0) {
minMax.setRight(filterOnlyTuple);
}
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder in project asterixdb by apache.
the class ExternalRTreeSearchOperatorNodePushable method open.
// We override this method to specify the searched version of the index
@Override
public void open() throws HyracksDataException {
writer.open();
accessor = new FrameTupleAccessor(inputRecDesc);
indexHelper.open();
index = indexHelper.getIndexInstance();
if (retainMissing) {
int fieldCount = getFieldCount();
nonMatchTupleBuild = new ArrayTupleBuilder(fieldCount);
DataOutput out = nonMatchTupleBuild.getDataOutput();
for (int i = 0; i < fieldCount; i++) {
try {
nonMatchWriter.writeMissing(out);
} catch (IOException e) {
throw new HyracksDataException(e);
}
nonMatchTupleBuild.addFieldEndOffset();
}
} else {
nonMatchTupleBuild = null;
}
ExternalRTree rTreeIndex = (ExternalRTree) index;
try {
searchPred = createSearchPredicate();
tb = new ArrayTupleBuilder(recordDesc.getFieldCount());
dos = tb.getDataOutput();
appender = new FrameTupleAppender(new VSizeFrame(ctx));
ISearchOperationCallback searchCallback = searchCallbackFactory.createSearchOperationCallback(indexHelper.getResource().getId(), ctx, null);
// The next line is the reason we override this method...
// The right thing to do would be to change the signature of createAccessor
indexAccessor = rTreeIndex.createAccessor(searchCallback, version);
cursor = createCursor();
if (retainInput) {
frameTuple = new FrameTupleReference();
}
} catch (Exception e) {
throw new HyracksDataException(e);
}
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder in project asterixdb by apache.
the class OnDiskInvertedIndex method validate.
@Override
public void validate() throws HyracksDataException {
btree.validate();
// Scan the btree and validate the order of elements in each inverted-list.
IIndexAccessor btreeAccessor = btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
IIndexCursor btreeCursor = btreeAccessor.createSearchCursor(false);
MultiComparator btreeCmp = MultiComparator.create(btree.getComparatorFactories());
RangePredicate rangePred = new RangePredicate(null, null, true, true, btreeCmp, btreeCmp);
int[] fieldPermutation = new int[tokenTypeTraits.length];
for (int i = 0; i < tokenTypeTraits.length; i++) {
fieldPermutation[i] = i;
}
PermutingTupleReference tokenTuple = new PermutingTupleReference(fieldPermutation);
IInvertedIndexAccessor invIndexAccessor = (IInvertedIndexAccessor) createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
IInvertedListCursor invListCursor = invIndexAccessor.createInvertedListCursor();
MultiComparator invListCmp = MultiComparator.create(invListCmpFactories);
try {
// Search key for finding an inverted-list in the actual index.
ArrayTupleBuilder prevBuilder = new ArrayTupleBuilder(invListTypeTraits.length);
ArrayTupleReference prevTuple = new ArrayTupleReference();
btreeAccessor.search(btreeCursor, rangePred);
while (btreeCursor.hasNext()) {
btreeCursor.next();
tokenTuple.reset(btreeCursor.getTuple());
// Validate inverted list by checking that the elements are totally ordered.
invIndexAccessor.openInvertedListCursor(invListCursor, tokenTuple);
invListCursor.pinPages();
try {
if (invListCursor.hasNext()) {
invListCursor.next();
ITupleReference invListElement = invListCursor.getTuple();
// Initialize prev tuple.
TupleUtils.copyTuple(prevBuilder, invListElement, invListElement.getFieldCount());
prevTuple.reset(prevBuilder.getFieldEndOffsets(), prevBuilder.getByteArray());
}
while (invListCursor.hasNext()) {
invListCursor.next();
ITupleReference invListElement = invListCursor.getTuple();
// Compare with previous element.
if (invListCmp.compare(invListElement, prevTuple) <= 0) {
throw new HyracksDataException("Index validation failed.");
}
// Set new prevTuple.
TupleUtils.copyTuple(prevBuilder, invListElement, invListElement.getFieldCount());
prevTuple.reset(prevBuilder.getFieldEndOffsets(), prevBuilder.getByteArray());
}
} finally {
invListCursor.unpinPages();
}
}
} finally {
btreeCursor.close();
}
}
Aggregations