Search in sources :

Example 1 with IFieldValueGenerator

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

the class LSMBTreeTuplesTest method testLSMBTreeTuple.

private void testLSMBTreeTuple(ISerializerDeserializer[] maxFieldSerdes) throws HyracksDataException {
    // Create a tuple with the max-1 fields for checking setFieldCount() of tuple references later.
    ITypeTraits[] maxTypeTraits = SerdeUtils.serdesToTypeTraits(maxFieldSerdes);
    IFieldValueGenerator[] maxFieldGens = DataGenUtils.getFieldGensFromSerdes(maxFieldSerdes, rnd, false);
    // Generate a tuple with random field values.
    Object[] maxFields = new Object[maxFieldSerdes.length];
    for (int j = 0; j < maxFieldSerdes.length; j++) {
        maxFields[j] = maxFieldGens[j].next();
    }
    // Run test for varying number of fields and keys.
    for (int numKeyFields = 1; numKeyFields < maxFieldSerdes.length; numKeyFields++) {
        // Create tuples with varying number of fields, and try to interpret their bytes with the lsmBTreeTuple.
        for (int numFields = numKeyFields; numFields <= maxFieldSerdes.length; numFields++) {
            // Create and write tuple to bytes using an LSMBTreeTupleWriter.
            LSMBTreeTupleWriter maxMatterTupleWriter = new LSMBTreeTupleWriter(maxTypeTraits, numKeyFields, false);
            ITupleReference maxTuple = TupleUtils.createTuple(maxFieldSerdes, (Object[]) maxFields);
            ByteBuffer maxMatterBuf = writeTuple(maxTuple, maxMatterTupleWriter);
            // Tuple reference should work for both matter and antimatter tuples (doesn't matter which factory creates it).
            LSMBTreeTupleReference maxLsmBTreeTuple = (LSMBTreeTupleReference) maxMatterTupleWriter.createTupleReference();
            ISerializerDeserializer[] fieldSerdes = Arrays.copyOfRange(maxFieldSerdes, 0, numFields);
            ITypeTraits[] typeTraits = SerdeUtils.serdesToTypeTraits(fieldSerdes);
            IFieldValueGenerator[] fieldGens = DataGenUtils.getFieldGensFromSerdes(fieldSerdes, rnd, false);
            // Generate a tuple with random field values.
            Object[] fields = new Object[numFields];
            for (int j = 0; j < numFields; j++) {
                fields[j] = fieldGens[j].next();
            }
            // Create and write tuple to bytes using an LSMBTreeTupleWriter.
            ITupleReference tuple = TupleUtils.createTuple(fieldSerdes, (Object[]) fields);
            LSMBTreeTupleWriter matterTupleWriter = new LSMBTreeTupleWriter(typeTraits, numKeyFields, false);
            LSMBTreeTupleWriter antimatterTupleWriter = new LSMBTreeTupleWriter(typeTraits, numKeyFields, true);
            LSMBTreeCopyTupleWriter copyTupleWriter = new LSMBTreeCopyTupleWriter(typeTraits, numKeyFields);
            ByteBuffer matterBuf = writeTuple(tuple, matterTupleWriter);
            ByteBuffer antimatterBuf = writeTuple(tuple, antimatterTupleWriter);
            // The antimatter buf should only contain keys, sanity check the size.
            if (numFields != numKeyFields) {
                assertTrue(antimatterBuf.array().length < matterBuf.array().length);
            }
            // Tuple reference should work for both matter and antimatter tuples (doesn't matter which factory creates it).
            LSMBTreeTupleReference lsmBTreeTuple = (LSMBTreeTupleReference) matterTupleWriter.createTupleReference();
            // Repeat the block inside to test that repeated resetting to matter/antimatter tuples works.
            for (int r = 0; r < 4; r++) {
                // Check matter tuple with lsmBTreeTuple.
                lsmBTreeTuple.resetByTupleOffset(matterBuf.array(), 0);
                checkTuple(lsmBTreeTuple, numFields, false, fieldSerdes, fields);
                // Create a copy using copyTupleWriter, and verify again.
                ByteBuffer copyMatterBuf = writeTuple(lsmBTreeTuple, copyTupleWriter);
                lsmBTreeTuple.resetByTupleOffset(copyMatterBuf.array(), 0);
                checkTuple(lsmBTreeTuple, numFields, false, fieldSerdes, fields);
                // Check antimatter tuple with lsmBTreeTuple.
                lsmBTreeTuple.resetByTupleOffset(antimatterBuf.array(), 0);
                // Should only contain keys.
                checkTuple(lsmBTreeTuple, numKeyFields, true, fieldSerdes, fields);
                // Create a copy using copyTupleWriter, and verify again.
                ByteBuffer copyAntimatterBuf = writeTuple(lsmBTreeTuple, copyTupleWriter);
                lsmBTreeTuple.resetByTupleOffset(copyAntimatterBuf.array(), 0);
                // Should only contain keys.
                checkTuple(lsmBTreeTuple, numKeyFields, true, fieldSerdes, fields);
                // Check matter tuple with maxLsmBTreeTuple.
                // We should be able to manually set a prefix of the fields
                // (the passed type traits in the tuple factory's constructor).
                maxLsmBTreeTuple.setFieldCount(numFields);
                maxLsmBTreeTuple.resetByTupleOffset(matterBuf.array(), 0);
                checkTuple(maxLsmBTreeTuple, numFields, false, fieldSerdes, fields);
                // Check antimatter tuple with maxLsmBTreeTuple.
                maxLsmBTreeTuple.resetByTupleOffset(antimatterBuf.array(), 0);
                // Should only contain keys.
                checkTuple(maxLsmBTreeTuple, numKeyFields, true, fieldSerdes, fields);
                // Resetting maxLsmBTreeTuple should set its field count to
                // maxFieldSerdes.length, based on the its type traits.
                maxLsmBTreeTuple.resetByTupleOffset(maxMatterBuf.array(), 0);
                checkTuple(maxLsmBTreeTuple, maxFieldSerdes.length, false, maxFieldSerdes, maxFields);
            }
        }
    }
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) IFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.IFieldValueGenerator) ByteBuffer(java.nio.ByteBuffer) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 2 with IFieldValueGenerator

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

