use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testDivideByZero.
public void testDivideByZero() 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 / ($value - 10)"));
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 testApplyAssignSingle.
public void testApplyAssignSingle() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
assertNull(doc.getFieldValue("strfoo"));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "strfoo", "", new StringFieldValue("something")));
docUp.applyTo(doc);
assertEquals(new StringFieldValue("something"), doc.getFieldValue("strfoo"));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignMapNoexistNocreate.
public void testAssignMapNoexistNocreate() 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"));
AssignFieldPathUpdate ass = new AssignFieldPathUpdate(doc.getDataType(), "structmap{foo}", "", fv1);
ass.setCreateMissingPath(false);
docUp.addFieldPathUpdate(ass);
docUp.applyTo(doc);
MapFieldValue valueNow = (MapFieldValue) doc.getFieldValue("structmap");
assertNull(valueNow);
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignMathTargetFieldNotSet.
public void testAssignMathTargetFieldNotSet() 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", "", "100"));
docUp.applyTo(doc);
assertEquals(new IntegerFieldValue(100), doc.getFieldValue(doc.getField("num")));
}
use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testAssignWsetRemoveIfZero.
public void testAssignWsetRemoveIfZero() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
assertNull(doc.getFieldValue(doc.getField("strwset")));
WeightedSet<StringFieldValue> strwset = new WeightedSet<>(doc.getDataType().getField("strwset").getDataType());
strwset.put(new StringFieldValue("hello hello"), 164);
strwset.put(new StringFieldValue("blahdi blahdi"), 243);
doc.setFieldValue(doc.getField("strwset"), strwset);
assertNotNull(doc.getFieldValue(doc.getField("strwset")));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
AssignFieldPathUpdate upd = new AssignFieldPathUpdate(doc.getDataType(), "strwset{hello hello}", "", "$value - 164");
upd.setRemoveIfZero(true);
docUp.addFieldPathUpdate(upd);
docUp.applyTo(doc);
WeightedSet docWset = (WeightedSet) doc.getFieldValue(doc.getField("strwset"));
assertEquals(1, docWset.size());
assertEquals(new Integer(243), docWset.get(new StringFieldValue("blahdi blahdi")));
}
Aggregations