Search in sources :

Example 1 with SDDocumentType

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

the class DocumentGraphValidator method validateChildren.

private static void validateChildren(SDDocumentType root, SDDocumentType currentDocument) {
    try {
        currentDocument.getDocumentReferences().get().forEach(entry -> {
            SDDocumentType referencedDocument = entry.getValue().targetSearch().getDocument();
            validateDocument(root, referencedDocument);
        });
        currentDocument.getInheritedTypes().forEach(inheritedDocument -> {
            if (!isRootDocument(inheritedDocument)) {
                validateDocument(root, inheritedDocument);
            }
        });
    } catch (DocumentGraphException e) {
        e.addParentDocument(currentDocument);
        throw e;
    }
}
Also used : SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType)

Example 2 with SDDocumentType

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

the class SDDocumentTypeOrderer method visit.

private void visit(DataType type) {
    if (type instanceof StructuredDataType) {
        StructuredDataType structType = (StructuredDataType) type;
        SDDocumentType sdDocType = find(structType.getName());
        if (sdDocType == null) {
            throw new IllegalArgumentException("Could not find struct '" + type.getName() + "'.");
        }
        visit(sdDocType);
        return;
    }
    if (type instanceof MapDataType) {
        MapDataType mType = (MapDataType) type;
        visit(mType.getValueType());
        visit(mType.getKeyType());
    } else if (type instanceof WeightedSetDataType) {
        WeightedSetDataType wType = (WeightedSetDataType) type;
        visit(wType.getNestedType());
    } else if (type instanceof CollectionDataType) {
        CollectionDataType cType = (CollectionDataType) type;
        visit(cType.getNestedType());
    } else if (type instanceof AnnotationReferenceDataType) {
    // do nothing
    } else if (type instanceof PrimitiveDataType) {
    // do nothing
    } else if (type instanceof TensorDataType) {
    // do nothing
    } else if (type instanceof ReferenceDataType) {
    // do nothing
    } else {
        deployLogger.log(Level.WARNING, "Unknown type : " + type);
    }
}
Also used : SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) TemporarySDDocumentType(com.yahoo.searchdefinition.document.TemporarySDDocumentType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType) AnnotationReferenceDataType(com.yahoo.document.annotation.AnnotationReferenceDataType)

Example 3 with SDDocumentType

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

the class SearchBuilder method build.

/**
 * Processes and finalizes the imported search definitions so that they become available through the {@link
 * #getSearch(String)} method.
 *
 * @throws IllegalStateException Thrown if this method has already been called.
 * @param deployLogger The logger to use during build
 */
public void build(boolean validate, DeployLogger deployLogger) {
    if (isBuilt)
        throw new IllegalStateException("Model already built");
    List<Search> built = new ArrayList<>();
    List<SDDocumentType> sdocs = new ArrayList<>();
    sdocs.add(SDDocumentType.VESPA_DOCUMENT);
    for (Search search : searchList) {
        if (search.hasDocument()) {
            sdocs.add(search.getDocument());
        }
    }
    SDDocumentTypeOrderer orderer = new SDDocumentTypeOrderer(sdocs, deployLogger);
    orderer.process();
    for (SDDocumentType sdoc : orderer.getOrdered()) {
        new FieldOperationApplierForStructs().process(sdoc);
        new FieldOperationApplier().process(sdoc);
    }
    DocumentReferenceResolver resolver = new DocumentReferenceResolver(searchList);
    sdocs.forEach(resolver::resolveReferences);
    if (validate)
        new DocumentGraphValidator().validateDocumentGraph(sdocs);
    DocumentModelBuilder builder = new DocumentModelBuilder(model);
    for (Search search : new SearchOrderer().order(searchList)) {
        new FieldOperationApplierForSearch().process(search);
        // These two needed for a couple of old unit tests, ideally these are just read from app
        process(search, deployLogger, new QueryProfiles(queryProfileRegistry), validate);
        built.add(search);
    }
    builder.addToModel(searchList);
    if (validate && !builder.valid())
        throw new IllegalArgumentException("Impossible to build a correct model.");
    searchList = built;
    isBuilt = true;
}
Also used : ArrayList(java.util.ArrayList) SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType) SearchOrderer(com.yahoo.searchdefinition.derived.SearchOrderer) QueryProfiles(com.yahoo.vespa.model.container.search.QueryProfiles)

Example 4 with SDDocumentType

use of com.yahoo.searchdefinition.document.SDDocumentType 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 5 with SDDocumentType

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

the class FieldOperationApplierForStructs method process.

@Override
public void process(SDDocumentType sdoc) {
    for (SDDocumentType type : sdoc.getAllTypes()) {
        if (type.isStruct()) {
            apply(type);
            copyFields(type, sdoc);
        }
    }
}
Also used : SDDocumentType(com.yahoo.searchdefinition.document.SDDocumentType)

Aggregations

SDDocumentType (com.yahoo.searchdefinition.document.SDDocumentType)48 Test (org.junit.Test)28 SDField (com.yahoo.searchdefinition.document.SDField)23 Search (com.yahoo.searchdefinition.Search)21 RankProfileRegistry (com.yahoo.searchdefinition.RankProfileRegistry)7 BaseDeployLogger (com.yahoo.config.model.application.provider.BaseDeployLogger)6 QueryProfiles (com.yahoo.vespa.model.container.search.QueryProfiles)6 QueryProfileRegistry (com.yahoo.search.query.profile.QueryProfileRegistry)5 TemporarySDField (com.yahoo.searchdefinition.document.TemporarySDField)4 ArrayList (java.util.ArrayList)4 DataTypeName (com.yahoo.document.DataTypeName)3 TemporarySDDocumentType (com.yahoo.searchdefinition.document.TemporarySDDocumentType)3 HashMap (java.util.HashMap)3 NewDocumentType (com.yahoo.documentmodel.NewDocumentType)2 DocumentReferences (com.yahoo.searchdefinition.DocumentReferences)2 RankProfile (com.yahoo.searchdefinition.RankProfile)2 SearchBuilder (com.yahoo.searchdefinition.SearchBuilder)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 DataType (com.yahoo.document.DataType)1