diff options
author | Lester Solbakken <lesters@users.noreply.github.com> | 2018-10-24 08:38:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-24 08:38:34 +0200 |
commit | fce53d10fb4ba25d8c0449b18eebd9eef830cdf1 (patch) | |
tree | b32cdb50db25785f5384d06b6271c8aa56035d0d | |
parent | 4dc3f26a79c75a9ea6ef8116afdb02fbf8f4a4fc (diff) | |
parent | 4a5cbaddbd6fe2efa49b5a54cdcb258d010f6812 (diff) |
Merge pull request #7417 from vespa-engine/lesters/allow-array-map-struct-value
Check that assumption of struct data type is correct
2 files changed, 47 insertions, 38 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 55260b6e68f..dd2ffba20ec 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 @@ -290,14 +290,16 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, if (dataType instanceof CollectionDataType) { dataType = ((CollectionDataType)dataType).getNestedType(); } - SDDocumentType subType = sdoc != null ? sdoc.getType(dataType.getName()) : null; - if (subType == null) { - throw new IllegalArgumentException("Could not find struct '" + dataType.getName() + "'."); - } - for (Field field : subType.fieldSet()) { - SDField subField = new SDField(sdoc, name.concat(".").concat(field.getName()), field.getDataType(), - isHeader, subType, new Matching(), true, recursion + 1); - structFields.put(field.getName(), subField); + if (dataType instanceof StructDataType) { + SDDocumentType subType = sdoc != null ? sdoc.getType(dataType.getName()) : null; + if (subType == null) { + throw new IllegalArgumentException("Could not find struct '" + dataType.getName() + "'."); + } + for (Field field : subType.fieldSet()) { + SDField subField = new SDField(sdoc, name.concat(".").concat(field.getName()), field.getDataType(), + isHeader, subType, new Matching(), true, recursion + 1); + structFields.put(field.getName(), subField); + } } } } @@ -305,41 +307,43 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, public void populateWithStructMatching(SDDocumentType sdoc, String name, DataType dataType, Matching superFieldMatching) { DataType dt = getFirstStructOrMapRecursive(); - if (dt != null) { - if (dataType instanceof MapDataType) { - MapDataType mdt = (MapDataType) dataType; - - Matching keyFieldMatching = new Matching(); - if (superFieldMatching != null) { - keyFieldMatching.merge(superFieldMatching); - } - SDField keyField = structFields.get(name.concat(".key")); - if (keyField != null) { - keyField.populateWithStructMatching(sdoc, name.concat(".key"), mdt.getKeyType(), keyFieldMatching); - keyField.setMatching(keyFieldMatching); - } + if (dt == null) { + return; + } + if (dataType instanceof MapDataType) { + MapDataType mdt = (MapDataType) dataType; - Matching valueFieldMatching = new Matching(); - if (superFieldMatching != null) { - valueFieldMatching.merge(superFieldMatching); - } - SDField valueField = structFields.get(name.concat(".value")); - if (valueField != null) { - valueField.populateWithStructMatching(sdoc, name.concat(".value"), mdt.getValueType(), - valueFieldMatching); - valueField.setMatching(valueFieldMatching); - } + Matching keyFieldMatching = new Matching(); + if (superFieldMatching != null) { + keyFieldMatching.merge(superFieldMatching); + } + SDField keyField = structFields.get(name.concat(".key")); + if (keyField != null) { + keyField.populateWithStructMatching(sdoc, name.concat(".key"), mdt.getKeyType(), keyFieldMatching); + keyField.setMatching(keyFieldMatching); + } - } else { + Matching valueFieldMatching = new Matching(); + if (superFieldMatching != null) { + valueFieldMatching.merge(superFieldMatching); + } + SDField valueField = structFields.get(name.concat(".value")); + if (valueField != null) { + valueField.populateWithStructMatching(sdoc, name.concat(".value"), mdt.getValueType(), + valueFieldMatching); + valueField.setMatching(valueFieldMatching); + } - if (dataType instanceof CollectionDataType) { - dataType = ((CollectionDataType)dataType).getNestedType(); - } + } else { + if (dataType instanceof CollectionDataType) { + dataType = ((CollectionDataType)dataType).getNestedType(); + } + if (dataType instanceof StructDataType) { SDDocumentType subType = sdoc != null ? sdoc.getType(dataType.getName()) : null; if (subType != null) { for (Field f : subType.fieldSet()) { if (f instanceof SDField) { - SDField field = (SDField)f; + SDField field = (SDField) f; Matching subFieldMatching = new Matching(); if (superFieldMatching != null) { subFieldMatching.merge(superFieldMatching); @@ -348,11 +352,11 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer, SDField subField = structFields.get(field.getName()); if (subField != null) { subField.populateWithStructMatching(sdoc, name.concat(".").concat(field.getName()), field.getDataType(), - subFieldMatching); + subFieldMatching); subField.setMatching(subFieldMatching); } } else { - throw new IllegalArgumentException("Field in struct is not SDField " + f.getName()); + throw new IllegalArgumentException("Field in struct is not SDField " + f.getName()); } } } else { diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java index d6e31ac8934..675e04191f8 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java @@ -26,6 +26,11 @@ public class DisallowComplexMapAndWsetKeyTypesTestCase { testFieldType("array<map<mystruct,string>>"); } + @Test + public void requireThatNestedComplexValuesForMapSucceed() throws ParseException { + testFieldType("array<map<string,mystruct>>"); + } + @Test(expected = IllegalArgumentException.class) public void requireThatNestedComplexTypesForWsetFail() throws ParseException { testFieldType("array<weightedset<mystruct>>"); |