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);
}
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());
}
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();
}
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);
}
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}"));
}
Aggregations