use of com.yahoo.document.Field in project vespa by vespa-engine.
the class JsonWriterTestCase method registerTensorDocumentType.
private void registerTensorDocumentType() {
DocumentType x = new DocumentType("testtensor");
TensorType tensorType = new TensorType.Builder().mapped("x").mapped("y").build();
x.addField(new Field("tensorfield", new TensorDataType(tensorType)));
types.registerDocumentType(x);
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class MapTestCase method testAdvancedMap.
public void testAdvancedMap() {
MapDataType stringMapType1 = new MapDataType(DataType.STRING, DataType.STRING);
MapDataType stringMapType2 = new MapDataType(DataType.STRING, DataType.STRING);
MapFieldValue sm1 = stringMapType1.createFieldValue();
MapFieldValue sm2 = stringMapType2.createFieldValue();
StringFieldValue e = new StringFieldValue("e");
StringFieldValue g = new StringFieldValue("g");
sm1.put(new StringFieldValue("a"), new StringFieldValue("b"));
sm1.put(new StringFieldValue("c"), new StringFieldValue("d"));
sm2.put(e, new StringFieldValue("f"));
sm2.put(g, new StringFieldValue("h"));
StructDataType structType = new StructDataType("teststr");
structType.addField(new Field("int", DataType.INT));
structType.addField(new Field("flt", DataType.FLOAT));
Struct s = structType.createFieldValue();
s.setFieldValue("int", 99);
s.setFieldValue("flt", -89.345);
ArrayDataType twoDimArray = DataType.getArray(DataType.getArray(DataType.FLOAT));
Array tda = twoDimArray.createFieldValue();
MapDataType floatToTwoDimArray = new MapDataType(DataType.FLOAT, twoDimArray);
MapDataType stringToStruct = new MapDataType(DataType.STRING, structType);
MapDataType stringMapToStringMap = new MapDataType(stringMapType1, stringMapType2);
MapFieldValue f2tda = floatToTwoDimArray.createFieldValue();
f2tda.put(new FloatFieldValue(3.4f), tda);
MapFieldValue s2sct = stringToStruct.createFieldValue();
s2sct.put(new StringFieldValue("s1"), s);
MapFieldValue sm2sm = stringMapToStringMap.createFieldValue();
sm2sm.put(sm1, sm2);
assertEquals(f2tda.get(new FloatFieldValue(3.4f)), tda);
assertEquals(new IntegerFieldValue(99), ((Struct) (s2sct.get(new StringFieldValue("s1")))).getFieldValue("int"));
assertEquals(new StringFieldValue("f"), ((MapFieldValue) (sm2sm.get(sm1))).get(e));
assertEquals(new StringFieldValue("h"), ((MapFieldValue) (sm2sm.get(sm1))).get(g));
// Look up using different map w same contents
// TODO it works even if sm1_2 is empty, something with class id?
MapFieldValue sm1_2 = stringMapType1.createFieldValue();
sm1_2.put(new StringFieldValue("a"), new StringFieldValue("b"));
sm1_2.put(new StringFieldValue("c"), new StringFieldValue("d"));
assertEquals(new StringFieldValue("f"), ((MapFieldValue) (sm2sm.get(sm1_2))).get(e));
assertEquals(new StringFieldValue("h"), ((MapFieldValue) (sm2sm.get(sm1_2))).get(g));
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class MapTestCase method assertCorrectSerialization.
private void assertCorrectSerialization(MapDataType mapType, MapFieldValue<? extends FieldValue, ? extends FieldValue> map) {
Field f = new Field("", mapType);
DocumentTypeManager man = new DocumentTypeManager();
man.register(mapType);
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
serializer.write(f, map);
buffer.flip();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
MapFieldValue<FieldValue, FieldValue> map2 = new MapFieldValue<FieldValue, FieldValue>(mapType);
deserializer.read(f, map2);
assertNotSame(map, map2);
for (Map.Entry<?, ?> e : map.entrySet()) {
assertEquals(e.getValue(), map2.get(e.getKey()));
}
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class PredicateFieldValueTest method requireThatDeserializeCallsBackToReader.
@Test
public void requireThatDeserializeCallsBackToReader() {
Field field = Mockito.mock(Field.class);
FieldReader reader = Mockito.mock(FieldReader.class);
PredicateFieldValue value = new PredicateFieldValue(SimplePredicates.newPredicate());
value.deserialize(field, reader);
Mockito.verify(reader).read(field, value);
}
use of com.yahoo.document.Field in project vespa by vespa-engine.
the class StringTestCase method serializeAndAssert.
private void serializeAndAssert(StringFieldValue stringFieldValue) {
Field f = new Field("text", DataType.STRING);
GrowableByteBuffer buffer = new GrowableByteBuffer(1024);
DocumentSerializer serializer = DocumentSerializerFactory.create42(buffer);
serializer.write(f, stringFieldValue);
buffer.flip();
DocumentDeserializer deserializer = DocumentDeserializerFactory.create42(man, buffer);
StringFieldValue stringFieldValue2 = new StringFieldValue();
deserializer.read(f, stringFieldValue2);
assertEquals(stringFieldValue, stringFieldValue2);
assertNotSame(stringFieldValue, stringFieldValue2);
}
Aggregations