Search in sources :

Example 61 with DocumentPut

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

the class JsonReaderTestCase method testOldMapStringToArrayOfInt.

@Test
public final void testOldMapStringToArrayOfInt() throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": [" + "{ \"key\": \"bamse\", \"value\": [1, 2, 3] }" + "]}}"));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo parseInfo = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(parseInfo.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, parseInfo.documentId));
    new VespaJsonDocumentReader().readPut(parseInfo.fieldsBuffer, put);
    Document doc = put.getDocument();
    FieldValue f = doc.getFieldValue("actualMapStringToArrayOfInt");
    assertSame(MapFieldValue.class, f.getClass());
    MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
    Array<?> a = (Array<?>) m.get(new StringFieldValue("bamse"));
    assertEquals(3, a.size());
    assertEquals(new IntegerFieldValue(1), a.get(0));
    assertEquals(new IntegerFieldValue(2), a.get(1));
    assertEquals(new IntegerFieldValue(3), a.get(2));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader) Array(com.yahoo.document.datatypes.Array) ByteArrayInputStream(java.io.ByteArrayInputStream) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Test(org.junit.Test)

Example 62 with DocumentPut

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

the class LocalAsyncSession method put.

@Override
public Result put(Document document, DocumentProtocol.Priority pri) {
    long req = getNextRequestId();
    try {
        syncSession.put(new DocumentPut(document), pri);
        addResponse(new DocumentResponse(req));
    } catch (Exception e) {
        addResponse(new DocumentResponse(req, document, e.getMessage(), false));
    }
    return new Result(req);
}
Also used : DocumentResponse(com.yahoo.documentapi.DocumentResponse) DocumentPut(com.yahoo.document.DocumentPut) Result(com.yahoo.documentapi.Result)

Example 63 with DocumentPut

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

the class MessageBusAsyncSession method put.

@Override
public Result put(Document document, DocumentProtocol.Priority pri) {
    PutDocumentMessage msg = new PutDocumentMessage(new DocumentPut(document));
    msg.setPriority(pri);
    return send(msg);
}
Also used : DocumentPut(com.yahoo.document.DocumentPut)

Example 64 with DocumentPut

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

the class Call method unwrapSchemaMapping.

private void unwrapSchemaMapping(Processing processing) {
    final List<DocumentOperation> documentOperations = processing.getDocumentOperations();
    for (int i = 0; i < documentOperations.size(); i++) {
        DocumentOperation documentOperation = documentOperations.get(i);
        if (documentOperation instanceof DocumentPut) {
            DocumentPut putOperation = (DocumentPut) documentOperation;
            if (putOperation.getDocument() instanceof DocumentOperationWrapper) {
                DocumentOperationWrapper proxy = (DocumentOperationWrapper) putOperation.getDocument();
                documentOperations.set(i, new DocumentPut(putOperation, ((DocumentPut) proxy.getWrappedDocumentOperation()).getDocument()));
            }
        }
    }
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut)

Example 65 with DocumentPut

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

the class Call method configDoc.

/**
 * The Document object the proc should work on. Normally the one in arguments, but could be a proxy object
 * if schema mapping or @Accesses is in effect.
 *
 * <p>
 * public for testing
 */
public DocumentPut configDoc(DocumentProcessor docProc, DocumentPut documentPut) {
    if (!docProc.getFieldMap().isEmpty() || docProc.hasAnnotations()) {
        Document document = documentPut.getDocument();
        document = new ProxyDocument(docProc, document, docProc.getDocMap(document.getDataType().getName()));
        DocumentPut newDocumentPut = new DocumentPut(document);
        newDocumentPut.setCondition(documentPut.getCondition());
        documentPut = newDocumentPut;
    }
    return documentPut;
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument) Document(com.yahoo.document.Document) ProxyDocument(com.yahoo.docproc.proxy.ProxyDocument)

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