summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2021-10-01 16:56:32 +0200
committerGitHub <noreply@github.com>2021-10-01 16:56:32 +0200
commit4fe9367ec8e0153330dde29294525f6893079e77 (patch)
tree0c8358793ce1c1bc1c5cb1171aa578219e73b5a9
parent82a8c6019b9a961a26be658cb6c15d21bea158f1 (diff)
parent3b28877e3f8492df65051c1e6f9d85c6a65a8378 (diff)
Merge pull request #19400 from vespa-engine/geirst/fix-importing-complex-fields-from-parents-using-inheritance
Fix importing complex fields from parents using inheritance
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java2
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsTestCase.java66
2 files changed, 66 insertions, 2 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 02df81fbbb3..4d553054aaf 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
@@ -293,7 +293,7 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer,
for (Field field : subType.fieldSet()) {
SDField subField = new SDField(sdoc, name.concat(".").concat(field.getName()), field.getDataType(),
subType, new Matching(), true, recursion + 1);
- structFields.put(field.getName(), subField);
+ structFields.putIfAbsent(field.getName(), subField);
}
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsTestCase.java
index 8ace11a3c73..cb240a25963 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/ImportedFieldsTestCase.java
@@ -3,6 +3,7 @@ package com.yahoo.searchdefinition.processing;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.SearchBuilder;
+import com.yahoo.searchdefinition.derived.AttributeFields;
import com.yahoo.searchdefinition.document.ImportedComplexField;
import com.yahoo.searchdefinition.document.ImportedField;
import com.yahoo.searchdefinition.parser.ParseException;
@@ -14,6 +15,7 @@ import static org.junit.Assert.assertEquals;
import static com.yahoo.config.model.test.TestUtil.joinLines;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* @author geirst
@@ -459,4 +461,66 @@ public class ImportedFieldsTestCase {
assertSearchNotContainsImportedField(fieldName, search);
}
}
-}
+
+ @Test
+ public void field_with_struct_field_attributes_can_be_imported_from_parents_that_use_inheritance() throws ParseException {
+ var builder = buildParentsUsingInheritance();
+
+ assertParentContainsEntriesAttributes(builder.getSearch("parent_a"));
+ assertParentContainsEntriesAttributes(builder.getSearch("parent_b"));
+
+ var child = builder.getSearch("child");
+ checkImportedField("entries_from_a", "ref_parent_a", "parent_a", "entries", child, true);
+ checkImportedField("entries_from_a.key", "ref_parent_a", "parent_a", "entries.key", child, true);
+ checkImportedField("entries_from_a.value", "ref_parent_a", "parent_a", "entries.value", child, true);
+
+ checkImportedField("entries_from_b", "ref_parent_b", "parent_b", "entries", child, true);
+ checkImportedField("entries_from_b.key", "ref_parent_b", "parent_b", "entries.key", child, true);
+ checkImportedField("entries_from_b.value", "ref_parent_b", "parent_b", "entries.value", child, true);
+ }
+
+ private void assertParentContainsEntriesAttributes(Search parent) {
+ var attrs = new AttributeFields(parent);
+ assertTrue(attrs.containsAttribute("entries.key"));
+ assertTrue(attrs.containsAttribute("entries.value"));
+ }
+
+ private SearchBuilder buildParentsUsingInheritance() throws ParseException {
+ var builder = new SearchBuilder();
+ builder.importString(joinLines("schema parent_a {",
+ "document parent_a {",
+ " struct Entry {",
+ " field key type string {}",
+ " field value type string {}",
+ " }",
+ " field entries type array<Entry> {",
+ " indexing: summary",
+ " struct-field key { indexing: attribute }",
+ " struct-field value { indexing: attribute }",
+ " }",
+ "}",
+ "}"));
+
+ builder.importString(joinLines("schema parent_b {",
+ "document parent_b inherits parent_a {",
+ "}",
+ "}"));
+
+ builder.importString(joinLines("schema child {",
+ "document child {",
+ " field ref_parent_a type reference<parent_a> {",
+ " indexing: attribute",
+ " }",
+ " field ref_parent_b type reference<parent_b> {",
+ " indexing: attribute",
+ " }",
+ "}",
+ "import field ref_parent_a.entries as entries_from_a {}",
+ "import field ref_parent_b.entries as entries_from_b {}",
+ "}"));
+
+ builder.build();
+ return builder;
+ }
+
+ }