Search in sources :

Example 1 with TensorFieldValue

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

the class JsonRendererTestCase method testDataTypes.

@Test
public void testDataTypes() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"double\": 0.00390625,\n" + "                    \"float\": 14.29,\n" + "                    \"integer\": 1,\n" + "                    \"long\": 4398046511104,\n" + "                    \"object\": \"thingie\",\n" + "                    \"string\": \"stuff\",\n" + "                    \"predicate\": \"a in [b]\",\n" + "                    \"tensor1\": { \"cells\": [ { \"address\": {\"x\": \"a\"}, \"value\":2.0 } ] },\n" + "                    \"tensor2\": { \"cells\": [] },\n" + "                    \"tensor3\": { \"cells\": [ { \"address\": {\"x\": \"a\", \"y\": \"0\"}, \"value\":2.0 }, { \"address\": {\"x\": \"a\", \"y\": \"1\"}, \"value\":-1.0 } ] }\n" + "                },\n" + "                \"id\": \"datatypestuff\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("datatypestuff");
    // the floating point values are chosen to get a deterministic string representation
    h.setField("double", 0.00390625d);
    h.setField("float", 14.29f);
    h.setField("integer", 1);
    h.setField("long", 4398046511104L);
    h.setField("string", "stuff");
    h.setField("predicate", Predicate.fromString("a in [b]"));
    h.setField("tensor1", new TensorFieldValue(Tensor.from("{ {x:a}: 2.0}")));
    h.setField("tensor2", new TensorFieldValue(TensorType.empty));
    h.setField("tensor3", Tensor.from("{ {x:a, y:0}: 2.0, {x:a, y:1}: -1 }"));
    h.setField("object", new Thingie());
    r.hits().add(h);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 2 with TensorFieldValue

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

the class JsonReaderTestCase method assertTensorAssignUpdate.

private static void assertTensorAssignUpdate(String expectedTensor, DocumentUpdate update) {
    assertEquals("testtensor", update.getId().getDocType());
    assertEquals(TENSOR_DOC_ID, update.getId().toString());
    AssignValueUpdate assignUpdate = (AssignValueUpdate) getTensorField(update).getValueUpdate(0);
    TensorFieldValue fieldValue = (TensorFieldValue) assignUpdate.getValue();
    assertEquals(Tensor.from(expectedTensor), fieldValue.getTensor().get());
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate)

Example 3 with TensorFieldValue

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

the class JsonReaderTestCase method assertTensorField.

private static Tensor assertTensorField(String expectedTensor, DocumentPut put, String tensorFieldName) {
    final Document doc = put.getDocument();
    assertEquals("testtensor", doc.getId().getDocType());
    assertEquals(TENSOR_DOC_ID, doc.getId().toString());
    TensorFieldValue fieldValue = (TensorFieldValue) doc.getFieldValue(doc.getField(tensorFieldName));
    assertEquals(Tensor.from(expectedTensor), fieldValue.getTensor().get());
    return fieldValue.getTensor().get();
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Document(com.yahoo.document.Document)

Example 4 with TensorFieldValue

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

the class JsonReaderTestCase method testParsingWithoutTensorField.

@Test
public void testParsingWithoutTensorField() {
    Document doc = createPutWithoutTensor().getDocument();
    assertEquals("testtensor", doc.getId().getDocType());
    assertEquals("id:unittest:testtensor::0", doc.getId().toString());
    TensorFieldValue fieldValue = (TensorFieldValue) doc.getFieldValue(doc.getField("mappedtensorfield"));
    assertNull(fieldValue);
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 5 with TensorFieldValue

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

the class TensorFieldValueSerializationTestCase method requireThatTensorFieldValueIsSerializedAndDeserialized.

@Test
public void requireThatTensorFieldValueIsSerializedAndDeserialized() {
    assertSerialization(new TensorFieldValue(tensorType));
    assertSerialization(createTensor(tensorType, "{}"));
    assertSerialization(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)

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