summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorLester Solbakken <lesters@oath.com>2018-10-23 13:14:05 +0200
committerLester Solbakken <lesters@oath.com>2018-10-23 13:14:05 +0200
commit4a5cbaddbd6fe2efa49b5a54cdcb258d010f6812 (patch)
tree3f77bdc942b691a7bacdb3def6adf6256c1b626b /config-model
parent123c5a40b52018090a9a7d36ab2699b85bd12328 (diff)
Check that assumption of struct data type is correct
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java80
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/DisallowComplexMapAndWsetKeyTypesTestCase.java5
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>>");