diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-01-31 14:19:30 +0100 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-01-31 14:19:30 +0100 |
commit | 33f4a9d0368d4678c3c4acd4ff3b216ed20ee88f (patch) | |
tree | b5268a8d01ac9686235dd149ae4d0144cd8fe4af | |
parent | 2ef0087346058a1d60413733c7509c0360d63967 (diff) |
Ensure that a reference data type has a concrete target type after model building.
3 files changed, 26 insertions, 3 deletions
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 036e2058f75..91d655e825a 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/DocumentModelBuilder.java @@ -209,6 +209,12 @@ public class DocumentModelBuilder { } else if (type instanceof CollectionDataType) { CollectionDataType t = (CollectionDataType) type; t.setNestedType(resolveTemporariesRecurse(t.getNestedType(), repo, docs)); + } else if (type instanceof ReferenceDataType) { + ReferenceDataType t = (ReferenceDataType) type; + if (t.getTargetType() instanceof TemporaryStructuredDataType) { + DataType targetType = resolveTemporariesRecurse(t.getTargetType(), repo, docs); + t.setTargetType((StructuredDataType) targetType); + } } return type; } diff --git a/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderReferenceTypeTestCase.java b/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderReferenceTypeTestCase.java index 77631012972..e848a0d11e6 100644 --- a/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderReferenceTypeTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/documentmodel/DocumentModelBuilderReferenceTypeTestCase.java @@ -1,6 +1,8 @@ package com.yahoo.vespa.documentmodel; +import com.yahoo.document.ReferenceDataType; import com.yahoo.document.config.DocumentmanagerConfig; +import com.yahoo.documentmodel.NewDocumentType; import com.yahoo.searchdefinition.SearchBuilder; import com.yahoo.searchdefinition.SearchDefinitionTestCase; import com.yahoo.searchdefinition.parser.ParseException; @@ -10,6 +12,7 @@ import org.junit.Test; import java.io.IOException; import static com.yahoo.searchdefinition.TestUtils.joinLines; +import static junit.framework.TestCase.assertSame; /** * @author geirst @@ -51,6 +54,20 @@ public class DocumentModelBuilderReferenceTypeTestCase extends SearchDefinitionT "documentmanager_ref_to_self_type.cfg"); } + @Test + public void reference_data_type_has_a_concrete_target_type() throws ParseException { + DocumentModel model = new TestDocumentModelBuilder().addCampaign().build(joinLines( + "search ad {", + " document ad {", + " field campaign_ref type reference<campaign> {}", + " }", + "}")); + NewDocumentType campaignType = model.getDocumentManager().getDocumentType("campaign"); + NewDocumentType adType = model.getDocumentManager().getDocumentType("ad"); + ReferenceDataType campaignRefType = (ReferenceDataType) adType.getField("campaign_ref").getDataType(); + assertSame(campaignRefType.getTargetType(), campaignType); + } + private static String TEST_FOLDER = "src/test/configmodel/types/references/"; private void assertDocumentConfigs(DocumentModel model, diff --git a/document/src/main/java/com/yahoo/document/ReferenceDataType.java b/document/src/main/java/com/yahoo/document/ReferenceDataType.java index ad7120144b3..8dc41cd67dc 100644 --- a/document/src/main/java/com/yahoo/document/ReferenceDataType.java +++ b/document/src/main/java/com/yahoo/document/ReferenceDataType.java @@ -58,14 +58,14 @@ public class ReferenceDataType extends DataType { public StructuredDataType getTargetType() { return targetType; } /** - * Overrides the stored temporary data type with a concrete DocumentType instance. Should only + * Overrides the stored temporary data type with a concrete StructuredDataType instance. Should only * be invoked from configuration or model code when resolving temporary types. * * @throws IllegalStateException if the previously stored target type is already a concrete * instance of DocumentType. */ - public void setTargetType(DocumentType targetType) { - if (this.targetType instanceof DocumentType) { + public void setTargetType(StructuredDataType targetType) { + if (! (this.targetType instanceof TemporaryStructuredDataType)) { throw new IllegalStateException(String.format( "Unexpected attempt to replace already concrete target " + "type in ReferenceDataType instance (type is '%s')", this.targetType.getName())); |