summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorGeir Storli <geirst@oath.com>2018-04-26 16:32:54 +0200
committerGeir Storli <geirst@oath.com>2018-04-26 16:32:54 +0200
commit9154286ecbd9eb387e8be1d6187ba80ffd4d1adb (patch)
treee564d675a7d90e53ebe319f4f6c0b148e037d1c5 /config-model
parent8b9c5bd42d67df4573606607c2a637e9438f32cb (diff)
Disallow importing fields of type predicate as this is not (yet) supported by the search backend.
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummayValidator.java65
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolver.java21
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/Processing.java1
-rw-r--r--config-model/src/test/derived/importedfields/attributes.cfg20
-rw-r--r--config-model/src/test/derived/importedfields/child.sd1
-rw-r--r--config-model/src/test/derived/importedfields/imported-fields.cfg5
-rw-r--r--config-model/src/test/derived/importedfields/index-info.cfg6
-rw-r--r--config-model/src/test/derived/importedfields/parent_a.sd8
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummaryValidatorTestCase.java42
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java10
10 files changed, 21 insertions, 158 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummayValidator.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummayValidator.java
deleted file mode 100644
index 5e8065b887d..00000000000
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummayValidator.java
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2018 Yahoo Holdings. 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.document.DataType;
-import com.yahoo.searchdefinition.RankProfileRegistry;
-import com.yahoo.searchdefinition.Search;
-import com.yahoo.searchdefinition.document.ImportedField;
-import com.yahoo.vespa.documentmodel.DocumentSummary;
-import com.yahoo.vespa.documentmodel.SummaryField;
-import com.yahoo.vespa.model.container.search.QueryProfiles;
-
-import java.util.Map;
-
-/**
- * Validates that imported fields in document summaries are of supported types.
- * Currently, predicate fields are NOT supported.
- *
- * @author geirst
- */
-public class ImportedFieldsInSummayValidator extends Processor {
-
- public ImportedFieldsInSummayValidator(Search search, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
- super(search, deployLogger, rankProfileRegistry, queryProfiles);
- }
-
- @Override
- public void process(boolean validate) {
- if ( ! validate) return;
-
- if (search.importedFields().isPresent()) {
- validateDocumentSummaries(search.getSummaries());
- }
- }
-
- private void validateDocumentSummaries(Map<String, DocumentSummary> summaries) {
- for (DocumentSummary summary : summaries.values()) {
- for (SummaryField field : summary.getSummaryFields()) {
- ImportedField importedField = getImportedField(field);
- if (importedField != null) {
- validateImportedSummaryField(summary, field, importedField);
- }
- }
- }
- }
-
- private ImportedField getImportedField(SummaryField field) {
- return search.importedFields().get().fields().get(field.getName());
- }
-
- private void validateImportedSummaryField(DocumentSummary summary, SummaryField field, ImportedField importedField) {
- if (field.getDataType().equals(DataType.PREDICATE)
- && importedField.targetField().getDataType().equals(DataType.PREDICATE)) {
- fail(summary, field, "Is of type predicate. Not supported in document summaries");
- }
- }
-
- private void fail(DocumentSummary summary, SummaryField importedField, String msg) {
- throw new IllegalArgumentException("For search '" + search.getName() + "', document summary '" + summary.getName() +
- "', imported summary field '" + importedField.getName() + "': " + msg);
- }
-}
-
-
-
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolver.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolver.java
index 50e24e2f07d..9f03cdf4b5e 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolver.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolver.java
@@ -2,6 +2,7 @@
package com.yahoo.searchdefinition.processing;
import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.document.DataType;
import com.yahoo.searchdefinition.DocumentReference;
import com.yahoo.searchdefinition.DocumentReferences;
import com.yahoo.searchdefinition.RankProfileRegistry;
@@ -9,7 +10,6 @@ import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.ImmutableSDField;
import com.yahoo.searchdefinition.document.ImportedField;
import com.yahoo.searchdefinition.document.ImportedFields;
-import com.yahoo.searchdefinition.document.SDField;
import com.yahoo.searchdefinition.document.TemporaryImportedField;
import com.yahoo.vespa.model.container.search.QueryProfiles;
@@ -60,16 +60,19 @@ public class ImportedFieldsResolver extends Processor {
Search targetSearch = reference.targetSearch();
ImmutableSDField targetField = targetSearch.getField(targetFieldName);
if (targetField == null) {
- fail(importedField, targetFieldAsString(targetFieldName, reference) +
- ": Not found");
- } else if (!targetField.doesAttributing()) {
- if (validate)
+ fail(importedField, targetFieldAsString(targetFieldName, reference) + ": Not found");
+ }
+ if (validate) {
+ if (!targetField.doesAttributing()) {
+ fail(importedField, targetFieldAsString(targetFieldName, reference) +
+ ": Is not an attribute field. Only attribute fields supported");
+ } else if (targetField.doesIndexing()) {
fail(importedField, targetFieldAsString(targetFieldName, reference) +
- ": Is not an attribute field. Only attribute fields supported");
- } else if (targetField.doesIndexing()) {
- if (validate)
+ ": Is an index field. Not supported");
+ } else if (targetField.getDataType().equals(DataType.PREDICATE)) {
fail(importedField, targetFieldAsString(targetFieldName, reference) +
- ": Is an index field. Not supported");
+ ": Is of type 'predicate'. Not supported");
+ }
}
return targetField;
}
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 f76894f985c..cedbebe3b4e 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
@@ -72,7 +72,6 @@ public class Processing {
TensorFieldProcessor::new,
RankProfileTypeSettingsProcessor::new,
ReferenceFieldsProcessor::new,
- ImportedFieldsInSummayValidator::new,
FastAccessValidator::new,
ReservedMacroNames::new,
RankingExpressionTypeValidator::new,
diff --git a/config-model/src/test/derived/importedfields/attributes.cfg b/config-model/src/test/derived/importedfields/attributes.cfg
index f1cfab59e65..0fad35c13ee 100644
--- a/config-model/src/test/derived/importedfields/attributes.cfg
+++ b/config-model/src/test/derived/importedfields/attributes.cfg
@@ -138,26 +138,6 @@ attribute[].upperbound 9223372036854775807
attribute[].densepostinglistthreshold 0.4
attribute[].tensortype ""
attribute[].imported true
-attribute[].name "my_predicate_field"
-attribute[].datatype PREDICATE
-attribute[].collectiontype SINGLE
-attribute[].removeifzero false
-attribute[].createifnonexistent false
-attribute[].fastsearch false
-attribute[].huge false
-attribute[].sortascending true
-attribute[].sortfunction UCA
-attribute[].sortstrength PRIMARY
-attribute[].sortlocale ""
-attribute[].enablebitvectors false
-attribute[].enableonlybitvector false
-attribute[].fastaccess false
-attribute[].arity 8
-attribute[].lowerbound 5
-attribute[].upperbound 300
-attribute[].densepostinglistthreshold 0.4
-attribute[].tensortype ""
-attribute[].imported true
attribute[].name "my_ancient_int_field"
attribute[].datatype INT32
attribute[].collectiontype SINGLE
diff --git a/config-model/src/test/derived/importedfields/child.sd b/config-model/src/test/derived/importedfields/child.sd
index e7a2953506c..d541ba8fc8c 100644
--- a/config-model/src/test/derived/importedfields/child.sd
+++ b/config-model/src/test/derived/importedfields/child.sd
@@ -9,7 +9,6 @@ search child {
import field b_ref.string_field as my_string_field {}
import field a_ref.int_array_field as my_int_array_field {}
import field a_ref.int_wset_field as my_int_wset_field {}
- import field a_ref.predicate_field as my_predicate_field {}
import field a_ref.ancient_int_field as my_ancient_int_field {}
fieldset myfieldset {
diff --git a/config-model/src/test/derived/importedfields/imported-fields.cfg b/config-model/src/test/derived/importedfields/imported-fields.cfg
index 2c36fee177d..d1895d02290 100644
--- a/config-model/src/test/derived/importedfields/imported-fields.cfg
+++ b/config-model/src/test/derived/importedfields/imported-fields.cfg
@@ -18,11 +18,6 @@ attribute[].referencefield "a_ref"
attribute[].targetfield "int_wset_field"
attribute[].datatype NONE
attribute[].collectiontype SINGLE
-attribute[].name "my_predicate_field"
-attribute[].referencefield "a_ref"
-attribute[].targetfield "predicate_field"
-attribute[].datatype NONE
-attribute[].collectiontype SINGLE
attribute[].name "my_ancient_int_field"
attribute[].referencefield "a_ref"
attribute[].targetfield "ancient_int_field"
diff --git a/config-model/src/test/derived/importedfields/index-info.cfg b/config-model/src/test/derived/importedfields/index-info.cfg
index 9291956447b..ef11247191f 100644
--- a/config-model/src/test/derived/importedfields/index-info.cfg
+++ b/config-model/src/test/derived/importedfields/index-info.cfg
@@ -49,12 +49,6 @@ indexinfo[].command[].indexname "my_int_wset_field"
indexinfo[].command[].command "multivalue"
indexinfo[].command[].indexname "my_int_wset_field"
indexinfo[].command[].command "attribute"
-indexinfo[].command[].indexname "my_predicate_field"
-indexinfo[].command[].command "predicate-bounds [5..300]"
-indexinfo[].command[].indexname "my_predicate_field"
-indexinfo[].command[].command "index"
-indexinfo[].command[].indexname "my_predicate_field"
-indexinfo[].command[].command "attribute"
indexinfo[].command[].indexname "my_ancient_int_field"
indexinfo[].command[].command "index"
indexinfo[].command[].indexname "my_ancient_int_field"
diff --git a/config-model/src/test/derived/importedfields/parent_a.sd b/config-model/src/test/derived/importedfields/parent_a.sd
index 4950e5e01c3..1f93b7884e0 100644
--- a/config-model/src/test/derived/importedfields/parent_a.sd
+++ b/config-model/src/test/derived/importedfields/parent_a.sd
@@ -13,14 +13,6 @@ search parent_a {
field int_wset_field type weightedset<int> {
indexing: attribute
}
- field predicate_field type predicate {
- indexing: attribute
- index {
- arity: 8
- lower-bound: 5
- upper-bound: 300
- }
- }
}
import field grandparent_ref.int_field as ancient_int_field {}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummaryValidatorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummaryValidatorTestCase.java
deleted file mode 100644
index b8ec33563b0..00000000000
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsInSummaryValidatorTestCase.java
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.searchdefinition.processing;
-
-import com.yahoo.document.DataType;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-/**
- * @author geirst
- */
-public class ImportedFieldsInSummaryValidatorTestCase {
-
- @Rule
- public final ExpectedException exceptionRule = ExpectedException.none();
-
- @Test
- public void validator_fails_if_imported_predicate_field_is_used_in_document_summary() {
- exceptionRule.expect(IllegalArgumentException.class);
- exceptionRule.expectMessage("For search 'child', document summary 'my_summary', " +
- "imported summary field 'my_predicate_field': Is of type predicate. Not supported in document summaries");
- new SearchModel()
- .addImportedField("my_predicate_field", "ref", "predicate_field")
- .addSummaryField("my_predicate_field", DataType.PREDICATE)
- .resolve();
- }
-
- private static class SearchModel extends ImportedFieldsResolverTestCase.SearchModel {
-
- public SearchModel() {
- super();
- }
-
- public void resolve() {
- super.resolve();
- new ImportedFieldsInSummayValidator(childSearch, null, null, null).process(true);
- }
-
- }
-
-}
-
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
index 815f696acdc..7230f176048 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsResolverTestCase.java
@@ -26,7 +26,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -104,6 +103,15 @@ public class ImportedFieldsResolverTestCase {
.resolve();
}
+ @Test
+ public void resolver_fails_if_imported_field_is_of_type_predicate() {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage(
+ "For search 'child', import field 'my_predicate_field': " +
+ "Field 'predicate_field' via reference field 'ref': Is of type 'predicate'. Not supported");
+ new SearchModel().addImportedField("my_predicate_field", "ref", "predicate_field").resolve();
+ }
+
static class SearchModel {
private final ApplicationPackage app = MockApplicationPackage.createEmpty();