use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignMathMissingField.
public void testAssignMathMissingField() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(10));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "num", "", "100 + foobar.bogus"));
docUp.applyTo(doc);
assertEquals(new IntegerFieldValue(10), doc.getFieldValue(doc.getField("num")));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignMathTargetFieldNotSetWithValue.
public void testAssignMathTargetFieldNotSetWithValue() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "num", "", "$value + 5"));
docUp.applyTo(doc);
assertEquals(new IntegerFieldValue(5), doc.getFieldValue(doc.getField("num")));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignMapStructVariable.
public void testAssignMapStructVariable() 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(fv1.getField("title"), new StringFieldValue("thomas"));
fv1.setFieldValue(fv1.getField("rating"), new IntegerFieldValue(32));
mfv.put(new StringFieldValue("foo"), fv1);
Struct fv2 = new Struct(mfv.getDataType().getValueType());
fv2.setFieldValue(fv2.getField("title"), new StringFieldValue("cyril"));
fv2.setFieldValue(fv2.getField("rating"), new IntegerFieldValue(16));
mfv.put(new StringFieldValue("bar"), fv2);
Struct fv3 = new Struct(mfv.getDataType().getValueType());
fv3.setFieldValue(fv3.getField("title"), new StringFieldValue("ulf"));
fv3.setFieldValue(fv3.getField("rating"), new IntegerFieldValue(8));
mfv.put(new StringFieldValue("zoo"), fv3);
doc.setFieldValue(doc.getField("structmap"), mfv);
Struct fv4 = new Struct(mfv.getDataType().getValueType());
fv4.setFieldValue(fv4.getField("title"), new StringFieldValue("cyril"));
fv4.setFieldValue(fv4.getField("rating"), new IntegerFieldValue(48));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "structmap{$x}.rating", "foobar.structmap{$x}.title == \"cyril\"", new IntegerFieldValue(48)));
docUp.applyTo(doc);
MapFieldValue valueNow = (MapFieldValue) doc.getFieldValue("structmap");
assertEquals(fv1, valueNow.get(new StringFieldValue("foo")));
assertEquals(fv4, valueNow.get(new StringFieldValue("bar")));
assertEquals(fv3, valueNow.get(new StringFieldValue("zoo")));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignSerialization.
public void testAssignSerialization() throws Exception {
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
AssignFieldPathUpdate ass = new AssignFieldPathUpdate(docType, "num", "", "3");
ass.setCreateMissingPath(false);
docUp.addFieldPathUpdate(ass);
GrowableByteBuffer buffer = new GrowableByteBuffer();
docUp.serialize(DocumentSerializerFactory.createHead(buffer));
buffer.flip();
DocumentUpdate docUp2 = new DocumentUpdate(DocumentDeserializerFactory.createHead(docMan, buffer));
assertEquals(docUp, docUp2);
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method createDocumentUpdateForSerialization.
private DocumentUpdate createDocumentUpdateForSerialization() {
docMan = DocumentTestCase.setUpCppDocType();
docType = docMan.getDocumentType("serializetest");
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:serialization:xlanguage"));
AssignFieldPathUpdate ass = new AssignFieldPathUpdate(docType, "intfield", "", "3");
ass.setCreateMissingPath(false);
ass.setRemoveIfZero(true);
docUp.addFieldPathUpdate(ass);
Array fArray = new Array(docType.getField("arrayoffloatfield").getDataType());
fArray.add(new FloatFieldValue(12.0f));
fArray.add(new FloatFieldValue(5.0f));
AddFieldPathUpdate add = new AddFieldPathUpdate(docType, "arrayoffloatfield", "", fArray);
docUp.addFieldPathUpdate(add);
RemoveFieldPathUpdate remove = new RemoveFieldPathUpdate(docType, "intfield", "serializetest.intfield > 0");
docUp.addFieldPathUpdate(remove);
return docUp;
}
Aggregations