Search in sources :

Example 1 with DocumentUpdate

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

the class MockReader method read.

@Override
public void read(Operation operation) throws Exception {
    if (finished) {
        return;
    }
    byte whatToDo = stream.getNextOperation();
    DocumentId id = new DocumentId("id:banana:banana::doc1");
    DocumentType docType = new DocumentType("banana");
    switch(whatToDo) {
        case 0:
            finished = true;
            break;
        case 1:
            Document doc = new Document(docType, id);
            operation.setDocument(doc);
            break;
        case 2:
            operation.setRemove(id);
            break;
        case 3:
            operation.setDocumentUpdate(new DocumentUpdate(docType, id));
            break;
        case 4:
            throw new RuntimeException("boom");
    }
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document)

Example 2 with DocumentUpdate

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

the class SchemaMappingAndAccessesTest method testMappedDocUpdateAPI.

public void testMappedDocUpdateAPI() {
    Document doc = getDoc();
    DocumentType type = doc.getDataType();
    DocumentUpdate dud = new DocumentUpdate(type, new DocumentId("doc:map:test:1"));
    FieldUpdate assignSingle = FieldUpdate.createAssign(type.getField("title"), new StringFieldValue("something"));
    Map<String, String> fieldMap = new HashMap<>();
    fieldMap.put("t", "title");
    fieldMap.put("a", "artist");
    ProxyDocumentUpdate pup = new ProxyDocumentUpdate(dud, fieldMap);
    pup.addFieldUpdate(assignSingle);
    assertEquals(pup.getFieldUpdates(), dud.getFieldUpdates());
    assertEquals(pup.getDocumentType(), dud.getDocumentType());
    assertEquals(pup.getFieldUpdate(new com.yahoo.document.Field("title")).size(), 1);
    assertEquals(pup.getFieldUpdate(0), dud.getFieldUpdate(0));
    assertEquals(pup.getFieldUpdate("title"), dud.getFieldUpdate("title"));
    assertEquals(pup.getId(), dud.getId());
    assertEquals(pup.getType(), dud.getType());
    assertEquals(pup.applyTo(doc), dud);
    assertEquals(doc.getFieldValue("title").getWrappedValue(), "something");
    assertEquals(pup, dud);
    assertEquals(pup.hashCode(), dud.hashCode());
    assertEquals(pup.toString(), dud.toString());
    assertEquals(pup.size(), dud.size());
    assertEquals(pup.getWrappedDocumentOperation().getId().toString(), "doc:map:test:1");
}
Also used : HashMap(java.util.HashMap) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 3 with DocumentUpdate

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

the class DocumentScriptTestCase method newFieldUpdate.

private static DocumentUpdate newFieldUpdate(FieldValue documentFieldValue, FieldValue extraFieldValue) {
    DocumentType type = newDocumentType();
    DocumentUpdate update = new DocumentUpdate(type, "doc:scheme:");
    if (documentFieldValue != null) {
        update.addFieldUpdate(FieldUpdate.createAssign(type.getField("documentField"), documentFieldValue));
    }
    if (extraFieldValue != null) {
        update.addFieldUpdate(FieldUpdate.createAssign(type.getField("extraField"), extraFieldValue));
    }
    return update;
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentType(com.yahoo.document.DocumentType)

Example 4 with DocumentUpdate

use of com.yahoo.document.DocumentUpdate 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 5 with DocumentUpdate

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

the class DocumentScriptTestCase method processFieldUpdate.

private static ValueUpdate<?> processFieldUpdate(FieldValue fieldValue) {
    DocumentType docType = new DocumentType("myDocumentType");
    docType.addField("myField", fieldValue.getDataType());
    DocumentUpdate update = new DocumentUpdate(docType, "doc:scheme:");
    update.addFieldUpdate(FieldUpdate.createAssign(docType.getField("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)

Aggregations

DocumentUpdate (com.yahoo.document.DocumentUpdate)43 Test (org.junit.Test)24 FieldUpdate (com.yahoo.document.update.FieldUpdate)16 DocumentType (com.yahoo.document.DocumentType)15 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)12 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InputStream (java.io.InputStream)9 Document (com.yahoo.document.Document)8 DocumentOperation (com.yahoo.document.DocumentOperation)8 DocumentPut (com.yahoo.document.DocumentPut)7 DocumentRemove (com.yahoo.document.DocumentRemove)6 DocumentId (com.yahoo.document.DocumentId)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 ValueUpdate (com.yahoo.document.update.ValueUpdate)5 HashMap (java.util.HashMap)5