Search in sources :

Example 1 with StructDataType

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

the class DocumentModelBuilder method convert.

private NewDocumentType convert(SDDocumentType sdoc) {
    Map<AnnotationType, String> annotationInheritance = new HashMap<>();
    Map<StructDataType, String> structInheritance = new HashMap<>();
    NewDocumentType dt = new NewDocumentType(new NewDocumentType.Name(sdoc.getName()), sdoc.getDocumentType().getHeaderType(), sdoc.getDocumentType().getBodyType(), sdoc.getFieldSets(), convertDocumentReferencesToNames(sdoc.getDocumentReferences()));
    for (SDDocumentType n : sdoc.getInheritedTypes()) {
        NewDocumentType.Name name = new NewDocumentType.Name(n.getName());
        NewDocumentType inherited = model.getDocumentManager().getDocumentType(name);
        if (inherited != null) {
            dt.inherit(inherited);
        }
    }
    for (SDDocumentType type : sdoc.getTypes()) {
        if (type.isStruct()) {
            handleStruct(dt, type);
        } else {
            throw new IllegalArgumentException("Data type '" + sdoc.getName() + "' is not a struct => tostring='" + sdoc.toString() + "'.");
        }
    }
    for (AnnotationType annotation : sdoc.getAnnotations()) {
        dt.add(annotation);
    }
    for (AnnotationType annotation : sdoc.getAnnotations()) {
        SDAnnotationType sa = (SDAnnotationType) annotation;
        if (annotation.getInheritedTypes().isEmpty() && (sa.getInherits() != null)) {
            annotationInheritance.put(annotation, sa.getInherits());
        }
        if (annotation.getDataType() == null) {
            if (sa.getSdDocType() != null) {
                StructDataType s = handleStruct(dt, sa.getSdDocType());
                annotation.setDataType(s);
                if ((sa.getInherits() != null)) {
                    structInheritance.put(s, "annotation." + sa.getInherits());
                }
            } else if (sa.getInherits() != null) {
                StructDataType s = new StructDataType("annotation." + annotation.getName());
                if (anyParentsHavePayLoad(sa, sdoc)) {
                    annotation.setDataType(s);
                    addType(dt, s);
                }
                structInheritance.put(s, "annotation." + sa.getInherits());
            }
        }
    }
    for (Map.Entry<AnnotationType, String> e : annotationInheritance.entrySet()) {
        e.getKey().inherit(dt.getAnnotationType(e.getValue()));
    }
    for (Map.Entry<StructDataType, String> e : structInheritance.entrySet()) {
        StructDataType s = (StructDataType) dt.getDataType(e.getValue());
        if (s != null) {
            e.getKey().inherit(s);
        }
    }
    handleStruct(dt, sdoc.getDocumentType().getHeaderType());
    handleStruct(dt, sdoc.getDocumentType().getBodyType());
    extractDataTypesFromFields(dt, sdoc.fieldSet());
    return dt;
}
Also used : SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) HashMap(java.util.HashMap) NewDocumentType(com.yahoo.documentmodel.NewDocumentType) SDAnnotationType(com.yahoo.searchdefinition.document.annotation.SDAnnotationType) AnnotationType(com.yahoo.document.annotation.AnnotationType) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) StructDataType(com.yahoo.document.StructDataType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with StructDataType

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

the class IndexSchemaTestCase method requireThatArrayOfStructIsFlattened.

@Test
public void requireThatArrayOfStructIsFlattened() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("my_byte", DataType.BYTE));
    type.addField(new Field("my_double", DataType.DOUBLE));
    type.addField(new Field("my_float", DataType.FLOAT));
    type.addField(new Field("my_int", DataType.INT));
    type.addField(new Field("my_long", DataType.LONG));
    type.addField(new Field("my_raw", DataType.RAW));
    type.addField(new Field("my_string", DataType.STRING));
    type.addField(new Field("my_uri", DataType.URI));
    assertFlat(new Field("foo", DataType.getArray(type)), new Field("foo.my_byte", DataType.getArray(DataType.BYTE)), new Field("foo.my_double", DataType.getArray(DataType.DOUBLE)), new Field("foo.my_float", DataType.getArray(DataType.FLOAT)), new Field("foo.my_int", DataType.getArray(DataType.INT)), new Field("foo.my_long", DataType.getArray(DataType.LONG)), new Field("foo.my_raw", DataType.getArray(DataType.RAW)), new Field("foo.my_string", DataType.getArray(DataType.STRING)), new Field("foo.my_uri", DataType.getArray(DataType.URI)));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 3 with StructDataType

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

the class IndexSchemaTestCase method requireThatArrayOfStructWithArrayFieldIsFlattened.

