Search in sources :

Example 6 with AssignFieldPathUpdate

use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.

the class DocumentScriptTestCase method newPathUpdate.

private static DocumentUpdate newPathUpdate(FieldValue documentFieldValue, FieldValue extraFieldValue) {
    DocumentType type = newDocumentType();
    DocumentUpdate update = new DocumentUpdate(type, "doc:scheme:");
    if (documentFieldValue != null) {
        update.addFieldPathUpdate(new AssignFieldPathUpdate(type, "documentField", documentFieldValue));
    }
    if (extraFieldValue != null) {
        update.addFieldPathUpdate(new AssignFieldPathUpdate(type, "extraField", extraFieldValue));
    }
    return update;
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentType(com.yahoo.document.DocumentType) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 7 with AssignFieldPathUpdate

use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.

the class DocumentScriptTestCase method processPathUpdate.

private static ValueUpdate<?> processPathUpdate(FieldValue fieldValue) {
    DocumentType docType = new DocumentType("myDocumentType");
    docType.addField("myField", fieldValue.getDataType());
    DocumentUpdate update = new DocumentUpdate(docType, "doc:scheme:");
    update.addFieldPathUpdate(new AssignFieldPathUpdate(docType, "myField", fieldValue));
    update = newScript(docType).execute(ADAPTER_FACTORY, update);
    return update.getFieldUpdate("myField").getValueUpdate(0);
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentType(com.yahoo.document.DocumentType) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 8 with AssignFieldPathUpdate

use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.

the class DocumentPathUpdateTestCase method testApplyAssignMath.

public void testApplyAssignMath() throws Exception {
    Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
    doc.setFieldValue(doc.getField("num"), new IntegerFieldValue(34));
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "num", "", "($value * 2) / $value"));
    docUp.applyTo(doc);
    assertEquals(new IntegerFieldValue(2), doc.getFieldValue(doc.getField("num")));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 9 with AssignFieldPathUpdate

use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.

the class DocumentPathUpdateTestCase method testAssignMapNoexist.

public void testAssignMapNoexist() 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"));
    docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "structmap{foo}", "", fv1));
    docUp.applyTo(doc);
    MapFieldValue valueNow = (MapFieldValue) doc.getFieldValue("structmap");
    assertEquals(fv1, valueNow.get(new StringFieldValue("foo")));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 10 with AssignFieldPathUpdate

use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate in project vespa by vespa-engine.

the class DocumentPathUpdateTestCase method testAddAndAssignList.

public void testAddAndAssignList() throws Exception {
    Document doc = new Document(docMan.getDocumentType("foobar"), new DocumentId("doc:something:foooo"));
    assertNull(doc.getFieldValue("strarray"));
    Array strArray = new Array(doc.getField("strarray").getDataType());
    strArray.add(new StringFieldValue("hello hello"));
    strArray.add(new StringFieldValue("blah blah"));
    doc.setFieldValue("strarray", strArray);
    assertNotNull(doc.getFieldValue("strarray"));
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "strarray[1]", "", new StringFieldValue("assigned val 1")));
    Array adds = new Array(doc.getField("strarray").getDataType());
    adds.add(new StringFieldValue("new value"));
    docUp.addFieldPathUpdate(new AddFieldPathUpdate(doc.getDataType(), "strarray", "", adds));
    docUp.applyTo(doc);
    List docList = (List) doc.getFieldValue("strarray");
    assertEquals(3, docList.size());
    assertEquals(new StringFieldValue("hello hello"), docList.get(0));
    assertEquals(new StringFieldValue("assigned val 1"), docList.get(1));
    assertEquals(new StringFieldValue("new value"), docList.get(2));
}
Also used : AddFieldPathUpdate(com.yahoo.document.fieldpathupdate.AddFieldPathUpdate) List(java.util.List) ArrayList(java.util.ArrayList) 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