Search in sources :

Example 6 with MapDataType

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

the class DocumentModelBuilder method specialHandleAnnotationReferenceRecurse.

private static DataType specialHandleAnnotationReferenceRecurse(NewDocumentType docType, String fieldName, DataType dataType) {
    if (dataType instanceof TemporaryAnnotationReferenceDataType) {
        TemporaryAnnotationReferenceDataType refType = (TemporaryAnnotationReferenceDataType) dataType;
        if (refType.getId() != 0) {
            return null;
        }
        AnnotationType target = docType.getAnnotationType(refType.getTarget());
        if (target == null) {
            throw new RetryLaterException("Annotation '" + refType.getTarget() + "' in reference '" + fieldName + "' does not exist.");
        }
        dataType = new AnnotationReferenceDataType(target);
        addType(docType, dataType);
        return dataType;
    } else if (dataType instanceof MapDataType) {
        MapDataType mapType = (MapDataType) dataType;
        DataType valueType = specialHandleAnnotationReferenceRecurse(docType, fieldName, mapType.getValueType());
        if (valueType == null) {
            return null;
        }
        mapType = mapType.clone();
        mapType.setValueType(valueType);
        addType(docType, mapType);
        return mapType;
    } else if (dataType instanceof CollectionDataType) {
        CollectionDataType lstType = (CollectionDataType) dataType;
        DataType nestedType = specialHandleAnnotationReferenceRecurse(docType, fieldName, lstType.getNestedType());
        if (nestedType == null) {
            return null;
        }
        lstType = lstType.clone();
        lstType.setNestedType(nestedType);
        addType(docType, lstType);
        return lstType;
    }
    return null;
}
Also used : AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) CollectionDataType(com.yahoo.document.CollectionDataType) StructuredDataType(com.yahoo.document.StructuredDataType) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) DataType(com.yahoo.document.DataType) StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) MapDataType(com.yahoo.document.MapDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) MapDataType(com.yahoo.document.MapDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType)

Example 7 with MapDataType

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

the class JsonReaderTestCase method setUp.

