summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@verizonmedia.com>2019-07-11 10:56:50 +0200
committerGitHub <noreply@github.com>2019-07-11 10:56:50 +0200
commit27a920c6a3169a2f7261d3d62f67c1b5f8d782a9 (patch)
tree203f72c56af593166a1d19a1496146b61fe60318 /config-model
parente227eb6b32852a715c9b3552362e2e582b0fb9a2 (diff)
parenta634adac46bad16b989051045e1702bda255600e (diff)
Merge pull request #10017 from vespa-engine/geirst/stricter-validation-of-attribute-settings
Setting attribute on a field that has struct or map sub-type(s) is no…
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java21
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexAttributeFieldsValidatorTestCase.java30
2 files changed, 51 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
index 8b523211471..c4e0f4cafef 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
@@ -463,12 +463,33 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer,
}
}
}.visit(indexingScript);
+ } else {
+ if (!getDataType().equals(PositionDataType.INSTANCE) &&
+ !getDataType().equals(DataType.getArray(PositionDataType.INSTANCE)) &&
+ hasAttributeExpression(exp))
+ {
+ throw new IllegalArgumentException("For field '" + getName() + "': Setting attribute on a field that has struct or map sub-type(s) is not supported");
+ }
}
for (SDField structField : getStructFields()) {
structField.setIndexingScript(exp);
}
}
+ private static boolean hasAttributeExpression(ScriptExpression exp) {
+ var visitor = new ExpressionVisitor() {
+ boolean result = false;
+ @Override
+ protected void doVisit(Expression exp) {
+ if (exp instanceof AttributeExpression) {
+ result = true;
+ }
+ }
+ };
+ visitor.visit(exp);
+ return visitor.result;
+ }
+
@Override
public ScriptExpression getIndexingScript() {
return indexingScript;
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexAttributeFieldsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexAttributeFieldsValidatorTestCase.java
index 3ba3745f46e..a0c05193661 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexAttributeFieldsValidatorTestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexAttributeFieldsValidatorTestCase.java
@@ -49,6 +49,36 @@ public class ComplexAttributeFieldsValidatorTestCase {
}
@Test
+ public void throws_when_attribute_is_set_on_a_field_with_struct_sub_type() throws IOException, SAXException {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For field 'struct_array.f2': Setting attribute on a field that has struct or map sub-type(s) is not supported");
+ createModelAndValidate(joinLines(createSearchDefintionWithInvalidStructFieldAttribute("array<s1>")));
+ }
+
+ @Test
+ public void throws_when_attribute_is_set_on_a_field_with_map_sub_type() throws IOException, SAXException {
+ exceptionRule.expect(IllegalArgumentException.class);
+ exceptionRule.expectMessage("For field 'struct_array.f2': Setting attribute on a field that has struct or map sub-type(s) is not supported");
+ createModelAndValidate(joinLines(createSearchDefintionWithInvalidStructFieldAttribute("map<string, int>")));
+ }
+
+ private String createSearchDefintionWithInvalidStructFieldAttribute(String invalidFieldType) {
+ return joinLines("search test {",
+ " document test {",
+ " struct s1 {",
+ " field f1 type int {}",
+ " }",
+ " struct s2 {",
+ " field f2 type " + invalidFieldType + " {}",
+ " }",
+ " field struct_array type array<s2> {",
+ " struct-field f2 { indexing: attribute }",
+ " }",
+ " }",
+ "}");
+ }
+
+ @Test
public void validation_passes_when_only_supported_struct_field_attributes_are_used() throws IOException, SAXException {
createModelAndValidate(joinLines("search test {",
" document test {",