Search in sources :

Example 11 with AssignFieldPathUpdate

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

Example 12 with AssignFieldPathUpdate

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

Example 13 with AssignFieldPathUpdate

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

Example 14 with AssignFieldPathUpdate

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

Example 15 with AssignFieldPathUpdate

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

Aggregations

AssignFieldPathUpdate (com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)35 AddFieldPathUpdate (com.yahoo.document.fieldpathupdate.AddFieldPathUpdate)9 FieldPathUpdate (com.yahoo.document.fieldpathupdate.FieldPathUpdate)9 Test (org.junit.Test)9 RemoveFieldPathUpdate (com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate)8 FieldValue (com.yahoo.document.datatypes.FieldValue)3 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DocumentType (com.yahoo.document.DocumentType)2 DocumentUpdate (com.yahoo.document.DocumentUpdate)2 Struct (com.yahoo.document.datatypes.Struct)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1