use of com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate 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;
}
use of com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testApplyRemoveEntireListField.
public void testApplyRemoveEntireListField() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
assertNull(doc.getFieldValue("strarray"));
Array<StringFieldValue> strArray = new Array<>(doc.getField("strarray").getDataType());
strArray.add(new StringFieldValue("this list"));
strArray.add(new StringFieldValue("should be"));
strArray.add(new StringFieldValue("totally removed"));
doc.setFieldValue("strarray", strArray);
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:toast:jam"));
docUp.addFieldPathUpdate(new RemoveFieldPathUpdate(doc.getDataType(), "strarray", null));
docUp.applyTo(doc);
assertNull(doc.getFieldValue("strarray"));
}
use of com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate in project vespa by vespa-engine.
the class DocumentPathUpdateTestCase method testApplyRemoveMultiWset.
public void testApplyRemoveMultiWset() throws Exception {
Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
assertNull(doc.getFieldValue("strwset"));
WeightedSet<StringFieldValue> strwset = new WeightedSet<>(doc.getDataType().getField("strwset").getDataType());
strwset.put(new StringFieldValue("hello hello"), 10);
strwset.put(new StringFieldValue("remove val 1"), 20);
doc.setFieldValue("strwset", strwset);
assertNotNull(doc.getFieldValue("strwset"));
DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
docUp.addFieldPathUpdate(new RemoveFieldPathUpdate(doc.getDataType(), "strwset{remove val 1}", ""));
docUp.applyTo(doc);
assertEquals(1, ((WeightedSet) doc.getFieldValue("strwset")).size());
WeightedSet docWset = (WeightedSet) doc.getFieldValue("strwset");
assertEquals(new Integer(10), docWset.get(new StringFieldValue("hello hello")));
}
use of com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate in project vespa by vespa-engine.
the class PathUpdateToDocumentTestCase method requireThatRemoveIsConverted.
@Test
public void requireThatRemoveIsConverted() {
DocumentType docType = new DocumentType("my_type");
ArrayDataType arrType = DataType.getArray(DataType.INT);
docType.addField(new Field("my_arr", arrType));
FieldPathUpdate upd = new RemoveFieldPathUpdate(docType, "my_arr", "");
Document doc = FieldPathUpdateHelper.newPartialDocument(null, upd);
assertNotNull(doc);
FieldValue obj = doc.getFieldValue("my_arr");
assertTrue(obj instanceof Array);
Array arr = (Array) obj;
assertEquals(0, arr.size());
}
Aggregations