diff options
author | Geir Storli <geirst@yahooinc.com> | 2023-07-03 14:18:16 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2023-07-03 14:18:16 +0000 |
commit | 60819f2638b4b3d7bcb27e62d6b56431055c9ab9 (patch) | |
tree | fb29161f68835d67c53289a7dd2d35b8a9d9c568 /config-model | |
parent | e02a187ae0951b3ee506ea930080b7b67a857df2 (diff) |
Improve validation of complex fields using struct field attributes.
With this more unsupported (and rare setups) are caught by the validator.
Diffstat (limited to 'config-model')
3 files changed, 47 insertions, 2 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/document/ComplexAttributeFieldUtils.java b/config-model/src/main/java/com/yahoo/schema/document/ComplexAttributeFieldUtils.java index 993c9180f78..ebafd8f1d24 100644 --- a/config-model/src/main/java/com/yahoo/schema/document/ComplexAttributeFieldUtils.java +++ b/config-model/src/main/java/com/yahoo/schema/document/ComplexAttributeFieldUtils.java @@ -70,6 +70,9 @@ public class ComplexAttributeFieldUtils { return false; } } + if (!structField.isImportedField() && hasStructFieldAttributes(structField)) { + return false; + } } return true; } else { @@ -77,6 +80,19 @@ public class ComplexAttributeFieldUtils { } } + private static boolean hasStructFieldAttributes(ImmutableSDField field) { + for (var structField : field.getStructFields()) { + var attribute = structField.getAttributes().get(structField.getName()); + if (attribute != null) { + return true; + } + if (hasStructFieldAttributes(structField)) { + return true; + } + } + return false; + } + public static boolean isPrimitiveType(Attribute attribute) { return attribute.getCollectionType().equals(Attribute.CollectionType.SINGLE) && isPrimitiveType(attribute.getDataType()); diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldAttributesValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldAttributesValidator.java index 8515c34a377..a3dc2b52b93 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldAttributesValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/ComplexFieldsWithStructFieldAttributesValidator.java @@ -82,7 +82,8 @@ public class ComplexFieldsWithStructFieldAttributesValidator extends Validator { if (structField.usesStructOrMap() && structField.wasConfiguredToDoAttributing()) { result.add(structField.getName()); } - result.addAll(getStructFieldAttributes(structField.getStructFields(), returnAllTypes)); + // If we encounter struct field attributes underneath this level, those are not supported and should be returned. + result.addAll(getStructFieldAttributes(structField.getStructFields(), true)); } return result; } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java index c673d5899e8..f3517f9ef48 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/application/validation/ComplexFieldsValidatorTestCase.java @@ -68,9 +68,37 @@ public class ComplexFieldsValidatorTestCase { "}", "}")); }); - assertTrue(exception.getMessage().contains(getExpectedMessage("docTopics (docTopics.topics)"))); + assertTrue(exception.getMessage().contains(getExpectedMessage("docTopics (docTopics.topics, docTopics.topics.id, docTopics.topics.label)"))); } + @Test + void throws_exception_when_struct_field_inside_nested_struct_array_is_specified_as_attribute() throws IOException, SAXException { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + createModelAndValidate(joinLines( + "schema test {", + "document test {", + "struct item {", + "field name type string {}", + "field color type string {}", + "field type type string {}", + "}", + "struct itembox {", + "field items type array<item> {}", + "}", + "field cabinet type map<string, itembox> {", + "struct-field key { indexing: attribute }", + "struct-field value.items {", + "struct-field name { indexing: attribute }", + "struct-field color { indexing: attribute }", + "}", + "}", + "}", + "}")); + }); + assertTrue(exception.getMessage().contains(getExpectedMessage("cabinet (cabinet.value.items.name, cabinet.value.items.color)"))); + } + + private String getExpectedMessage(String unsupportedFields) { return "For cluster 'mycluster', search 'test': " + "The following complex fields do not support using struct field attributes: " + |