diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
7 files changed, 48 insertions, 50 deletions
diff --git a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java index 7652000389b..65c282e01e2 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java @@ -15,21 +15,22 @@ import com.yahoo.document.datatypes.ReferenceFieldValue; * * @author arnej **/ -@SuppressWarnings("deprecation") public final class NewDocumentReferenceDataType extends DataType { - private StructuredDataType target; - private DocumentType docTypeTarget = null; + private final StructuredDataType target; + private final DocumentType docTypeTarget; private ReferenceDataType delegate = null; private final boolean temporary; private NewDocumentReferenceDataType(NewDocumentType.Name nameAndId, StructuredDataType target, + DocumentType docTypeTarget, boolean temporary) { super(nameAndId.getName(), nameAndId.getId()); this.target = target; + this.docTypeTarget = docTypeTarget; this.temporary = temporary; } @@ -39,47 +40,27 @@ public final class NewDocumentReferenceDataType extends DataType { } public static NewDocumentReferenceDataType forDocumentName(String documentName) { - return new NewDocumentReferenceDataType(buildTypeName(documentName), - TemporaryStructuredDataType.create(documentName), - true); + return new NewDocumentReferenceDataType(new DocumentType(documentName)); } public NewDocumentReferenceDataType(DocumentType document) { - this(buildTypeName(document.getName()), document, true); - this.docTypeTarget = document; + this(buildTypeName(document.getName()), document, document, true); } public NewDocumentReferenceDataType(NewDocumentType document) { - this(buildTypeName(document.getName()), document, false); + this(buildTypeName(document.getName()), document, new DocumentType(document.getName()), false); } public boolean isTemporary() { return temporary; } public StructuredDataType getTargetType() { return target; } - - public void setTargetType(StructuredDataType type) { - assert(target.getName().equals(type.getName())); - if (temporary) { - this.target = type; - if ((docTypeTarget == null) && (type instanceof DocumentType)) { - this.docTypeTarget = (DocumentType) type; - } - } else { - throw new IllegalStateException - (String.format("Unexpected attempt to replace already concrete target " + - "type in NewDocumentReferenceDataType instance (type is '%s')", target.getName())); - } - } + public String getTargetTypeName() { return target.getName(); } + public int getTargetTypeId() { return target.getId(); } @Override public FieldValue createFieldValue() { // TODO why do we even need this if (delegate == null) { - if (docTypeTarget == null) { - var tmptmp = TemporaryStructuredDataType.create(target.getName()); - var tmp = ReferenceDataType.createWithInferredId(tmptmp); - return tmp.createFieldValue(); - } delegate = ReferenceDataType.createWithInferredId(docTypeTarget); } return delegate.createFieldValue(); @@ -109,4 +90,10 @@ public final class NewDocumentReferenceDataType extends DataType { } return false; } + + @Override + public String toString() { + return "{NDRTDT " + getName() + " id=" + getId() + " target=" + target + " [" + target.getClass().getSimpleName() + "]}"; + } + } diff --git a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java index a6571ef819d..dd8edbdde6c 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java @@ -38,7 +38,7 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp private final DataTypeRepo dataTypes = new DataTypeRepo(); private final Map<Integer, NewDocumentType> inherits = new LinkedHashMap<>(); private final AnnotationTypeRegistry annotations = new AnnotationTypeRegistry(); - private final StructDataType header; + private final StructDataType contentStruct; private final Set<FieldSet> fieldSets = new LinkedHashSet<>(); private final Set<Name> documentReferences; // Imported fields are virtual and therefore exist outside of the SD's document field definition @@ -66,13 +66,13 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp } public NewDocumentType(Name name, - StructDataType header, + StructDataType contentStruct, FieldSets fs, Set<Name> documentReferences, Set<String> importedFieldNames) { super(name.getName()); this.name = name; - this.header = header; + this.contentStruct = contentStruct; if (fs != null) { this.fieldSets.addAll(fs.userFieldSets().values()); for (FieldSet f : fs.builtInFieldSets().values()) { @@ -90,22 +90,23 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp return name; } - public DataType getHeader() { return header; } + public DataType getContentStruct() { return contentStruct; } public Collection<NewDocumentType> getInherited() { return inherits.values(); } public NewDocumentType getInherited(Name inherited) { return inherits.get(inherited.getId()); } public NewDocumentType removeInherited(Name inherited) { return inherits.remove(inherited.getId()); } /** * Data type of the header fields of this and all inherited document types + * Used by DocumentGenMojo * @return merged {@link StructDataType} */ public StructDataType allHeader() { - StructDataType ret = new StructDataType(header.getName()); - for (Field f : header.getFields()) { + StructDataType ret = new StructDataType(contentStruct.getName()); + for (Field f : contentStruct.getFields()) { ret.addField(f); } for (NewDocumentType inherited : getInherited()) { - for (Field f : ((StructDataType) inherited.getHeader()).getFields()) { + for (Field f : ((StructDataType) inherited.getContentStruct()).getFields()) { ret.addField(f); } } @@ -172,7 +173,7 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp @Override public Field getField(String name) { - Field field = header.getField(name); + Field field = contentStruct.getField(name); if (field == null) { for (NewDocumentType inheritedType : inherits.values()) { field = inheritedType.getField(name); @@ -190,7 +191,7 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp @Override public Field getField(int id) { - Field field = header.getField(id); + Field field = contentStruct.getField(id); if (field == null) { for (NewDocumentType inheritedType : inherits.values()) { field = inheritedType.getField(id); @@ -209,13 +210,13 @@ public final class NewDocumentType extends StructuredDataType implements DataTyp collection.addAll(type.getAllFields()); } - collection.addAll(header.getFields()); + collection.addAll(contentStruct.getFields()); return Collections.unmodifiableCollection(collection); } public Collection<Field> getFields() { Collection<Field> collection = new LinkedList<>(); - collection.addAll(header.getFields()); + collection.addAll(contentStruct.getFields()); return Collections.unmodifiableCollection(collection); } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java index 16f60e40809..fb161cb8292 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java @@ -306,8 +306,7 @@ public class DocumentModelBuilder { } else if (type instanceof NewDocumentReferenceDataType) { var t = (NewDocumentReferenceDataType) type; - var tt = t.getTargetType(); - var doc = getDocumentType(docs, tt.getId()); + var doc = getDocumentType(docs, t.getTargetTypeId()); type = doc.getReferenceDataType(); } if (type != original) { diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java index 446187eed00..2e8362f1839 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentReferenceResolver.java @@ -16,7 +16,7 @@ import static java.util.stream.Collectors.toMap; /** * Resolves all document references in the search definitions * - * Iterates through all document fields having a {@link NewDocumentReferenceDataType} and uses {@link NewDocumentReferenceDataType#getTargetType()} + * Iterates through all document fields having a {@link NewDocumentReferenceDataType} and uses {@link NewDocumentReferenceDataType#getTargetTypeName()} * to determine the referenced document. This information is aggregated into a {@link DocumentReferences} object. * * @author bjorncs @@ -88,7 +88,7 @@ public class DocumentReferenceResolver { } private static String getTargetDocumentName(NewDocumentReferenceDataType reference) { - return reference.getTargetType().getName(); + return reference.getTargetTypeName(); } } diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java index a9532c080ee..e4d03a3f471 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedSchemas.java @@ -28,6 +28,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.logging.Level; /** * Class converting a collection of schemas from the intermediate format. @@ -114,7 +115,17 @@ public class ConvertParsedSchemas { } for (var struct : parsed.getStructs()) { var structProxy = fieldConverter.convertStructDeclaration(schema, document, struct); - document.addType(structProxy); + var old = document.getType(struct.name()); + if (old == null) { + document.addType(structProxy); + } else { + var oldFields = old.fieldSet(); + var newFields = structProxy.fieldSet(); + if (! newFields.equals(oldFields)) { + throw new IllegalArgumentException("Cannot modify already-existing struct: " + struct.name()); + } + deployLogger.logApplicationPackage(Level.WARNING, "Duplicate struct declaration for: " + struct.name()); + } } for (var annotation : parsed.getAnnotations()) { fieldConverter.convertAnnotation(schema, document, annotation); diff --git a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java index 6f52a384a36..ff311795089 100644 --- a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java +++ b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentManager.java @@ -138,7 +138,7 @@ public class DocumentManager { builder.documenttype(doc); doc. name(dt.getName()). - headerstruct(dt.getHeader().getId()); + headerstruct(dt.getContentStruct().getId()); for (NewDocumentType inherited : dt.getInherited()) { doc.inherits(new Datatype.Documenttype.Inherits.Builder().name(inherited.getName())); } @@ -178,7 +178,7 @@ public class DocumentManager { if (refType.isTemporary()) { throw new IllegalArgumentException("Still temporary: " + refType); } - builder.referencetype(new Datatype.Referencetype.Builder().target_type_id(refType.getTargetType().getId())); + builder.referencetype(new Datatype.Referencetype.Builder().target_type_id(refType.getTargetTypeId())); } else { throw new IllegalArgumentException("Can not create config for data type " + type + " of class " + type.getClass()); } @@ -280,13 +280,13 @@ public class DocumentManager { db. idx(indexMap.idxOf(documentType)). name(documentType.getName()). - contentstruct(indexMap.idxOf(documentType.getHeader())); + contentstruct(indexMap.idxOf(documentType.getContentStruct())); docTypeBuildFieldSets(documentType.getFieldSets(), db); docTypeBuildImportedFields(documentType.getImportedFieldNames(), db); for (NewDocumentType inherited : documentType.getInherited()) { db.inherits(b -> b.idx(indexMap.idxOf(inherited))); } - docTypeBuildAnyType(documentType.getHeader(), db, indexMap); + docTypeBuildAnyType(documentType.getContentStruct(), db, indexMap); for (DataType dt : sortedList(documentType.getAllTypes().getTypes(), (a,b) -> a.getName().compareTo(b.getName()))) { diff --git a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java index 2f0814bd664..1240dac8bf1 100644 --- a/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java +++ b/config-model/src/main/java/com/yahoo/vespa/configmodel/producers/DocumentTypes.java @@ -58,7 +58,7 @@ public class DocumentTypes { db. id(documentType.getId()). name(documentType.getName()). - headerstruct(documentType.getHeader().getId()); + headerstruct(documentType.getContentStruct().getId()); Set<Integer> built = new HashSet<>(); for (NewDocumentType inherited : documentType.getInherited()) { db.inherits(new DocumenttypesConfig.Documenttype.Inherits.Builder().id(inherited.getId())); @@ -224,7 +224,7 @@ public class DocumentTypes { DocumenttypesConfig.Documenttype.Referencetype.Builder refBuilder = new DocumenttypesConfig.Documenttype.Referencetype.Builder(); refBuilder.id(refType.getId()); - refBuilder.target_type_id(type.getTargetType().getId()); + refBuilder.target_type_id(type.getTargetTypeId()); documentBuilder.referencetype(refBuilder); } |