diff options
author | Arne H Juul <arnej@yahooinc.com> | 2022-03-23 14:15:33 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2022-03-23 14:17:15 +0000 |
commit | 66e514807987da03b76720161d44dbb0c28f02b6 (patch) | |
tree | 4078e85f7ba37edebae9fc31a878ba7a540f8c72 | |
parent | f385df1baad9fd3abde01256c6781227811128a2 (diff) |
model StructDataType declared in a specific document
3 files changed, 68 insertions, 8 deletions
diff --git a/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java b/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java new file mode 100644 index 00000000000..761a1f0963c --- /dev/null +++ b/config-model/src/main/java/com/yahoo/documentmodel/OwnedStructDataType.java @@ -0,0 +1,56 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.documentmodel; + +import com.yahoo.document.DocumentType; +import com.yahoo.document.StructDataType; + +/** + * Model for StructDataType declared in a specific document + * + * @author arnej + **/ +public final class OwnedStructDataType extends StructDataType implements OwnedType { + + private final String ownerName; + private final String uniqueName; + private boolean overrideId = false; + + public OwnedStructDataType(String name, DocumentType document) { + this(name, document.getName()); + } + + public OwnedStructDataType(String name, String owner) { + super(name); + this.ownerName = owner; + this.uniqueName = name + "@" + owner; + } + + public void enableOverride() { + this.overrideId = true; + } + + @Override + public String getOwnerName() { + return ownerName; + } + + @Override + public String getUniqueName() { + return uniqueName; + } + + @Override + public String getName() { + return overrideId ? uniqueName : super.getName(); + } + + @Override + public int getId() { + return overrideId ? getUniqueId() : super.getId(); + } + + @Override + public String toString() { + return "{OwnedStructDataType "+uniqueName+" id="+getId()+" uid="+getUniqueId()+" enable override="+overrideId+"}"; + } +} 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 1ac3f80c743..9654029ea13 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java @@ -16,6 +16,7 @@ import com.yahoo.document.annotation.AnnotationType; import com.yahoo.documentmodel.DataTypeCollection; import com.yahoo.documentmodel.NewDocumentReferenceDataType; import com.yahoo.documentmodel.NewDocumentType; +import com.yahoo.documentmodel.OwnedStructDataType; import com.yahoo.documentmodel.OwnedTemporaryType; import com.yahoo.documentmodel.TemporaryUnknownType; import com.yahoo.documentmodel.VespaDocumentType; @@ -379,6 +380,8 @@ public class DocumentModelBuilder { for (SDDocumentType proxy : type.getInheritedTypes()) { var inherited = (StructDataType) targetDt.getDataTypeRecursive(proxy.getName()); var converted = (StructDataType) targetDt.getDataType(type.getName()); + assert(converted instanceof OwnedStructDataType); + assert(inherited instanceof OwnedStructDataType); if (! converted.inherits(inherited)) { converted.inherit(inherited); } @@ -397,15 +400,15 @@ public class DocumentModelBuilder { StructDataType s = handleStruct(sa.getSdDocType()); annotation.setDataType(s); if ((sa.getInherits() != null)) { - structInheritance.put(s, "annotation."+sa.getInherits()); + structInheritance.put(s, "annotation." + sa.getInherits()); } } else if (sa.getInherits() != null) { - StructDataType s = new StructDataType("annotation."+annotation.getName()); + StructDataType s = new OwnedStructDataType("annotation." + annotation.getName(), sdoc.getName()); if (anyParentsHavePayLoad(sa, sdoc)) { annotation.setDataType(s); addType(s); } - structInheritance.put(s, "annotation."+sa.getInherits()); + structInheritance.put(s, "annotation." + sa.getInherits()); } } else { var dt = annotation.getDataType(); @@ -558,7 +561,7 @@ public class DocumentModelBuilder { return handleStruct((StructDataType) st); } } - StructDataType s = new StructDataType(type.getName()); + StructDataType s = new OwnedStructDataType(type.getName(), targetDt.getName()); for (Field f : type.getDocumentType().contentStruct().getFieldsThisTypeOnly()) { specialHandleAnnotationReference(f); s.addField(f); diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java index f628db85429..8e27b581769 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/parser/ConvertParsedTypes.java @@ -4,11 +4,12 @@ package com.yahoo.searchdefinition.parser; import com.yahoo.document.DataType; import com.yahoo.document.DocumentType; import com.yahoo.document.DocumentTypeManager; -import com.yahoo.documentmodel.NewDocumentReferenceDataType; -import com.yahoo.document.StructDataType; import com.yahoo.document.PositionDataType; +import com.yahoo.document.StructDataType; import com.yahoo.document.WeightedSetDataType; import com.yahoo.document.annotation.AnnotationReferenceDataType; +import com.yahoo.documentmodel.NewDocumentReferenceDataType; +import com.yahoo.documentmodel.OwnedStructDataType; import com.yahoo.searchdefinition.document.annotation.SDAnnotationType; import java.util.ArrayList; @@ -58,7 +59,7 @@ public class ConvertParsedTypes { var doc = schema.getDocument(); for (var struct : doc.getStructs()) { String structId = doc.name() + "->" + struct.name(); - var dt = new StructDataType(struct.name()); + var dt = new OwnedStructDataType(struct.name(), doc.name()); structsFromSchemas.put(structId, dt); } for (var annotation : doc.getAnnotations()) { @@ -72,7 +73,7 @@ public class ConvertParsedTypes { if (withStruct.isPresent()) { ParsedStruct struct = withStruct.get(); String structId = doc.name() + "->" + struct.name(); - var old = structsFromSchemas.put(structId, new StructDataType(struct.name())); + var old = structsFromSchemas.put(structId, new OwnedStructDataType(struct.name(), doc.name())); assert(old == null); } } |