Search in sources :

Example 1 with MapDataType

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

the class JsonWriterTestCase method registerMapDocumentType.

private void registerMapDocumentType() {
    DocumentType x = new DocumentType("testmap");
    DataType d = new MapDataType(DataType.STRING, DataType.STRING);
    x.addField(new Field("actualmap", 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)

Example 2 with MapDataType

use of com.yahoo.document.MapDataType 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 3 with MapDataType

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

the class MapTestCase method testSerializationComplex.

public void testSerializationComplex() {
    ArrayDataType twoDimArray = DataType.getArray(DataType.getArray(DataType.FLOAT));
    MapDataType floatToTwoDimArray = new MapDataType(DataType.FLOAT, twoDimArray);
    MapFieldValue<FloatFieldValue, Array<Array<FloatFieldValue>>> map = floatToTwoDimArray.createFieldValue();
    Array<FloatFieldValue> af1 = new Array(DataType.getArray(DataType.FLOAT));
    af1.add(new FloatFieldValue(11f));
    af1.add(new FloatFieldValue(111f));
    Array<FloatFieldValue> af2 = new Array(DataType.getArray(DataType.FLOAT));
    af2.add(new FloatFieldValue(22f));
    af2.add(new FloatFieldValue(222f));
    Array<Array<FloatFieldValue>> aaf1 = new Array(twoDimArray);
    aaf1.add(af1);
    aaf1.add(af2);
    Array<FloatFieldValue> af3 = new Array(DataType.getArray(DataType.FLOAT));
    af3.add(new FloatFieldValue(33f));
    af3.add(new FloatFieldValue(333f));
    Array<FloatFieldValue> af4 = new Array(DataType.getArray(DataType.FLOAT));
    af4.add(new FloatFieldValue(44f));
    af4.add(new FloatFieldValue(444f));
    Array<Array<FloatFieldValue>> aaf2 = new Array(twoDimArray);
    aaf2.add(af3);
    aaf2.add(af4);
    map.put(new FloatFieldValue(1.1f), aaf1);
    map.put(new FloatFieldValue(2.2f), aaf2);
    assertCorrectSerialization(floatToTwoDimArray, map);
}
Also used : MapDataType(com.yahoo.document.MapDataType) ArrayDataType(com.yahoo.document.ArrayDataType)

Example 4 with MapDataType

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

the class DocumentModelBuilder method resolveTemporariesRecurse.

@SuppressWarnings("deprecation")
private static DataType resolveTemporariesRecurse(DataType type, DataTypeCollection repo, Collection<NewDocumentType> docs) {
    if (type instanceof TemporaryStructuredDataType) {
        NewDocumentType docType = getDocumentType(docs, type.getId());
        if (docType != null) {
            type = docType;
            return type;
        }
        DataType real = repo.getDataType(type.getId());
        if (real == null) {
            throw new NullPointerException("Can not find type '" + type.toString() + "', impossible.");
        }
        type = real;
    } else if (type instanceof StructDataType) {
        StructDataType dt = (StructDataType) type;
        for (com.yahoo.document.Field field : dt.getFields()) {
            if (field.getDataType() != type) {
                // XXX deprecated:
                field.setDataType(resolveTemporariesRecurse(field.getDataType(), repo, docs));
            }
        }
    } else if (type instanceof MapDataType) {
        MapDataType t = (MapDataType) type;
        t.setKeyType(resolveTemporariesRecurse(t.getKeyType(), repo, docs));
        t.setValueType(resolveTemporariesRecurse(t.getValueType(), repo, docs));
    } else if (type instanceof CollectionDataType) {
        CollectionDataType t = (CollectionDataType) type;
        t.setNestedType(resolveTemporariesRecurse(t.getNestedType(), repo, docs));
    } else if (type instanceof ReferenceDataType) {
        ReferenceDataType t = (ReferenceDataType) type;
        if (t.getTargetType() instanceof TemporaryStructuredDataType) {
            DataType targetType = resolveTemporariesRecurse(t.getTargetType(), repo, docs);
            t.setTargetType((StructuredDataType) targetType);
        }
    }
    return type;
}
Also used : SDField(com.yahoo.searchdefinition.document.SDField) SearchField(com.yahoo.vespa.documentmodel.SearchField) Field(com.yahoo.document.Field) TemporaryStructuredDataType(com.yahoo.document.TemporaryStructuredDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType) ReferenceDataType(com.yahoo.document.ReferenceDataType) StructDataType(com.yahoo.document.StructDataType) 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) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) MapDataType(com.yahoo.document.MapDataType)

Example 5 with MapDataType

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

the class DocumentModelBuilder method extractNestedTypes.

private static void extractNestedTypes(NewDocumentType dt, DataType type) {
    if (type instanceof StructDataType) {
        StructDataType tmp = (StructDataType) type;
        extractDataTypesFromFields(dt, tmp.getFieldsThisTypeOnly());
    } else if (type instanceof DocumentType) {
        throw new IllegalArgumentException("Can not handle nested document definitions. In document type '" + dt.getName().toString() + "', we can not define document type '" + type.toString());
    } else if (type instanceof CollectionDataType) {
        CollectionDataType tmp = (CollectionDataType) type;
        extractNestedTypes(dt, tmp.getNestedType());
        addType(dt, tmp.getNestedType());
    } else if (type instanceof MapDataType) {
        MapDataType tmp = (MapDataType) type;
        extractNestedTypes(dt, tmp.getKeyType());
        extractNestedTypes(dt, tmp.getValueType());
        addType(dt, tmp.getKeyType());
        addType(dt, tmp.getValueType());
    } else if (type instanceof TemporaryAnnotationReferenceDataType) {
        throw new IllegalArgumentException(type.toString());
    }
}
Also used : StructDataType(com.yahoo.document.StructDataType) CollectionDataType(com.yahoo.document.CollectionDataType) DocumentType(com.yahoo.document.DocumentType) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) VespaDocumentType(com.yahoo.documentmodel.VespaDocumentType) MapDataType(com.yahoo.document.MapDataType) TemporaryAnnotationReferenceDataType(com.yahoo.searchdefinition.document.annotation.TemporaryAnnotationReferenceDataType)

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