use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference in project asterixdb by apache.
the class BTreeSearchCursorTest method nonUniqueFieldPrefixIndexTest.
@Test
public void nonUniqueFieldPrefixIndexTest() throws Exception {
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("TESTING RANGE SEARCH CURSOR ON NONUNIQUE FIELD-PREFIX COMPRESSED INDEX");
}
IBufferCache bufferCache = harness.getBufferCache();
// declare keys
int keyFieldCount = 2;
IBinaryComparatorFactory[] cmpFactories = new IBinaryComparatorFactory[keyFieldCount];
cmpFactories[0] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
cmpFactories[1] = PointableBinaryComparatorFactory.of(IntegerPointable.FACTORY);
ITreeIndexFrameFactory leafFrameFactory = new BTreeNSMLeafFrameFactory(tupleWriterFactory);
ITreeIndexFrameFactory interiorFrameFactory = new BTreeNSMInteriorFrameFactory(tupleWriterFactory);
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) leafFrameFactory.createFrame();
IBTreeInteriorFrame interiorFrame = (IBTreeInteriorFrame) interiorFrameFactory.createFrame();
IMetadataPageManager freePageManager = new LinkedMetaDataPageManager(bufferCache, metaFrameFactory);
BTree btree = new BTree(bufferCache, harness.getFileMapProvider(), freePageManager, interiorFrameFactory, leafFrameFactory, cmpFactories, fieldCount, harness.getFileReference());
btree.create();
btree.activate();
ArrayTupleBuilder tupleBuilder = new ArrayTupleBuilder(fieldCount);
ArrayTupleReference tuple = new ArrayTupleReference();
ITreeIndexAccessor indexAccessor = btree.createAccessor(TestOperationCallback.INSTANCE, TestOperationCallback.INSTANCE);
// generate keys
int numKeys = 50;
int maxKey = 10;
ArrayList<Integer> keys = new ArrayList<>();
for (int i = 0; i < numKeys; i++) {
int k = rnd.nextInt() % maxKey;
keys.add(k);
}
Collections.sort(keys);
// insert keys into btree
for (int i = 0; i < keys.size(); i++) {
TupleUtils.createIntegerTuple(tupleBuilder, tuple, keys.get(i), i);
tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
try {
indexAccessor.insert(tuple);
} catch (Exception e) {
e.printStackTrace();
}
}
int minSearchKey = -100;
int maxSearchKey = 100;
// forward searches
Assert.assertTrue(performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, true, true, false));
Assert.assertTrue(performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, false, true, false));
Assert.assertTrue(performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, true, false, false));
Assert.assertTrue(performSearches(keys, btree, leafFrame, interiorFrame, minSearchKey, maxSearchKey, true, true, false));
btree.deactivate();
btree.destroy();
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference in project asterixdb by apache.
the class LSMBTreeFilterMergeTestDriver method filterToMinMax.
private Pair<ITupleReference, ITupleReference> filterToMinMax(ILSMComponentFilter f) throws HyracksDataException {
ArrayTupleBuilder builder = new ArrayTupleBuilder(1);
builder.addField(f.getMinTuple().getFieldData(0), f.getMinTuple().getFieldStart(0), f.getMinTuple().getFieldLength(0));
ArrayTupleReference minCopy = new ArrayTupleReference();
minCopy.reset(builder.getFieldEndOffsets(), builder.getByteArray());
builder = new ArrayTupleBuilder(1);
builder.addField(f.getMaxTuple().getFieldData(0), f.getMaxTuple().getFieldStart(0), f.getMaxTuple().getFieldLength(0));
ArrayTupleReference maxCopy = new ArrayTupleReference();
maxCopy.reset(builder.getFieldEndOffsets(), builder.getByteArray());
builder.reset();
return Pair.of(minCopy, maxCopy);
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference in project asterixdb by apache.
the class TupleUtils method createDoubleTuple.
public static ITupleReference createDoubleTuple(final double... fields) throws HyracksDataException {
ArrayTupleBuilder tupleBuilder = new ArrayTupleBuilder(fields.length);
ArrayTupleReference tuple = new ArrayTupleReference();
createDoubleTuple(tupleBuilder, tuple, fields);
return tuple;
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference in project asterixdb by apache.
the class TupleUtils method copyTuple.
public static ITupleReference copyTuple(ITupleReference tuple) throws HyracksDataException {
ArrayTupleBuilder tupleBuilder = new ArrayTupleBuilder(tuple.getFieldCount());
for (int i = 0; i < tuple.getFieldCount(); i++) {
tupleBuilder.addField(tuple.getFieldData(i), tuple.getFieldStart(i), tuple.getFieldLength(i));
}
ArrayTupleReference tupleCopy = new ArrayTupleReference();
tupleCopy.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
return tupleCopy;
}
use of org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference in project asterixdb by apache.
the class TupleUtils method createIntegerTuple.
public static ITupleReference createIntegerTuple(boolean filtered, final int... fields) throws HyracksDataException {
ArrayTupleBuilder tupleBuilder = filtered ? new ArrayTupleBuilder(fields.length + 1) : new ArrayTupleBuilder(fields.length);
ArrayTupleReference tuple = new ArrayTupleReference();
createIntegerTuple(tupleBuilder, tuple, fields);
return tuple;
}
Aggregations