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