aboutsummaryrefslogtreecommitdiffstats
path: root/indexinglanguage/src/test/java
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@verizonmedia.com>2019-12-02 15:21:52 +0100
committerTor Brede Vekterli <vekterli@verizonmedia.com>2019-12-02 15:36:17 +0100
commit423d127475495cd485085648db49e2ad5b923bb6 (patch)
tree78338691551bce779f94259ec1564311b6954d58 /indexinglanguage/src/test/java
parent4e0290915f15ff1edd530daa5b53217e76b785c6 (diff)
Preserve AssignValueUpdates to struct fields in indexing docproc
Would previously be rewritten as MapValueUpdates for unknown reasons. This wouldn't actually work, as an exception would be thrown during serialization when sanity checking code figured out that the MapValue update was attempted used for a non-array/wset field data type.
Diffstat (limited to 'indexinglanguage/src/test/java')
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java
index 5480e0feca7..beed3053692 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/DocumentUpdateTestCase.java
@@ -6,6 +6,7 @@ import com.yahoo.document.datatypes.IntegerFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.Struct;
import com.yahoo.document.update.AddValueUpdate;
+import com.yahoo.document.update.AssignValueUpdate;
import com.yahoo.document.update.FieldUpdate;
import com.yahoo.document.update.ValueUpdate;
import com.yahoo.vespa.indexinglanguage.expressions.Expression;
@@ -64,4 +65,30 @@ public class DocumentUpdateTestCase {
upd = Expression.execute(Expression.fromString("input my_str | index my_str"), upd);
assertTrue(upd.getCreateIfNonExistent());
}
+
+ @Test
+ public void assign_updates_to_structs_are_preserved() throws ParseException {
+ var docType = new DocumentType("my_input");
+ var structType = new StructDataType("foobarstruct");
+ var fooField = new Field("foo", DataType.STRING);
+ var barField = new Field("bar", DataType.STRING);
+ structType.addField(fooField);
+ structType.addField(barField);
+ docType.addField(new Field("mystruct", structType));
+
+ var upd = new DocumentUpdate(docType, "id:scheme:my_input::");
+ var updatedStruct = new Struct(structType);
+ updatedStruct.setFieldValue("foo", new StringFieldValue("new groovy value"));
+ updatedStruct.setFieldValue("bar", new StringFieldValue("totally tubular!"));
+ upd.addFieldUpdate(FieldUpdate.createAssign(docType.getField("mystruct"), updatedStruct));
+
+ upd = Expression.execute(Expression.fromString("input mystruct | passthrough mystruct"), upd);
+ assertEquals(upd.fieldUpdates().size(), 1);
+ var fieldUpdate = upd.getFieldUpdate("mystruct");
+ assertNotNull(fieldUpdate);
+ var valueUpdate = fieldUpdate.getValueUpdate(0);
+ assertTrue(valueUpdate instanceof AssignValueUpdate);
+ var av = (AssignValueUpdate)valueUpdate;
+ assertEquals(av.getValue(), updatedStruct);
+ }
}