the class LSMInvertedIndexTestUtils method createStringDocumentTupleGen.

public static TupleGenerator createStringDocumentTupleGen(Random rnd) throws IOException {
    IFieldValueGenerator[] fieldGens = new IFieldValueGenerator[2];
    fieldGens[0] = new DocumentStringFieldValueGenerator(2, 10, 10000, rnd);
    fieldGens[1] = new SortedIntegerFieldValueGenerator(0);
    ISerializerDeserializer[] fieldSerdes = new ISerializerDeserializer[] { new UTF8StringSerializerDeserializer(), IntegerSerializerDeserializer.INSTANCE };
    TupleGenerator tupleGen = new TupleGenerator(fieldGens, fieldSerdes, 0);
    return tupleGen;
}
Also used : SortedIntegerFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.SortedIntegerFieldValueGenerator) IFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.IFieldValueGenerator) TupleGenerator(org.apache.hyracks.storage.am.common.datagen.TupleGenerator) UTF8StringSerializerDeserializer(org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer) DocumentStringFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.DocumentStringFieldValueGenerator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 3 with IFieldValueGenerator

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

the class LSMInvertedIndexTestUtils method createPersonNamesTupleGen.

public static TupleGenerator createPersonNamesTupleGen(Random rnd) throws IOException {
    IFieldValueGenerator[] fieldGens = new IFieldValueGenerator[2];
    fieldGens[0] = new PersonNameFieldValueGenerator(rnd, 0.5f);
    fieldGens[1] = new SortedIntegerFieldValueGenerator(0);
    ISerializerDeserializer[] fieldSerdes = new ISerializerDeserializer[] { new UTF8StringSerializerDeserializer(), IntegerSerializerDeserializer.INSTANCE };
    TupleGenerator tupleGen = new TupleGenerator(fieldGens, fieldSerdes, 0);
    return tupleGen;
}
Also used : SortedIntegerFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.SortedIntegerFieldValueGenerator) PersonNameFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.PersonNameFieldValueGenerator) IFieldValueGenerator(org.apache.hyracks.storage.am.common.datagen.IFieldValueGenerator) TupleGenerator(org.apache.hyracks.storage.am.common.datagen.TupleGenerator) UTF8StringSerializerDeserializer(org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Aggregations

ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)3 IFieldValueGenerator (org.apache.hyracks.storage.am.common.datagen.IFieldValueGenerator)3 UTF8StringSerializerDeserializer (org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer)2 SortedIntegerFieldValueGenerator (org.apache.hyracks.storage.am.common.datagen.SortedIntegerFieldValueGenerator)2 TupleGenerator (org.apache.hyracks.storage.am.common.datagen.TupleGenerator)2 ByteBuffer (java.nio.ByteBuffer)1 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)1 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)1 DocumentStringFieldValueGenerator (org.apache.hyracks.storage.am.common.datagen.DocumentStringFieldValueGenerator)1 PersonNameFieldValueGenerator (org.apache.hyracks.storage.am.common.datagen.PersonNameFieldValueGenerator)1