Search in sources :

Example 21 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class VespaDocumentDeserializerHead method read.

@Override
public void read(DocumentUpdate update) {
    update.setId(new DocumentId(this));
    update.setDocumentType(readDocumentType());
    int size = getInt(null);
    for (int i = 0; i < size; i++) {
        // TODO: Should use checked method, but doesn't work according to test now.
        update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), 8));
    }
    int sizeAndFlags = getInt(null);
    update.setCreateIfNonExistent(DocumentUpdateFlags.extractFlags(sizeAndFlags).getCreateIfNonExistent());
    size = DocumentUpdateFlags.extractValue(sizeAndFlags);
    for (int i = 0; i < size; i++) {
        int type = getByte(null);
        update.addFieldPathUpdate(FieldPathUpdate.create(FieldPathUpdate.Type.valueOf(type), update.getDocumentType(), this));
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 22 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class IndexingProcessorTestCase method requireThatIndexerProcessesUpdates.

@Test
public void requireThatIndexerProcessesUpdates() {
    DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music");
    DocumentUpdate input = new DocumentUpdate(inputType, "doc:scheme:");
    input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("isbn"), new StringFieldValue("isbnmarker")));
    input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("artist"), new StringFieldValue("69")));
    DocumentOperation output = process(input);
    assertTrue(output instanceof DocumentUpdate);
    DocumentUpdate docUpdate = (DocumentUpdate) output;
    assertEquals(3, docUpdate.getFieldUpdates().size());
    {
        FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(0);
        assertEquals("song", fieldUpdate.getField().getName());
        assertEquals(1, fieldUpdate.getValueUpdates().size());
        ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
        fieldUpdate = docUpdate.getFieldUpdate(1);
        assertEquals("title", fieldUpdate.getField().getName());
        assertEquals(1, fieldUpdate.getValueUpdates().size());
        valueUpdate = fieldUpdate.getValueUpdate(0);
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
    }
    {
        FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(1);
        ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
        assertEquals("title", fieldUpdate.getField().getName());
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
    }
    {
        FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(2);
        ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
        assertEquals("isbn", fieldUpdate.getField().getName());
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
    }
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) DocumentType(com.yahoo.document.DocumentType) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 23 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class DocumentUpdate method toString.

@Override
public String toString() {
    StringBuilder string = new StringBuilder();
    string.append("update of document '");
    string.append(docId);
    string.append("': ");
    string.append("create-if-non-existent=");
    string.append(createIfNonExistent.orElse(false));
    string.append(": ");
    string.append("[");
    for (Iterator<FieldUpdate> i = fieldUpdates.iterator(); i.hasNext(); ) {
        FieldUpdate fieldUpdate = i.next();
        string.append(fieldUpdate);
        if (i.hasNext()) {
            string.append(", ");
        }
    }
    string.append("]");
    if (fieldPathUpdates.size() > 0) {
        string.append(" [ ");
        for (FieldPathUpdate up : fieldPathUpdates) {
            string.append(up.toString() + " ");
        }
        string.append(" ]");
    }
    return string.toString();
}
Also used : FieldUpdate(com.yahoo.document.update.FieldUpdate) FieldPathUpdate(com.yahoo.document.fieldpathupdate.FieldPathUpdate)

Example 24 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class JsonReaderTestCase method testStructUpdate.

@Test
public final void testStructUpdate() throws IOException {
    DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { \"sandra\": \"person\"," + " \"cloud\": \"another person\"}}}}");
    assertEquals(1, put.getFieldUpdates().size());
    FieldUpdate fu = put.getFieldUpdate(0);
    assertEquals(1, fu.getValueUpdates().size());
    ValueUpdate vu = fu.getValueUpdate(0);
    assertTrue(vu instanceof AssignValueUpdate);
    AssignValueUpdate avu = (AssignValueUpdate) vu;
    assertTrue(avu.getValue() instanceof Struct);
    Struct s = (Struct) avu.getValue();
    assertEquals(2, s.getFieldCount());
    assertEquals(new StringFieldValue("person"), s.getFieldValue(s.getField("sandra")));
    GrowableByteBuffer buf = new GrowableByteBuffer();
    DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
    put.serialize(serializer);
    assertEquals(107, buf.position());
}
Also used : AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentSerializer(com.yahoo.document.serialization.DocumentSerializer) FieldUpdate(com.yahoo.document.update.FieldUpdate) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 25 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class JsonReaderTestCase method testAssignToString.

@Test
public final void testAssignToString() throws IOException {
    DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": {" + " \"assign\": \"orOther\" }}" + " }");
    FieldUpdate f = doc.getFieldUpdate("something");
    assertEquals(1, f.size());
    AssignValueUpdate a = (AssignValueUpdate) f.getValueUpdate(0);
    assertEquals(new StringFieldValue("orOther"), a.getValue());
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Aggregations

FieldUpdate (com.yahoo.document.update.FieldUpdate)37 Test (org.junit.Test)17 DocumentUpdate (com.yahoo.document.DocumentUpdate)16 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)15 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)14 ValueUpdate (com.yahoo.document.update.ValueUpdate)12 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)8 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 HashMap (java.util.HashMap)5 DocumentId (com.yahoo.document.DocumentId)4 DocumentType (com.yahoo.document.DocumentType)4 FieldPathUpdate (com.yahoo.document.fieldpathupdate.FieldPathUpdate)4 ArrayList (java.util.ArrayList)4 Field (com.yahoo.document.Field)3 Array (com.yahoo.document.datatypes.Array)3 Struct (com.yahoo.document.datatypes.Struct)3 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)3