Search in sources :

Example 66 with DocumentPut

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

the class VespaJsonDocumentReader method createDocumentOperation.

public DocumentOperation createDocumentOperation(DocumentType documentType, DocumentParseInfo documentParseInfo) {
    final DocumentOperation documentOperation;
    try {
        switch(documentParseInfo.operationType) {
            case PUT:
                documentOperation = new DocumentPut(new Document(documentType, documentParseInfo.documentId));
                readPut(documentParseInfo.fieldsBuffer, (DocumentPut) documentOperation);
                verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
                break;
            case REMOVE:
                documentOperation = new DocumentRemove(documentParseInfo.documentId);
                break;
            case UPDATE:
                documentOperation = new DocumentUpdate(documentType, documentParseInfo.documentId);
                readUpdate(documentParseInfo.fieldsBuffer, (DocumentUpdate) documentOperation);
                verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT);
                break;
            default:
                throw new IllegalStateException("Implementation out of sync with itself. This is a bug.");
        }
    } catch (JsonReaderException e) {
        throw JsonReaderException.addDocId(e, documentParseInfo.documentId);
    }
    if (documentParseInfo.create.isPresent()) {
        if (!(documentOperation instanceof DocumentUpdate)) {
            throw new RuntimeException("Could not set create flag on non update operation.");
        }
        DocumentUpdate update = (DocumentUpdate) documentOperation;
        update.setCreateIfNonExistent(documentParseInfo.create.get());
    }
    return documentOperation;
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentRemove(com.yahoo.document.DocumentRemove) DocumentUpdate(com.yahoo.document.DocumentUpdate) JsonReaderException(com.yahoo.document.json.JsonReaderException) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document)

Example 67 with DocumentPut

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

the class FieldPathUpdate method applyTo.

public void applyTo(Document doc) {
    if (selector == null) {
        FieldPathIteratorHandler handler = getIteratorHandler(doc);
        doc.iterateNested(fieldPath, 0, handler);
    } else {
        ResultList results = selector.getMatchingResultList(new DocumentPut(doc));
        for (ResultList.ResultPair rp : results.getResults()) {
            if (rp.getResult() == Result.TRUE) {
                FieldPathIteratorHandler handler = getIteratorHandler(doc);
                handler.getVariables().clear();
                handler.getVariables().putAll(rp.getVariables());
                doc.iterateNested(fieldPath, 0, handler);
            }
        }
    }
}
Also used : ResultList(com.yahoo.document.select.ResultList) FieldPathIteratorHandler(com.yahoo.document.datatypes.FieldPathIteratorHandler) DocumentPut(com.yahoo.document.DocumentPut)

Aggregations

DocumentPut (com.yahoo.document.DocumentPut)67 Document (com.yahoo.document.Document)40 DocumentType (com.yahoo.document.DocumentType)35 Test (org.junit.Test)30 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)23 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 DocumentOperation (com.yahoo.document.DocumentOperation)13 DocumentId (com.yahoo.document.DocumentId)12 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)11 FieldValue (com.yahoo.document.datatypes.FieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)10 DocumentRemove (com.yahoo.document.DocumentRemove)8 DocumentUpdate (com.yahoo.document.DocumentUpdate)7 Array (com.yahoo.document.datatypes.Array)7 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)6 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)5