Search in sources :

Example 6 with TensorFieldValue

use of com.yahoo.document.datatypes.TensorFieldValue in project vespa by vespa-engine.

the class TensorFieldValueSerializationTestCase method requireThatSerializationMatchesCpp.

@Test
public void requireThatSerializationMatchesCpp() throws IOException {
    assertSerializationMatchesCpp("non_existing_tensor", new TensorFieldValue(tensorType));
    assertSerializationMatchesCpp("empty_tensor", createTensor(tensorType, "{}"));
    assertSerializationMatchesCpp("multi_cell_tensor", createTensor(tensorType, "{{dimX:a,dimY:bb}:2.0,{dimX:ccc,dimY:dddd}:3.0,{dimX:e,dimY:ff}:5.0}"));
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Test(org.junit.Test)

Example 7 with TensorFieldValue

use of com.yahoo.document.datatypes.TensorFieldValue in project vespa by vespa-engine.

the class JsonWriterTestCase method testWritingOfTensorFieldValueWithoutTensor.

@Test
public void testWritingOfTensorFieldValueWithoutTensor() throws IOException {
    DocumentType documentTypeWithTensor = types.getDocumentType("testtensor");
    String docId = "id:unittest:testtensor::0";
    Document doc = new Document(documentTypeWithTensor, docId);
    Field tensorField = documentTypeWithTensor.getField("tensorfield");
    doc.setFieldValue(tensorField, new TensorFieldValue(((TensorDataType) tensorField.getDataType()).getTensorType()));
    assertEqualJson(asDocument(docId, "{ \"tensorfield\": {} }"), JsonWriter.toByteArray(doc));
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 8 with TensorFieldValue

use of com.yahoo.document.datatypes.TensorFieldValue in project vespa by vespa-engine.

the class CompositeReader method populateComposite.

// TODO createComposite is extremely similar to add/remove, refactor
// yes, this suppresswarnings ugliness is by intention, the code relies on the contracts in the builders
@SuppressWarnings({ "cast", "rawtypes" })
public static void populateComposite(TokenBuffer buffer, FieldValue fieldValue) {
    JsonToken token = buffer.currentToken();
    if ((token != JsonToken.START_OBJECT) && (token != JsonToken.START_ARRAY)) {
        throw new IllegalArgumentException("Expected '[' or '{'. Got '" + token + "'.");
    }
    if (fieldValue instanceof CollectionFieldValue) {
        DataType valueType = ((CollectionFieldValue) fieldValue).getDataType().getNestedType();
        if (fieldValue instanceof WeightedSet) {
            fillWeightedSet(buffer, valueType, (WeightedSet) fieldValue);
        } else {
            fillArray(buffer, (CollectionFieldValue) fieldValue, valueType);
        }
    } else if (fieldValue instanceof MapFieldValue) {
        MapReader.fillMap(buffer, (MapFieldValue) fieldValue);
    } else if (fieldValue instanceof StructuredFieldValue) {
        StructReader.fillStruct(buffer, (StructuredFieldValue) fieldValue);
    } else if (fieldValue instanceof TensorFieldValue) {
        TensorReader.fillTensor(buffer, (TensorFieldValue) fieldValue);
    } else {
        throw new IllegalStateException("Has created a composite field" + " value the reader does not know how to handle: " + fieldValue.getClass().getName() + " This is a bug. token = " + token);
    }
    expectCompositeEnd(buffer.currentToken());
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) DataType(com.yahoo.document.DataType) JsonToken(com.fasterxml.jackson.core.JsonToken) WeightedSet(com.yahoo.document.datatypes.WeightedSet) WeightedSetReader.fillWeightedSet(com.yahoo.document.json.readers.WeightedSetReader.fillWeightedSet)

Aggregations

TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)8 Test (org.junit.Test)5 Document (com.yahoo.document.Document)3 JsonToken (com.fasterxml.jackson.core.JsonToken)1 DataType (com.yahoo.document.DataType)1 DocumentType (com.yahoo.document.DocumentType)1 Field (com.yahoo.document.Field)1 TensorDataType (com.yahoo.document.TensorDataType)1 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 WeightedSetReader.fillWeightedSet (com.yahoo.document.json.readers.WeightedSetReader.fillWeightedSet)1 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)1 FastHit (com.yahoo.prelude.fastsearch.FastHit)1 JSONString (com.yahoo.prelude.hitfield.JSONString)1 Result (com.yahoo.search.Result)1 Hit (com.yahoo.search.result.Hit)1