diff options
author | Bjørn Christian Seime <bjorn.christian@seime.no> | 2017-04-03 16:56:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 16:56:07 +0200 |
commit | f0cecac64ed5d99bfce888c658166ccd48f252e1 (patch) | |
tree | fc4553b830b5605e945b524028b271df375ce016 /config-model | |
parent | 1143cb219fc4caaa029cf53fe4124bd70414fdcd (diff) | |
parent | 8eb8e1ca571bbb2748dafc47cbbbbc9acfe13ff3 (diff) |
Merge pull request #2136 from yahoo/bjorncs/forbid-document-references-in-streaming-search
Forbid document references in streaming search
Diffstat (limited to 'config-model')
6 files changed, 92 insertions, 8 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java index be038840b92..9dabf33e5a3 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/StreamingValidator.java @@ -1,18 +1,21 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.model.application.validation; -import java.util.List; -import java.util.logging.Level; - -import com.yahoo.config.model.deploy.DeployState; -import com.yahoo.searchdefinition.document.Matching; import com.yahoo.config.application.api.DeployLogger; +import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.document.DataType; import com.yahoo.document.NumericDataType; +import com.yahoo.document.ReferenceDataType; +import com.yahoo.searchdefinition.document.Attribute; +import com.yahoo.searchdefinition.document.Matching; import com.yahoo.searchdefinition.document.SDField; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.search.AbstractSearchCluster; import com.yahoo.vespa.model.search.SearchCluster; +import java.util.List; +import java.util.logging.Level; + /** * Validates streaming mode @@ -29,10 +32,11 @@ public class StreamingValidator extends Validator { SearchCluster sc = (SearchCluster) cluster; warnStreamingAttributes(sc, deployState.getDeployLogger()); warnStreamingGramMatching(sc, deployState.getDeployLogger()); + failStreamingDocumentReferences(sc); } } - private void warnStreamingGramMatching(SearchCluster sc, DeployLogger logger) { + private static void warnStreamingGramMatching(SearchCluster sc, DeployLogger logger) { if (sc.getSdConfig() != null) { for (SDField sd : sc.getSdConfig().getSearch().allConcreteFields()) { if (sd.getMatching().getType().equals(Matching.Type.GRAM)) { @@ -49,7 +53,7 @@ public class StreamingValidator extends Validator { * @param sc a search cluster to be checked for attributes in streaming search * @param logger a DeployLogger */ - private void warnStreamingAttributes(SearchCluster sc, DeployLogger logger) { + private static void warnStreamingAttributes(SearchCluster sc, DeployLogger logger) { if (sc.getSdConfig() != null) { for (SDField sd : sc.getSdConfig().getSearch().allConcreteFields()) { if (sd.doesAttributing()) { @@ -59,11 +63,24 @@ public class StreamingValidator extends Validator { } } - private void warnStreamingAttribute(SearchCluster sc, SDField sd, DeployLogger logger) { + private static void warnStreamingAttribute(SearchCluster sc, SDField sd, DeployLogger logger) { // If the field is numeric, we can't print this, because we may have converted the field to // attribute indexing ourselves (IntegerIndex2Attribute) if (sd.getDataType() instanceof NumericDataType) return; logger.log(Level.WARNING, "For streaming search cluster '" + sc.getClusterName() + "', SD field '" + sd.getName() + "': 'attribute' has same match semantics as 'index'."); } + + private static void failStreamingDocumentReferences(SearchCluster sc) { + for (Attribute attribute : sc.getSdConfig().getAttributeFields().attributes()) { + DataType dataType = attribute.getDataType(); + if (dataType instanceof ReferenceDataType) { + String errorMessage = String.format( + "For streaming search cluster '%s': Attribute '%s' has type '%s'. " + + "Document references and imported fields are not allowed in streaming search.", + sc.getClusterName(), attribute.getName(), dataType.getName()); + throw new IllegalArgumentException(errorMessage); + } + } + } } diff --git a/config-model/src/test/cfg/application/validation/document_references_validation/hosts.xml b/config-model/src/test/cfg/application/validation/document_references_validation/hosts.xml new file mode 100644 index 00000000000..c8cbda0509d --- /dev/null +++ b/config-model/src/test/cfg/application/validation/document_references_validation/hosts.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<hosts> + <host name="localhost"> + <alias>node1</alias> + </host> +</hosts> diff --git a/config-model/src/test/cfg/application/validation/document_references_validation/searchdefinitions/ad.sd b/config-model/src/test/cfg/application/validation/document_references_validation/searchdefinitions/ad.sd new file mode 100644 index 00000000000..608c04594b5 --- /dev/null +++ b/config-model/src/test/cfg/application/validation/document_references_validation/searchdefinitions/ad.sd @@ -0,0 +1,9 @@ +# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +search ad { + document ad { + field campaign_ref type reference<campaign> { + indexing: attribute | summary + } + } + import field campaign_ref.budget as my_budget {} +} diff --git a/config-model/src/test/cfg/application/validation/document_references_validation/searchdefinitions/campaign.sd b/config-model/src/test/cfg/application/validation/document_references_validation/searchdefinitions/campaign.sd new file mode 100644 index 00000000000..cab17fa666d --- /dev/null +++ b/config-model/src/test/cfg/application/validation/document_references_validation/searchdefinitions/campaign.sd @@ -0,0 +1,8 @@ +# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +search campaign { + document campaign { + field budget type int { + indexing: attribute + } + } +} diff --git a/config-model/src/test/cfg/application/validation/document_references_validation/services.xml b/config-model/src/test/cfg/application/validation/document_references_validation/services.xml new file mode 100644 index 00000000000..088949c15c2 --- /dev/null +++ b/config-model/src/test/cfg/application/validation/document_references_validation/services.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<services> + <admin version="2.0"> + <adminserver hostalias="node1" /> + <logserver hostalias="node1" /> + </admin> + <content version="1.0"> + <redundancy>1</redundancy> + <documents> + <document type='ad' mode="streaming"/> + <document type='campaign' mode="streaming" global="true"/> + </documents> + <nodes> + <node hostalias='node1' distribution-key='0'/> + </nodes> + </content> +</services> diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/StreamingValidatorTest.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/StreamingValidatorTest.java new file mode 100644 index 00000000000..1e1022183b1 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/StreamingValidatorTest.java @@ -0,0 +1,25 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.application.validation; + +import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/** + * @author bjorncs + */ +public class StreamingValidatorTest { + @Rule + public final ExpectedException exceptionRule = ExpectedException.none(); + + @Test + public void document_references_are_forbidden_in_streaming_search() { + exceptionRule.expect(IllegalArgumentException.class); + exceptionRule.expectMessage( + "For streaming search cluster 'content.ad': Attribute 'campaign_ref' has type 'Reference<campaign>'. " + + "Document references and imported fields are not allowed in streaming search."); + new VespaModelCreatorWithFilePkg("src/test/cfg/application/validation/document_references_validation/") + .create(); + } +} |