Search in sources :

Example 16 with FieldUpdate

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

the class DocumentUpdateTestCase method testRequireThatAddAllCombinesFieldUpdates.

public void testRequireThatAddAllCombinesFieldUpdates() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    FieldUpdate fooField = FieldUpdate.createAssign(field, new IntegerFieldValue(1));
    DocumentUpdate fooUpdate = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
    fooUpdate.addFieldUpdate(fooField);
    FieldUpdate barField = FieldUpdate.createAssign(field, new IntegerFieldValue(2));
    DocumentUpdate barUpdate = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
    barUpdate.addFieldUpdate(barField);
    fooUpdate.addAll(barUpdate);
    assertEquals(1, fooUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(0);
    assertNotNull(fieldUpdate);
    assertEquals(field, fieldUpdate.getField());
    assertEquals(2, fieldUpdate.getValueUpdates().size());
    ValueUpdate valueUpdate = fieldUpdate.getValueUpdate(0);
    assertNotNull(valueUpdate);
    assertTrue(valueUpdate instanceof AssignValueUpdate);
    assertEquals(new IntegerFieldValue(1), valueUpdate.getValue());
    assertNotNull(valueUpdate = fieldUpdate.getValueUpdate(1));
    assertTrue(valueUpdate instanceof AssignValueUpdate);
    assertEquals(new IntegerFieldValue(2), valueUpdate.getValue());
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate)

Example 17 with FieldUpdate

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

the class DocumentUpdateTestCase method testUpdatesToTheSameFieldAreCombining.

public void testUpdatesToTheSameFieldAreCombining() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
    update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1)));
    update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2)));
    assertEquals(1, update.getFieldUpdates().size());
    FieldUpdate fieldUpdate = update.getFieldUpdate(0);
    assertNotNull(fieldUpdate);
    assertEquals(field, fieldUpdate.getField());
    assertEquals(2, fieldUpdate.getValueUpdates().size());
    ValueUpdate valueUpdate = fieldUpdate.getValueUpdate(0);
    assertNotNull(valueUpdate);
    assertTrue(valueUpdate instanceof AssignValueUpdate);
    assertEquals(new IntegerFieldValue(1), valueUpdate.getValue());
    assertNotNull(valueUpdate = fieldUpdate.getValueUpdate(1));
    assertTrue(valueUpdate instanceof AssignValueUpdate);
    assertEquals(new IntegerFieldValue(2), valueUpdate.getValue());
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate)

Example 18 with FieldUpdate

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

the class VespaDocumentDeserializer42 method read.

public void read(DocumentUpdate update) {
    short serializationVersion = getShort(null);
    update.setId(new DocumentId(this));
    byte contents = getByte(null);
    if ((contents & 0x1) == 0) {
        throw new DeserializationException("Cannot deserialize DocumentUpdate without doctype");
    }
    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(), serializationVersion));
    }
}
Also used : DocumentId(com.yahoo.document.DocumentId) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 19 with FieldUpdate

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

the class VespaXMLUpdateReader method readArithmeticField.

FieldUpdate readArithmeticField(DocumentUpdate update, String type) throws XMLStreamException {
    Field f = null;
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        if ("field".equals(reader.getAttributeName(i).toString())) {
            f = update.getDocumentType().getField(reader.getAttributeValue(i));
        }
    }
    if (f == null) {
        throw newDeserializeException("Assignment update without \"field\" attribute");
    }
    FieldUpdate fu = FieldUpdate.create(f);
    readArithmetic(update, type, f, fu);
    return fu;
}
Also used : FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 20 with FieldUpdate

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

the class VespaJsonDocumentReader method addFieldUpdates.

private void addFieldUpdates(DocumentUpdate update, TokenBuffer buffer, String fieldName) {
    Field field = update.getType().getField(fieldName);
    int localNesting = buffer.nesting();
    FieldUpdate fieldUpdate = FieldUpdate.create(field);
    buffer.next();
    while (localNesting <= buffer.nesting()) {
        switch(buffer.currentName()) {
            case UPDATE_REMOVE:
                createRemoves(buffer, field, fieldUpdate);
                break;
            case UPDATE_ADD:
                createAdds(buffer, field, fieldUpdate);
                break;
            case UPDATE_MATCH:
                fieldUpdate.addValueUpdate(createMapUpdate(buffer, field));
                break;
            default:
                String action = buffer.currentName();
                fieldUpdate.addValueUpdate(readSingleUpdate(buffer, field.getDataType(), action));
        }
        buffer.next();
    }
    update.addFieldUpdate(fieldUpdate);
}
Also used : Field(com.yahoo.document.Field) FieldUpdate(com.yahoo.document.update.FieldUpdate)

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