Search in sources :

Example 36 with Field

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);
}
Also used : Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) DocumentType(com.yahoo.document.DocumentType) TensorType(com.yahoo.tensor.TensorType)

Example 37 with Field

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));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 38 with Field

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()));
    }
}
Also used : Field(com.yahoo.document.Field) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Map(java.util.Map)

Example 39 with Field

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);
}
Also used : Field(com.yahoo.document.Field) FieldReader(com.yahoo.document.serialization.FieldReader) Test(org.junit.Test)

Example 40 with Field

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);
}
Also used : Field(com.yahoo.document.Field) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Aggregations

Field (com.yahoo.document.Field)115 Test (org.junit.Test)50 StructDataType (com.yahoo.document.StructDataType)46 DocumentType (com.yahoo.document.DocumentType)24 DataType (com.yahoo.document.DataType)17 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)14 ReferenceDataType (com.yahoo.document.ReferenceDataType)13 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)13 ArrayDataType (com.yahoo.document.ArrayDataType)12 MapDataType (com.yahoo.document.MapDataType)12 TensorDataType (com.yahoo.document.TensorDataType)11 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)11 SDField (com.yahoo.searchdefinition.document.SDField)10 PositionDataType (com.yahoo.document.PositionDataType)9 FieldValue (com.yahoo.document.datatypes.FieldValue)9 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)9 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)8 Struct (com.yahoo.document.datatypes.Struct)7 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)6 Document (com.yahoo.document.Document)5