aboutsummaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorGeir Storli <geirstorli@yahoo.no>2017-04-05 16:11:26 +0200
committerGitHub <noreply@github.com>2017-04-05 16:11:26 +0200
commitdf9fe1e0c734e41c93155190ca1e2433ce2ae37b (patch)
treec2115f3334f647d55a83815da3750af85493298d /config-model
parent645c9b9bcda3e96c4546cf72915a2b0a7c9d3482 (diff)
parentaaaf9ae5ea617c64f1a9156f35862b6191c5c074 (diff)
Merge pull request #2148 from yahoo/bjorncs/forbid-fast-access-prediate-tensor-reference-attribute
Forbid fast-access for predicate, tensor and reference attributes
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/FastAccessValidator.java53
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java1
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/FastAccessValidatorTest.java59
3 files changed, 113 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/FastAccessValidator.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/FastAccessValidator.java
new file mode 100644
index 00000000000..7bef7244eb7
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/FastAccessValidator.java
@@ -0,0 +1,53 @@
+// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.searchdefinition.processing;
+
+import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.searchdefinition.RankProfileRegistry;
+import com.yahoo.searchdefinition.Search;
+import com.yahoo.searchdefinition.document.Attribute;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+
+import java.util.stream.Collectors;
+
+/**
+ * Validates the use of the fast-access property.
+ *
+ * @author bjorncs
+ */
+public class FastAccessValidator extends Processor {
+ public FastAccessValidator(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ super(search, deployLogger, rankProfileRegistry, queryProfiles);
+ }
+
+ @Override
+ public void process() {
+ String invalidAttributes = search.allFields()
+ .flatMap(field -> field.getAttributes().values().stream())
+ .filter(FastAccessValidator::isIncompatibleAttribute)
+ .map(Attribute::getName)
+ .collect(Collectors.joining(", "));
+ if (!invalidAttributes.isEmpty()) {
+ throw new IllegalArgumentException(
+ String.format(
+ "For search '%s': The following attributes have a type that is incompatible with fast-access: %s. " +
+ "Predicate, tensor and reference attributes are incompatible with fast-access.",
+ search.getName(),
+ invalidAttributes));
+ }
+ }
+
+ private static boolean isIncompatibleAttribute(Attribute attribute) {
+ return attribute.isFastAccess() && isTypeIncompatibleWithFastAccess(attribute.getType());
+ }
+
+ private static boolean isTypeIncompatibleWithFastAccess(Attribute.Type type) {
+ switch (type) {
+ case PREDICATE:
+ case TENSOR:
+ case REFERENCE:
+ return true;
+ default:
+ return false;
+ }
+ }
+}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
index 2098d0c0808..18cfd227813 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java
@@ -73,6 +73,7 @@ public class Processing {
TensorFieldProcessor::new,
RankProfileTypeSettingsProcessor::new,
ReferenceFieldsProcessor::new,
+ FastAccessValidator::new,
// These two should be last.
IndexingValidation::new,
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/FastAccessValidatorTest.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/FastAccessValidatorTest.java
new file mode 100644
index 00000000000..8097d828da9
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/FastAccessValidatorTest.java
@@ -0,0 +1,59 @@
+package com.yahoo.searchdefinition.processing;
+
+import com.yahoo.config.model.test.TestUtil;
+import com.yahoo.searchdefinition.RankProfileRegistry;
+import com.yahoo.searchdefinition.SearchBuilder;
+import com.yahoo.searchdefinition.parser.ParseException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * @author bjorncs
+ */
+public class FastAccessValidatorTest {
+
+ @Rule
+ public final ExpectedException exceptionRule = ExpectedException.none();
+
+ @Test
+ public void throws_exception_on_incompatible_use_of_fastaccess() throws ParseException {
+ SearchBuilder builder = new SearchBuilder(new RankProfileRegistry());
+ builder.importString(
+ TestUtil.joinLines(
+ "search parent {",
+ " document parent {",
+ " field int_field type int { indexing: attribute }",
+ " }",
+ "}"));
+ builder.importString(
+ TestUtil.joinLines(
+ "search test {",
+ " document test { ",
+ " field int_attribute type int { ",
+ " indexing: attribute ",
+ " attribute: fast-access",
+ " }",
+ " field predicate_attribute type predicate {",
+ " indexing: attribute ",
+ " attribute: fast-access",
+ " }",
+ " field tensor_attribute type tensor(x[]) {",
+ " indexing: attribute ",
+ " attribute: fast-access",
+ " }",
+ " field reference_attribute type reference<parent> {",
+ " indexing: attribute ",
+ " attribute: fast-access",
+ " }",
+ " }",
+ "}"));
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage(
+ "For search 'test': The following attributes have a type that is incompatible " +
+ "with fast-access: predicate_attribute, tensor_attribute, reference_attribute. " +
+ "Predicate, tensor and reference attributes are incompatible with fast-access.");
+ builder.build();
+ }
+
+}