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;
}
}
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);
}
}
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;
}
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;
}
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);
}
}
}
Aggregations