Search in sources :

Example 26 with AssignFieldPathUpdate

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

the class DocumentPathUpdateTestCase method testAssignMathMissingField.

public void testAssignMathMissingField() 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 + foobar.bogus"));
    docUp.applyTo(doc);
    assertEquals(new IntegerFieldValue(10), doc.getFieldValue(doc.getField("num")));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 27 with AssignFieldPathUpdate

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

the class DocumentPathUpdateTestCase method testAssignMathTargetFieldNotSetWithValue.

public void testAssignMathTargetFieldNotSetWithValue() 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", "", "$value + 5"));
    docUp.applyTo(doc);
    assertEquals(new IntegerFieldValue(5), doc.getFieldValue(doc.getField("num")));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 28 with AssignFieldPathUpdate

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

the class DocumentPathUpdateTestCase method testAssignMapStructVariable.

public void testAssignMapStructVariable() 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(fv1.getField("title"), new StringFieldValue("thomas"));
    fv1.setFieldValue(fv1.getField("rating"), new IntegerFieldValue(32));
    mfv.put(new StringFieldValue("foo"), fv1);
    Struct fv2 = new Struct(mfv.getDataType().getValueType());
    fv2.setFieldValue(fv2.getField("title"), new StringFieldValue("cyril"));
    fv2.setFieldValue(fv2.getField("rating"), new IntegerFieldValue(16));
    mfv.put(new StringFieldValue("bar"), fv2);
    Struct fv3 = new Struct(mfv.getDataType().getValueType());
    fv3.setFieldValue(fv3.getField("title"), new StringFieldValue("ulf"));
    fv3.setFieldValue(fv3.getField("rating"), new IntegerFieldValue(8));
    mfv.put(new StringFieldValue("zoo"), fv3);
    doc.setFieldValue(doc.getField("structmap"), mfv);
    Struct fv4 = new Struct(mfv.getDataType().getValueType());
    fv4.setFieldValue(fv4.getField("title"), new StringFieldValue("cyril"));
    fv4.setFieldValue(fv4.getField("rating"), new IntegerFieldValue(48));
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    docUp.addFieldPathUpdate(new AssignFieldPathUpdate(doc.getDataType(), "structmap{$x}.rating", "foobar.structmap{$x}.title == \"cyril\"", new IntegerFieldValue(48)));
    docUp.applyTo(doc);
    MapFieldValue valueNow = (MapFieldValue) doc.getFieldValue("structmap");
    assertEquals(fv1, valueNow.get(new StringFieldValue("foo")));
    assertEquals(fv4, valueNow.get(new StringFieldValue("bar")));
    assertEquals(fv3, valueNow.get(new StringFieldValue("zoo")));
}
Also used : AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 29 with AssignFieldPathUpdate

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

the class DocumentPathUpdateTestCase method testAssignSerialization.

public void testAssignSerialization() throws Exception {
    DocumentUpdate docUp = new DocumentUpdate(docType, new DocumentId("doc:foo:bar"));
    AssignFieldPathUpdate ass = new AssignFieldPathUpdate(docType, "num", "", "3");
    ass.setCreateMissingPath(false);
    docUp.addFieldPathUpdate(ass);
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    docUp.serialize(DocumentSerializerFactory.createHead(buffer));
    buffer.flip();
    DocumentUpdate docUp2 = new DocumentUpdate(DocumentDeserializerFactory.createHead(docMan, buffer));
    assertEquals(docUp, docUp2);
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) AssignFieldPathUpdate(com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate)

Example 30 with AssignFieldPathUpdate

use of com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate 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)

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