diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2022-03-18 15:32:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-18 15:32:27 +0100 |
commit | 49b6b5174dabceb13b2628d3d824d940278b1900 (patch) | |
tree | 137a628d76bd10cd1728324f50684db75be361e6 | |
parent | 51898a0b6c5722312eee9ffe1f783c1b41224834 (diff) | |
parent | 466ab8c7bee231d4ea85643d3cdd1e64ef5c3f29 (diff) |
Merge pull request #21745 from vespa-engine/arnej/minor-cleanup
Arnej/minor cleanup
16 files changed, 50 insertions, 57 deletions
diff --git a/config-model/remove-indexes-from-temp-files.sh b/config-model/remove-indexes-from-temp-files.sh index 41feb65d3f0..988c99bc6e6 100755 --- a/config-model/remove-indexes-from-temp-files.sh +++ b/config-model/remove-indexes-from-temp-files.sh @@ -1,3 +1,3 @@ #!/bin/sh -perl -pi -e 's{[[][0-9]*[]][.]}{[].}g;s{[[][0-9]*[]] }{[] }' temp/*/*.cfg +perl -pi -e 's{[[][0-9]*[]][.]}{[].}g;s{[[][0-9]*[]] }{[] };chomp;s/$/\n/' temp/*/*.cfg 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..994e969eeb0 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentReferenceDataType.java @@ -18,18 +18,20 @@ import com.yahoo.document.datatypes.ReferenceFieldValue; @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 +41,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 +91,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/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); } diff --git a/config-model/src/test/derived/function_arguments/rank-profiles.cfg b/config-model/src/test/derived/function_arguments/rank-profiles.cfg index 318b0303a75..007c671229e 100644 --- a/config-model/src/test/derived/function_arguments/rank-profiles.cfg +++ b/config-model/src/test/derived/function_arguments/rank-profiles.cfg @@ -68,4 +68,4 @@ rankprofile[].fef.property[].value "rankingExpression(my_func@a03bffb2024104a4)" rankprofile[].fef.property[].name "vespa.type.attribute.t1" rankprofile[].fef.property[].value "tensor<float>(x{})" rankprofile[].fef.property[].name "vespa.type.attribute.t2" -rankprofile[].fef.property[].value "tensor<float>(x{})"
\ No newline at end of file +rankprofile[].fef.property[].value "tensor<float>(x{})" diff --git a/config-model/src/test/derived/function_arguments_with_expressions/rank-profiles.cfg b/config-model/src/test/derived/function_arguments_with_expressions/rank-profiles.cfg index 5e7b38fc264..650bc4cb15b 100644 --- a/config-model/src/test/derived/function_arguments_with_expressions/rank-profiles.cfg +++ b/config-model/src/test/derived/function_arguments_with_expressions/rank-profiles.cfg @@ -102,4 +102,4 @@ rankprofile[].fef.property[].value "rankingExpression(my_func@93366be10bade547)" rankprofile[].fef.property[].name "vespa.type.attribute.t1" rankprofile[].fef.property[].value "tensor<float>(x{})" rankprofile[].fef.property[].name "vespa.type.attribute.t2" -rankprofile[].fef.property[].value "tensor<float>(x{})"
\ No newline at end of file +rankprofile[].fef.property[].value "tensor<float>(x{})" diff --git a/config-model/src/test/derived/language/ilscripts.cfg b/config-model/src/test/derived/language/ilscripts.cfg index cafc7feafb8..4858788095c 100644 --- a/config-model/src/test/derived/language/ilscripts.cfg +++ b/config-model/src/test/derived/language/ilscripts.cfg @@ -6,4 +6,4 @@ ilscript[].docfield[] "title" ilscript[].content[] "clear_state | guard { input language | tokenize normalize stem:\"BEST\" | summary language | index language | set_language; }" ilscript[].content[] "clear_state | guard { input title | tokenize normalize stem:\"BEST\" | index titlebest; }" ilscript[].content[] "clear_state | guard { input title | tokenize normalize | index titlenone; }" -ilscript[].content[] "clear_state | guard { input title | tokenize normalize stem:\"BEST\" | summary title | index title; }"
\ No newline at end of file +ilscript[].content[] "clear_state | guard { input title | tokenize normalize stem:\"BEST\" | summary title | index title; }" diff --git a/config-model/src/test/derived/lowercase/ilscripts.cfg b/config-model/src/test/derived/lowercase/ilscripts.cfg index 0cf56eb43e0..fe36dc5daef 100644 --- a/config-model/src/test/derived/lowercase/ilscripts.cfg +++ b/config-model/src/test/derived/lowercase/ilscripts.cfg @@ -6,4 +6,4 @@ ilscript[].docfield[] "array_field_source" ilscript[].content[] "clear_state | guard { input array_field_source | for_each { lowercase } | for_each { tokenize normalize stem:\"BEST\" } | summary array_field | index array_field; }" ilscript[].content[] "clear_state | guard { input single_field_source | lowercase | tokenize normalize stem:\"BEST\" | summary single_field | index single_field; }" ilscript[].content[] "input array_field_source | passthrough array_field_source" -ilscript[].content[] "input single_field_source | passthrough single_field_source"
\ No newline at end of file +ilscript[].content[] "input single_field_source | passthrough single_field_source" diff --git a/config-model/src/test/derived/lowercase/index-info.cfg b/config-model/src/test/derived/lowercase/index-info.cfg index b94125de79d..ff6008fe1ce 100644 --- a/config-model/src/test/derived/lowercase/index-info.cfg +++ b/config-model/src/test/derived/lowercase/index-info.cfg @@ -38,4 +38,4 @@ indexinfo[].command[].command "normalize" indexinfo[].command[].indexname "single_field" indexinfo[].command[].command "plain-tokens" indexinfo[].command[].indexname "single_field" -indexinfo[].command[].command "type string"
\ No newline at end of file +indexinfo[].command[].command "type string" diff --git a/config-model/src/test/derived/schemainheritance/summary.cfg b/config-model/src/test/derived/schemainheritance/summary.cfg index 6fcf5b2aaa8..11f876c66c6 100644 --- a/config-model/src/test/derived/schemainheritance/summary.cfg +++ b/config-model/src/test/derived/schemainheritance/summary.cfg @@ -47,4 +47,4 @@ classes[].fields[].type "featuredata" classes[].fields[].name "summaryfeatures" classes[].fields[].type "featuredata" classes[].fields[].name "cf1" -classes[].fields[].type "longstring"
\ No newline at end of file +classes[].fields[].type "longstring" diff --git a/config-model/src/test/derived/tokenization/ilscripts.cfg b/config-model/src/test/derived/tokenization/ilscripts.cfg index ead74110db3..4414ad0f7cb 100644 --- a/config-model/src/test/derived/tokenization/ilscripts.cfg +++ b/config-model/src/test/derived/tokenization/ilscripts.cfg @@ -6,4 +6,4 @@ ilscript[].docfield[] "text_array" ilscript[].content[] "clear_state | guard { input text_array | for_each { lowercase } | for_each { normalize } | for_each { tokenize normalize stem:\"BEST\" } | index text_array_derived | summary text_array_derived; }" ilscript[].content[] "clear_state | guard { input text | normalize | tokenize normalize stem:\"BEST\" | index text_derived | summary text_derived; }" ilscript[].content[] "clear_state | guard { input text | tokenize normalize stem:\"BEST\" | index text | summary text; }" -ilscript[].content[] "clear_state | guard { input text_array | for_each { tokenize normalize stem:\"BEST\" } | index text_array | summary text_array; }"
\ No newline at end of file +ilscript[].content[] "clear_state | guard { input text_array | for_each { tokenize normalize stem:\"BEST\" } | index text_array | summary text_array; }" diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java index d77c6d822e3..38ebb147cac 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankProfileTestCase.java @@ -8,6 +8,7 @@ import com.yahoo.config.model.application.provider.MockFileRegistry; import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.document.DataType; +import com.yahoo.search.query.profile.QueryProfile; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.search.query.profile.types.FieldDescription; import com.yahoo.search.query.profile.types.FieldType; @@ -363,6 +364,9 @@ public class RankProfileTestCase extends AbstractSchemaTestCase { type.addField(new FieldDescription("ranking.features.query(numeric)", FieldType.fromString("integer", typeRegistry)), typeRegistry); typeRegistry.register(type); + var profile = new QueryProfile(new ComponentId("testprofile")); + profile.setType(type); + registry.register(profile); return registry; } diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ReferenceFieldTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ReferenceFieldTestCase.java index c517e36bce1..bfd87580dbe 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ReferenceFieldTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ReferenceFieldTestCase.java @@ -108,7 +108,8 @@ public class ReferenceFieldTestCase { DataType dataType = field.getDataType(); assertTrue(dataType instanceof NewDocumentReferenceDataType); NewDocumentReferenceDataType refField = (NewDocumentReferenceDataType) dataType; - assertEquals(referencedDocType, refField.getTargetType().getName()); + assertEquals(referencedDocType, refField.getTargetTypeName()); + assertTrue(! refField.isTemporary()); } } |