Search in sources :

Example 1 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class VespaBackEndSearcher method addMetaInfo.

protected void addMetaInfo(Query query, QueryPacketData queryPacketData, QueryResultPacket resultPacket, Result result, boolean fromCache) {
    result.setTotalHitCount(resultPacket.getTotalDocumentCount());
    // Grouping
    if (resultPacket.getGroupData() != null) {
        byte[] data = resultPacket.getGroupData();
        ArrayList<Grouping> list = new ArrayList<>();
        BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer(ByteBuffer.wrap(data)));
        int cnt = buf.getInt(null);
        for (int i = 0; i < cnt; i++) {
            Grouping g = new Grouping();
            g.deserialize(buf);
            list.add(g);
        }
        GroupingListHit hit = new GroupingListHit(list, getDocsumDefinitionSet(query));
        hit.setQuery(result.getQuery());
        hit.setSource(getName());
        hit.setSourceNumber(sourceNumber);
        hit.setQueryPacketData(queryPacketData);
        result.hits().add(hit);
    }
    if (resultPacket.getCoverageFeature()) {
        result.setCoverage(new Coverage(resultPacket.getCoverageDocs(), resultPacket.getActiveDocs(), resultPacket.getNodesReplied()).setSoonActive(resultPacket.getSoonActiveDocs()).setDegradedReason(resultPacket.getDegradedReason()).setNodesTried(resultPacket.getNodesQueried()));
    }
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) ArrayList(java.util.ArrayList) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping) Coverage(com.yahoo.search.result.Coverage)

Example 2 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class TensorField method decode.

@Override
public Tensor decode(ByteBuffer buffer) {
    int length = buffer.getInt();
    if (length == 0)
        return null;
    ByteBuffer contentBuffer = ByteBuffer.wrap(buffer.array(), buffer.arrayOffset() + buffer.position(), length);
    Tensor tensor = TypedBinaryFormat.decode(Optional.empty(), new GrowableByteBuffer(contentBuffer));
    buffer.position(buffer.position() + length);
    return tensor;
}
Also used : Tensor(com.yahoo.tensor.Tensor) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 3 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class Document method serialize.

public void serialize(OutputStream out) throws SerializationException {
    DocumentSerializer writer = DocumentSerializerFactory.create42(new GrowableByteBuffer(64 * 1024, 2.0f));
    writer.write(this);
    GrowableByteBuffer data = writer.getBuf();
    byte[] array;
    if (data.hasArray()) {
        // just get the array
        array = data.array();
    } else {
        // copy the bytebuffer into the array
        array = new byte[data.position()];
        int endPos = data.position();
        data.position(0);
        data.get(array);
        data.position(endPos);
    }
    try {
        out.write(array, 0, data.position());
    } catch (IOException ioe) {
        throw new SerializationException(ioe);
    }
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) IOException(java.io.IOException)

Example 4 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class SerializationTestUtils method deserializeDocument.

public static Document deserializeDocument(byte[] buf, TestDocumentFactory factory) {
    Document document = factory.createDocument();
    DocumentDeserializerFactory.create42(factory.typeManager(), new GrowableByteBuffer(ByteBuffer.wrap(buf))).read(document);
    return document;
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document)

Example 5 with GrowableByteBuffer

use of com.yahoo.io.GrowableByteBuffer in project vespa by vespa-engine.

the class VespaDocumentSerializerTestCase method incompressable_structs_are_serialized_without_buffer_size_overhead_bug.

@Test
public void incompressable_structs_are_serialized_without_buffer_size_overhead_bug() {
    CompressionFixture fixture = new CompressionFixture();
    Document doc = new Document(fixture.docType, "id:foo:map_of_structs::flarn");
    Struct nested = new Struct(fixture.nestedType);
    nested.setFieldValue("str", new StringFieldValue(CompressionFixture.COMPRESSABLE_STRING));
    MapFieldValue<StringFieldValue, Struct> map = new MapFieldValue<StringFieldValue, Struct>(fixture.mapType);
    // Only 1 struct added. Not enough redundant information that header struct containing map itself
    // can be compressed.
    map.put(new StringFieldValue("foo"), nested);
    doc.setFieldValue("map", map);
    GrowableByteBuffer buf = CompressionFixture.asSerialized(doc);
    // Explanation of arbitrary value: buffer copy bug meant that incompressable structs were all serialized
    // rounded up to 4096 bytes.
    assertTrue(buf.remaining() < 4096);
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Document(com.yahoo.document.Document) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Aggregations

GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)74 Test (org.junit.Test)34 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)18 Document (com.yahoo.document.Document)9 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)9 Field (com.yahoo.document.Field)8 ByteBuffer (java.nio.ByteBuffer)8 FileOutputStream (java.io.FileOutputStream)6 DocumentType (com.yahoo.document.DocumentType)5 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 AbstractTypesTest (com.yahoo.document.annotation.AbstractTypesTest)4 Raw (com.yahoo.document.datatypes.Raw)4 Struct (com.yahoo.document.datatypes.Struct)4 Grouping (com.yahoo.searchlib.aggregation.Grouping)4 Array (com.yahoo.document.datatypes.Array)3 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)3 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)3 FieldUpdate (com.yahoo.document.update.FieldUpdate)3 IOException (java.io.IOException)3