@Test
public void requireThatArrayOfStructWithArrayFieldIsFlattened() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("my_byte", DataType.getArray(DataType.BYTE)));
    type.addField(new Field("my_double", DataType.getArray(DataType.DOUBLE)));
    type.addField(new Field("my_float", DataType.getArray(DataType.FLOAT)));
    type.addField(new Field("my_int", DataType.getArray(DataType.INT)));
    type.addField(new Field("my_long", DataType.getArray(DataType.LONG)));
    type.addField(new Field("my_raw", DataType.getArray(DataType.RAW)));
    type.addField(new Field("my_string", DataType.getArray(DataType.STRING)));
    type.addField(new Field("my_uri", DataType.getArray(DataType.URI)));
    assertFlat(new Field("foo", DataType.getArray(type)), new Field("foo.my_byte", DataType.getArray(DataType.getArray(DataType.BYTE))), new Field("foo.my_double", DataType.getArray(DataType.getArray(DataType.DOUBLE))), new Field("foo.my_float", DataType.getArray(DataType.getArray(DataType.FLOAT))), new Field("foo.my_int", DataType.getArray(DataType.getArray(DataType.INT))), new Field("foo.my_long", DataType.getArray(DataType.getArray(DataType.LONG))), new Field("foo.my_raw", DataType.getArray(DataType.getArray(DataType.RAW))), new Field("foo.my_string", DataType.getArray(DataType.getArray(DataType.STRING))), new Field("foo.my_uri", DataType.getArray(DataType.getArray(DataType.URI))));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 4 with StructDataType

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

the class IndexSchemaTestCase method requireThatStructIsFlattened.

@Test
public void requireThatStructIsFlattened() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("my_byte", DataType.BYTE));
    type.addField(new Field("my_double", DataType.DOUBLE));
    type.addField(new Field("my_float", DataType.FLOAT));
    type.addField(new Field("my_int", DataType.INT));
    type.addField(new Field("my_long", DataType.LONG));
    type.addField(new Field("my_raw", DataType.RAW));
    type.addField(new Field("my_string", DataType.STRING));
    type.addField(new Field("my_uri", DataType.URI));
    assertFlat(new Field("foo", type), new Field("foo.my_byte", DataType.BYTE), new Field("foo.my_double", DataType.DOUBLE), new Field("foo.my_float", DataType.FLOAT), new Field("foo.my_int", DataType.INT), new Field("foo.my_long", DataType.LONG), new Field("foo.my_raw", DataType.RAW), new Field("foo.my_string", DataType.STRING), new Field("foo.my_uri", DataType.URI));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Example 5 with StructDataType

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

the class IndexSchemaTestCase method requireThatArrayOfArrayOfStructIsFlattened.

@Test
public void requireThatArrayOfArrayOfStructIsFlattened() {
    StructDataType type = new StructDataType("my_struct");
    type.addField(new Field("my_byte", DataType.BYTE));
    type.addField(new Field("my_double", DataType.DOUBLE));
    type.addField(new Field("my_float", DataType.FLOAT));
    type.addField(new Field("my_int", DataType.INT));
    type.addField(new Field("my_long", DataType.LONG));
    type.addField(new Field("my_raw", DataType.RAW));
    type.addField(new Field("my_string", DataType.STRING));
    type.addField(new Field("my_uri", DataType.URI));
    assertFlat(new Field("foo", DataType.getArray(DataType.getArray(type))), new Field("foo.my_byte", DataType.getArray(DataType.getArray(DataType.BYTE))), new Field("foo.my_double", DataType.getArray(DataType.getArray(DataType.DOUBLE))), new Field("foo.my_float", DataType.getArray(DataType.getArray(DataType.FLOAT))), new Field("foo.my_int", DataType.getArray(DataType.getArray(DataType.INT))), new Field("foo.my_long", DataType.getArray(DataType.getArray(DataType.LONG))), new Field("foo.my_raw", DataType.getArray(DataType.getArray(DataType.RAW))), new Field("foo.my_string", DataType.getArray(DataType.getArray(DataType.STRING))), new Field("foo.my_uri", DataType.getArray(DataType.getArray(DataType.URI))));
}
Also used : Field(com.yahoo.document.Field) StructDataType(com.yahoo.document.StructDataType) Test(org.junit.Test)

Aggregations

StructDataType (com.yahoo.document.StructDataType)44 Field (com.yahoo.document.Field)37 Test (org.junit.Test)27 Struct (com.yahoo.document.datatypes.Struct)9 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)8 DocumentType (com.yahoo.document.DocumentType)6 Array (com.yahoo.document.datatypes.Array)5 FieldValue (com.yahoo.document.datatypes.FieldValue)5 MapDataType (com.yahoo.document.MapDataType)4 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)4 DataType (com.yahoo.document.DataType)3 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)3 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)3 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)3 ArrayList (java.util.ArrayList)3 ArrayDataType (com.yahoo.document.ArrayDataType)2 CollectionDataType (com.yahoo.document.CollectionDataType)2 Document (com.yahoo.document.Document)2 DocumentId (com.yahoo.document.DocumentId)2 ReferenceDataType (com.yahoo.document.ReferenceDataType)2