use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentScriptTestCase method newPathUpdate.
private static DocumentUpdate newPathUpdate(FieldValue documentFieldValue, FieldValue extraFieldValue) {
DocumentType type = newDocumentType();
DocumentUpdate update = new DocumentUpdate(type, "doc:scheme:");
if (documentFieldValue != null) {
update.addFieldPathUpdate(new AssignFieldPathUpdate(type, "documentField", documentFieldValue));
}
if (extraFieldValue != null) {
update.addFieldPathUpdate(new AssignFieldPathUpdate(type, "extraField", extraFieldValue));
}
return update;
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentScriptTestCase method processPathUpdate.
private static ValueUpdate<?> processPathUpdate(FieldValue fieldValue) {
DocumentType docType = new DocumentType("myDocumentType");
docType.addField("myField", fieldValue.getDataType());
DocumentUpdate update = new DocumentUpdate(docType, "doc:scheme:");
update.addFieldPathUpdate(new AssignFieldPathUpdate(docType, "myField", fieldValue));
update = newScript(docType).execute(ADAPTER_FACTORY, update);
return update.getFieldUpdate("myField").getValueUpdate(0);
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testApplyAssignMath.
public void testApplyAssignMath() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(34));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "num", "", "($value * 2) / $value"));
docUp.applyTo(doc);
assertEquals(new IntegerFieldValue(2), doc.getFieldValue(doc.getField("num")));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignMapNoexist.
public void testAssignMapNoexist() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
MapFieldValue mfv = new MapFieldValue((MapDataType) doc.getField("structmap").getDataType());
Struct fv1 = new Struct(mfv.getDataType().getValueType());
fv1.setFieldValue("title", new StringFieldValue("thomas"));
fv1.setFieldValue("rating", new IntegerFieldValue(32));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "structmap{foo}", "", fv1));
docUp.applyTo(doc);
MapFieldValue valueNow = (MapFieldValue) doc.getFieldValue("structmap");
assertEquals(fv1, valueNow.get(new StringFieldValue("foo")));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAddAndAssignList.
public void testAddAndAssignList() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
assertNull(doc.getFieldValue("strarray"));
Array strArray = new Array(doc.getField("strarray").getDataType());
strArray.add(new StringFieldValue("hello hello"));
strArray.add(new StringFieldValue("blah blah"));
doc.setFieldValue("strarray", strArray);
assertNotNull(doc.getFieldValue("strarray"));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "strarray[1]", "", new StringFieldValue("assigned val 1")));
Array adds = new Array(doc.getField("strarray").getDataType());
adds.add(new StringFieldValue("new value"));
docUp.addFieldPathUpdate(new AddFieldPathUpdate(doc.getDataType(), "strarray", "", adds));
docUp.applyTo(doc);
List docList = (List) doc.getFieldValue("strarray");
assertEquals(3, docList.size());
assertEquals(new StringFieldValue("hello hello"), docList.get(0));
assertEquals(new StringFieldValue("assigned val 1"), docList.get(1));
assertEquals(new StringFieldValue("new value"), docList.get(2));
}
Aggregations