aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java35
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java17
2 files changed, 35 insertions, 17 deletions
diff --git a/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java b/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java
index 056185e9811..1298384c4a2 100644
--- a/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java
+++ b/docprocs/src/test/java/com/yahoo/docprocs/indexing/DocumentScriptTestCase.java
@@ -176,12 +176,17 @@ public class DocumentScriptTestCase {
type.addField(new Field("structarray", structArray));
structMap = new MapDataType(DataType.STRING, structType);
type.addField(new Field("structmap", structMap));
+ type.addField(new Field("structfield", structType));
}
- FieldPathUpdate executeWithUpdate(String fieldName, FieldPathUpdate updateIn) {
+ DocumentUpdate executeWithUpdate(String fieldName, FieldPathUpdate updateIn) {
DocumentUpdate update = new DocumentUpdate(type, "doc:scheme:");
update.addFieldPathUpdate(updateIn);
- update = newScript(type, fieldName).execute(ADAPTER_FACTORY, update);
+ return newScript(type, fieldName).execute(ADAPTER_FACTORY, update);
+ }
+
+ FieldPathUpdate executeWithUpdateAndExpectFieldPath(String fieldName, FieldPathUpdate updateIn) {
+ DocumentUpdate update = executeWithUpdate(fieldName, updateIn);
assertEquals(1, update.getFieldPathUpdates().size());
return update.getFieldPathUpdates().get(0);
}
@@ -194,7 +199,7 @@ public class DocumentScriptTestCase {
Struct newElemValue = new Struct(f.structType);
newElemValue.setFieldValue("title", "iron moose 2, the moosening");
- FieldPathUpdate updated = f.executeWithUpdate("structarray", new AssignFieldPathUpdate(f.type, "structarray[10]", newElemValue));
+ FieldPathUpdate updated = f.executeWithUpdateAndExpectFieldPath("structarray", new AssignFieldPathUpdate(f.type, "structarray[10]", newElemValue));
assertTrue(updated instanceof AssignFieldPathUpdate);
AssignFieldPathUpdate assignUpdate = (AssignFieldPathUpdate)updated;
@@ -209,7 +214,7 @@ public class DocumentScriptTestCase {
Struct newElemValue = new Struct(f.structType);
newElemValue.setFieldValue("title", "iron moose 3, moose in new york");
- FieldPathUpdate updated = f.executeWithUpdate("structmap", new AssignFieldPathUpdate(f.type, "structmap{foo}", newElemValue));
+ FieldPathUpdate updated = f.executeWithUpdateAndExpectFieldPath("structmap", new AssignFieldPathUpdate(f.type, "structmap{foo}", newElemValue));
assertTrue(updated instanceof AssignFieldPathUpdate);
AssignFieldPathUpdate assignUpdate = (AssignFieldPathUpdate)updated;
@@ -217,6 +222,28 @@ public class DocumentScriptTestCase {
assertEquals(newElemValue, assignUpdate.getFieldValue());
}
+ @Test
+ public void nested_struct_fieldpath_update_is_not_converted_to_regular_field_value_update() {
+ FieldPathFixture f = new FieldPathFixture();
+
+ StringFieldValue newTitleValue = new StringFieldValue("iron moose 4, moose with a vengeance");
+ DocumentUpdate update = f.executeWithUpdate("structfield", new AssignFieldPathUpdate(f.type, "structfield.title", newTitleValue));
+
+ Document doc = new Document(f.type, "id:test:documentType::balle");
+ Struct s = new Struct(f.structType);
+ s.setFieldValue("title", new StringFieldValue("banan"));
+ doc.setFieldValue("structfield", s);
+
+ update.applyTo(doc);
+
+ assertEquals(1, update.getFieldPathUpdates().size());
+ assertEquals(0, update.getFieldUpdates().size());
+ assertTrue(update.getFieldPathUpdates().get(0) instanceof AssignFieldPathUpdate);
+ AssignFieldPathUpdate assignUpdate = (AssignFieldPathUpdate)update.getFieldPathUpdates().get(0);
+ assertEquals("structfield.title", assignUpdate.getOriginalFieldPath());
+ assertEquals(newTitleValue, assignUpdate.getFieldValue());
+ }
+
private static FieldValue processDocument(FieldValue fieldValue) {
DocumentType docType = new DocumentType("myDocumentType");
docType.addField("myField", fieldValue.getDataType());
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java
index 171c6a8eb9a..5c170fe147e 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java
@@ -20,19 +20,10 @@ public abstract class FieldPathUpdateHelper {
if (!(update instanceof AssignFieldPathUpdate)) {
return false;
}
- for (FieldPathEntry entry : update.getFieldPath()) {
- switch (entry.getType()) {
- case STRUCT_FIELD:
- case MAP_ALL_KEYS:
- case MAP_ALL_VALUES:
- continue;
- case ARRAY_INDEX:
- case MAP_KEY:
- case VARIABLE:
- return false;
- }
- }
- return true;
+ // Only consider field path updates that touch a top-level field as 'complete',
+ // as these may be converted to regular field value updates.
+ return ((update.getFieldPath().size() == 1)
+ && update.getFieldPath().get(0).getType() == FieldPathEntry.Type.STRUCT_FIELD);
}
public static void applyUpdate(FieldPathUpdate update, Document doc) {