Search in sources :

Example 1 with CheckTuple

use of org.apache.hyracks.storage.am.common.CheckTuple in project asterixdb by apache.

the class OrderedIndexTestUtils method bulkLoadStringTuples.

@SuppressWarnings("unchecked")
public void bulkLoadStringTuples(IIndexTestContext ctx, int numTuples, boolean filtered, Random rnd) throws Exception {
    int fieldCount = ctx.getFieldCount();
    int numKeyFields = ctx.getKeyFieldCount();
    String[] fieldValues = new String[fieldCount];
    TreeSet<CheckTuple> tmpCheckTuples = new TreeSet<>();
    for (int i = 0; i < numTuples; i++) {
        // Set keys.
        for (int j = 0; j < numKeyFields; j++) {
            int length = (Math.abs(rnd.nextInt()) % 10) + 1;
            fieldValues[j] = getRandomString(length, rnd);
        }
        // Set values.
        for (int j = numKeyFields; j < fieldCount; j++) {
            fieldValues[j] = getRandomString(5, rnd);
        }
        // Set expected values. We also use these as the pre-sorted stream
        // for bulk loading.
        ctx.insertCheckTuple(createStringCheckTuple(fieldValues, ctx.getKeyFieldCount()), tmpCheckTuples);
    }
    bulkLoadCheckTuples(ctx, tmpCheckTuples, filtered);
    // Add tmpCheckTuples to ctx check tuples for comparing searches.
    for (CheckTuple checkTuple : tmpCheckTuples) {
        ctx.insertCheckTuple(checkTuple, ctx.getCheckTuples());
    }
}
Also used : CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) TreeSet(java.util.TreeSet)

Example 2 with CheckTuple

use of org.apache.hyracks.storage.am.common.CheckTuple in project asterixdb by apache.

the class OrderedIndexTestUtils method getPrefixExpectedSubset.

@SuppressWarnings("unchecked")
public static // work.
SortedSet<CheckTuple> getPrefixExpectedSubset(TreeSet<CheckTuple> checkTuples, CheckTuple lowKey, CheckTuple highKey) {
    lowKey.setIsHighKey(false);
    highKey.setIsHighKey(true);
    CheckTuple low = checkTuples.ceiling(lowKey);
    CheckTuple high = checkTuples.floor(highKey);
    if (low == null || high == null) {
        // Must be empty.
        return new TreeSet<>();
    }
    if (high.compareTo(low) < 0) {
        // Must be empty.
        return new TreeSet<>();
    }
    return checkTuples.subSet(low, true, high, true);
}
Also used : CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) TreeSet(java.util.TreeSet)

Example 3 with CheckTuple

use of org.apache.hyracks.storage.am.common.CheckTuple in project asterixdb by apache.

the class OrderedIndexTestUtils method insertSortedIntTuples.

@SuppressWarnings("unchecked")
public void insertSortedIntTuples(IIndexTestContext ctx, int numTuples, Random rnd) throws Exception {
    int fieldCount = ctx.getFieldCount();
    int numKeyFields = ctx.getKeyFieldCount();
    int[] fieldValues = new int[ctx.getFieldCount()];
    int maxValue = (int) Math.ceil(Math.pow(numTuples, 1.0 / numKeyFields));
    Collection<CheckTuple> tmpCheckTuples = createCheckTuplesCollection();
    for (int i = 0; i < numTuples; i++) {
        // Set keys.
        setIntKeyFields(fieldValues, numKeyFields, maxValue, rnd);
        // Set values.
        setIntPayloadFields(fieldValues, numKeyFields, fieldCount);
        // Set expected values. (We also use these as the pre-sorted stream
        // for ordered indexes bulk loading).
        ctx.insertCheckTuple(createIntCheckTuple(fieldValues, ctx.getKeyFieldCount()), tmpCheckTuples);
    }
    insertCheckTuples(ctx, tmpCheckTuples);
    // Add tmpCheckTuples to ctx check tuples for comparing searches.
    for (CheckTuple checkTuple : tmpCheckTuples) {
        ctx.insertCheckTuple(checkTuple, ctx.getCheckTuples());
    }
}
Also used : CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple)

Example 4 with CheckTuple

use of org.apache.hyracks.storage.am.common.CheckTuple 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();
    }
}
Also used : CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 5 with CheckTuple

use of org.apache.hyracks.storage.am.common.CheckTuple in project asterixdb by apache.

the class OrderedIndexTestUtils method insertSortedStringTuples.

@SuppressWarnings("unchecked")
public void insertSortedStringTuples(IIndexTestContext ctx, int numTuples, Random rnd) throws Exception {
    int fieldCount = ctx.getFieldCount();
    int numKeyFields = ctx.getKeyFieldCount();
    String[] fieldValues = new String[fieldCount];
    TreeSet<CheckTuple> tmpCheckTuples = new TreeSet<>();
    for (int i = 0; i < numTuples; i++) {
        // Set keys.
        for (int j = 0; j < numKeyFields; j++) {
            int length = (Math.abs(rnd.nextInt()) % 10) + 1;
            fieldValues[j] = getRandomString(length, rnd);
        }
        // Set values.
        for (int j = numKeyFields; j < fieldCount; j++) {
            fieldValues[j] = getRandomString(5, rnd);
        }
        // Set expected values. We also use these as the pre-sorted stream
        // for bulk loading.
        ctx.insertCheckTuple(createStringCheckTuple(fieldValues, ctx.getKeyFieldCount()), tmpCheckTuples);
    }
    insertCheckTuples(ctx, tmpCheckTuples);
    // Add tmpCheckTuples to ctx check tuples for comparing searches.
    for (CheckTuple checkTuple : tmpCheckTuples) {
        ctx.insertCheckTuple(checkTuple, ctx.getCheckTuples());
    }
}
Also used : CheckTuple(org.apache.hyracks.storage.am.common.CheckTuple) TreeSet(java.util.TreeSet)

Aggregations

CheckTuple (org.apache.hyracks.storage.am.common.CheckTuple)18 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)8 TreeSet (java.util.TreeSet)6 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)6 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)6 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)4 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)3 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)3 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInput (java.io.DataInput)2 DataInputStream (java.io.DataInputStream)2 IInvertedIndex (org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedIndex)2 IInvertedIndexAccessor (org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedIndexAccessor)2 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)1 GrowableArray (org.apache.hyracks.data.std.util.GrowableArray)1 PermutingTupleReference (org.apache.hyracks.storage.am.common.tuples.PermutingTupleReference)1 IInvertedListCursor (org.apache.hyracks.storage.am.lsm.invertedindex.api.IInvertedListCursor)1 IToken (org.apache.hyracks.storage.am.lsm.invertedindex.tokenizers.IToken)1 IIndexBulkLoader (org.apache.hyracks.storage.common.IIndexBulkLoader)1