Search in sources :

Example 6 with RemoveFieldPathUpdate

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;
}
Also used : RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 7 with RemoveFieldPathUpdate

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"));
}
Also used : RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate)

Example 8 with RemoveFieldPathUpdate

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")));
}
Also used : RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate)

Example 9 with RemoveFieldPathUpdate

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());
}
Also used : RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate) RemoveFieldPathUpdate(com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate) AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) Test(org.junit.Test)

Aggregations

RemoveFieldPathUpdate (com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate)9 AddFieldPathUpdate (com.yahoo.document.fieldpathupdate.AddFieldPathUpdate)4 AssignFieldPathUpdate (com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FieldPathUpdate (com.yahoo.document.fieldpathupdate.FieldPathUpdate)1 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Test (org.junit.Test)1