aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@verizonmedia.com>2019-07-11 07:59:15 +0000
committerGeir Storli <geirst@verizonmedia.com>2019-07-11 07:59:15 +0000
commita634adac46bad16b989051045e1702bda255600e (patch)
tree3e06bd22e0a97026dcdeb391cdb40fb95ce3aca1
parent9eadbd143c75a5f10b9429deb1ed0d0abc55ff13 (diff)
Setting attribute on a field that has struct or map sub-type(s) is not supported.
Fail instead of silently ignoring it as that makes the user believe it should work.
-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 {",