From 69bb8e938ca38eca6f0e9e05760109fb3799bf6f Mon Sep 17 00:00:00 2001 From: Arne H Juul Date: Fri, 11 Mar 2022 09:41:24 +0000 Subject: [PATCH] ensure unique ReferenceDataType instances --- .../com/yahoo/documentmodel/NewDocumentType.java | 16 ++++++++++++++++ .../searchdefinition/DocumentModelBuilder.java | 13 ++----------- .../documentmanager_refs_to_same_type.cfg | 8 +++----- 3 files changed, 21 insertions(+), 16 deletions(-) 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 d98869e9dd30..4ff54d7ff1cb 100644 --- a/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java +++ b/config-model/src/main/java/com/yahoo/documentmodel/NewDocumentType.java @@ -4,8 +4,10 @@ import com.yahoo.document.DataType; import com.yahoo.document.Document; import com.yahoo.document.Field; +import com.yahoo.document.ReferenceDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.StructuredDataType; +import com.yahoo.document.TemporaryStructuredDataType; import com.yahoo.document.annotation.AnnotationType; import com.yahoo.document.annotation.AnnotationTypeRegistry; import com.yahoo.document.datatypes.FieldValue; @@ -383,4 +385,18 @@ public boolean equals(Object other) { } + private ReferenceDataType refToThis = null; + + @SuppressWarnings("deprecation") + public ReferenceDataType getReferenceDataType() { + if (refToThis == null) { + // super ugly, the APIs for this are horribly inconsistent + var tmptmp = TemporaryStructuredDataType.create(getName()); + var tmp = ReferenceDataType.createWithInferredId(tmptmp); + tmp.setTargetType((StructuredDataType) this); + refToThis = tmp; + } + return refToThis; + } + } 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 4a449dc898f3..2d9c81085fe1 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java @@ -292,17 +292,8 @@ else if (type instanceof WeightedSetDataType) { else if (type instanceof ReferenceDataType) { ReferenceDataType t = (ReferenceDataType) type; var tt = t.getTargetType(); - if (tt instanceof TemporaryStructuredDataType) { - DataType targetType = resolveTemporariesRecurse(tt, repo, docs, replacements); - t.setTargetType((StructuredDataType) targetType); - } else if (tt instanceof DocumentType) { - DataType targetType = resolveTemporariesRecurse(tt, repo, docs, replacements); - // super ugly, the APIs for this are horribly inconsistent - var tmptmp = TemporaryStructuredDataType.create(tt.getName()); - var tmp = new ReferenceDataType(tmptmp, t.getId()); - tmp.setTargetType((StructuredDataType) targetType); - type = tmp; - } + var doc = getDocumentType(docs, tt.getId()); + type = doc.getReferenceDataType(); } if (type != original) { replacements.add(new TypeReplacement(original, type)); diff --git a/config-model/src/test/configmodel/types/references/documentmanager_refs_to_same_type.cfg b/config-model/src/test/configmodel/types/references/documentmanager_refs_to_same_type.cfg index 876ed00d0c4c..ef1bb4c5ad4a 100644 --- a/config-model/src/test/configmodel/types/references/documentmanager_refs_to_same_type.cfg +++ b/config-model/src/test/configmodel/types/references/documentmanager_refs_to_same_type.cfg @@ -47,8 +47,6 @@ doctype[1].fieldsets{[document]}.fields[0] "campaign_ref" doctype[1].fieldsets{[document]}.fields[1] "other_campaign_ref" doctype[1].documentref[0].idx 10017 doctype[1].documentref[0].targettype 10018 -doctype[1].documentref[1].idx 10019 -doctype[1].documentref[1].targettype 10018 doctype[1].structtype[0].idx 10016 doctype[1].structtype[0].name "ad.header" doctype[1].structtype[0].field[0].name "campaign_ref" @@ -56,10 +54,10 @@ doctype[1].structtype[0].field[0].internalid 23963250 doctype[1].structtype[0].field[0].type 10017 doctype[1].structtype[0].field[1].name "other_campaign_ref" doctype[1].structtype[0].field[1].internalid 874751172 -doctype[1].structtype[0].field[1].type 10019 +doctype[1].structtype[0].field[1].type 10017 doctype[2].name "campaign" doctype[2].idx 10018 doctype[2].inherits[0].idx 10000 -doctype[2].contentstruct 10020 -doctype[2].structtype[0].idx 10020 +doctype[2].contentstruct 10019 +doctype[2].structtype[0].idx 10019 doctype[2].structtype[0].name "campaign.header"