@Before
public void setUp() throws Exception {
    parserFactory = new JsonFactory();
    types = new DocumentTypeManager();
    {
        DocumentType x = new DocumentType("smoke");
        x.addField(new Field("something", DataType.STRING));
        x.addField(new Field("nalle", DataType.STRING));
        x.addField(new Field("int1", DataType.INT));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("mirrors");
        StructDataType woo = new StructDataType("woo");
        woo.addField(new Field("sandra", DataType.STRING));
        woo.addField(new Field("cloud", DataType.STRING));
        x.addField(new Field("skuggsjaa", woo));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testarray");
        DataType d = new ArrayDataType(DataType.STRING);
        x.addField(new Field("actualarray", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testset");
        DataType d = new WeightedSetDataType(DataType.STRING, true, true);
        x.addField(new Field("actualset", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testmap");
        DataType d = new MapDataType(DataType.STRING, DataType.STRING);
        x.addField(new Field("actualmap", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testraw");
        DataType d = DataType.RAW;
        x.addField(new Field("actualraw", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testMapStringToArrayOfInt");
        DataType value = new ArrayDataType(DataType.INT);
        DataType d = new MapDataType(DataType.STRING, value);
        x.addField(new Field("actualMapStringToArrayOfInt", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testsinglepos");
        DataType d = PositionDataType.INSTANCE;
        x.addField(new Field("singlepos", d));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testtensor");
        x.addField(new Field("mappedtensorfield", new TensorDataType(new TensorType.Builder().mapped("x").mapped("y").build())));
        x.addField(new Field("indexedtensorfield", new TensorDataType(new TensorType.Builder().indexed("x").indexed("y").build())));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testpredicate");
        x.addField(new Field("boolean", DataType.PREDICATE));
        types.registerDocumentType(x);
    }
    {
        DocumentType x = new DocumentType("testint");
        x.addField(new Field("integerfield", DataType.INT));
        types.registerDocumentType(x);
    }
}
Also used : Field(com.yahoo.document.Field) TensorDataType(com.yahoo.document.TensorDataType) StructDataType(com.yahoo.document.StructDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) JsonFactory(com.fasterxml.jackson.core.JsonFactory) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) MapDataType(com.yahoo.document.MapDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) PositionDataType(com.yahoo.document.PositionDataType) MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType) TensorType(com.yahoo.tensor.TensorType) Before(org.junit.Before)

Example 8 with MapDataType

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

the class JsonWriterTestCase method registerMapToStringToArrayDocumentType.

private void registerMapToStringToArrayDocumentType() {
    DocumentType x = new DocumentType("testMapStringToArrayOfInt");
    DataType value = new ArrayDataType(DataType.INT);
    DataType d = new MapDataType(DataType.STRING, value);
    x.addField(new Field("actualMapStringToArrayOfInt", d));
    types.registerDocumentType(x);
}
Also used : Field(com.yahoo.document.Field) DocumentType(com.yahoo.document.DocumentType) DataType(com.yahoo.document.DataType) ArrayDataType(com.yahoo.document.ArrayDataType) StructDataType(com.yahoo.document.StructDataType) MapDataType(com.yahoo.document.MapDataType) PositionDataType(com.yahoo.document.PositionDataType) TensorDataType(com.yahoo.document.TensorDataType) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 9 with MapDataType

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

the class MapTestCase method testSerializationStringMap.

public void testSerializationStringMap() {
    MapDataType mapType = new MapDataType(DataType.STRING, DataType.STRING);
    MapFieldValue<StringFieldValue, StringFieldValue> map = mapType.createFieldValue();
    // Field f = new Field("stringmap",mapType);
    StringFieldValue sfvk1 = new StringFieldValue("k1");
    StringFieldValue sfvk2 = new StringFieldValue("k2");
    StringFieldValue sfvk3 = new StringFieldValue("k3");
    StringFieldValue sfvv1 = new StringFieldValue("v1");
    StringFieldValue sfvv2 = new StringFieldValue("v2");
    StringFieldValue sfvv3 = new StringFieldValue("v3");
    map.put(sfvk1, sfvv1);
    map.put(sfvk2, sfvv2);
    map.put(sfvk3, sfvv3);
    assertCorrectSerialization(mapType, map);
}
Also used : MapDataType(com.yahoo.document.MapDataType)

Example 10 with MapDataType

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

the class MapTestCase method testIllegalMapAssignment.

public void testIllegalMapAssignment() {
    MapDataType type1 = new MapDataType(DataType.INT, DataType.INT);
    MapDataType type2 = new MapDataType(DataType.STRING, DataType.STRING);
    MapFieldValue map1 = new MapFieldValue(type1);
    map1.put(new IntegerFieldValue(42), new IntegerFieldValue(84));
    MapFieldValue map2 = new MapFieldValue(type2);
    try {
        map2.assign(map1);
        fail("Expected an exception");
    } catch (IllegalArgumentException e) {
        assertEquals("Incompatible data types. Got datatype int (code: 0)," + " expected datatype string (code: 2)", e.getMessage());
    }
}
Also used : MapDataType(com.yahoo.document.MapDataType)

Aggregations

MapDataType (com.yahoo.document.MapDataType)13 StructDataType (com.yahoo.document.StructDataType)7 ArrayDataType (com.yahoo.document.ArrayDataType)5 DataType (com.yahoo.document.DataType)5 Field (com.yahoo.document.Field)5 DocumentType (com.yahoo.document.DocumentType)4 ReferenceDataType (com.yahoo.document.ReferenceDataType)4 CollectionDataType (com.yahoo.document.CollectionDataType)3 PositionDataType (com.yahoo.document.PositionDataType)3 TensorDataType (com.yahoo.document.TensorDataType)3 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)3 TemporaryAnnotationReferenceDataType (com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)3 StructuredDataType (com.yahoo.document.StructuredDataType)2 TemporaryStructuredDataType (com.yahoo.document.TemporaryStructuredDataType)2 AnnotationReferenceDataType (com.yahoo.document.annotation.AnnotationReferenceDataType)2 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)1 AnnotationType (com.yahoo.document.annotation.AnnotationType)1 VespaDocumentType (com.yahoo.documentmodel.VespaDocumentType)1