Search in sources :

Example 16 with Document

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

the class SchemaMappingAndAccessesTest method testProxyAndSecure.

public void testProxyAndSecure() {
    DocumentProcessor procOK = new TestDPSecure();
    Map<Pair<String, String>, String> fieldMap = new HashMap<>();
    fieldMap.put(new Pair<>("album", "titleMapped"), "title");
    procOK.setFieldMap(fieldMap);
    DocumentPut put = new DocumentPut(getDoc());
    Document proxyDoc = new Call(procOK).configDoc(procOK, put).getDocument();
    procOK.process(Processing.of(new DocumentPut(proxyDoc)));
    assertEquals(proxyDoc.getFieldValue("title").toString(), "MyTitle MyTitle");
}
Also used : Call(com.yahoo.docproc.Call) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) HashMap(java.util.HashMap) DocumentPut(com.yahoo.document.DocumentPut) Document(com.yahoo.document.Document) Pair(com.yahoo.collections.Pair)

Example 17 with Document

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

the class DocumentScriptTestCase method processDocument.

private static FieldValue processDocument(FieldValue fieldValue) {
    DocumentType docType = new DocumentType("myDocumentType");
    docType.addField("myField", fieldValue.getDataType());
    Document doc = new Document(docType, "doc:scheme:");
    doc.setFieldValue("myField", fieldValue.clone());
    doc = newScript(docType).execute(ADAPTER_FACTORY, doc);
    return doc.getFieldValue("myField");
}
Also used : DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document)

Example 18 with Document

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

the class LocalSyncSession method update.

@Override
public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) {
    Document document = access.documents.get(update.getId());
    if (document == null) {
        return false;
    }
    update.applyTo(document);
    return true;
}
Also used : Document(com.yahoo.document.Document)

Example 19 with Document

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

the class IndexingProcessorTestCase method requireThatIndexerForwardsDocumentsOfUnknownType.

@Test
public void requireThatIndexerForwardsDocumentsOfUnknownType() {
    Document input = new Document(new DocumentType("unknown"), "doc:scheme:");
    DocumentOperation output = process(new DocumentPut(input));
    assertTrue(output instanceof DocumentPut);
    assertSame(input, ((DocumentPut) output).getDocument());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 20 with Document

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

the class SplitterJoinerTestCase method testSplitJoin.

@Test
public void testSplitJoin() {
    ConfigGetter<SplitterJoinerDocumentProcessorConfig> getter = new ConfigGetter<>(SplitterJoinerDocumentProcessorConfig.class);
    ConfigGetter<DocumentmanagerConfig> docManGetter = new ConfigGetter<>(DocumentmanagerConfig.class);
    SplitterJoinerDocumentProcessorConfig cfg = getter.getConfig("file:src/test/java/com/yahoo/docproc/util/splitter-joiner-document-processor.cfg");
    DocumentmanagerConfig docManCfg = docManGetter.getConfig("file:src/test/java/com/yahoo/docproc/util/documentmanager.docindoc.cfg");
    SplitterDocumentProcessor splitter = new SplitterDocumentProcessor(cfg, docManCfg);
    DocumentTypeManager manager = splitter.manager;
    /**
     ** Create documents: ***
     */
    Document inner1 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:one");
    inner1.setFieldValue("name", new StringFieldValue("Donald Duck"));
    inner1.setFieldValue("content", new StringFieldValue("Lives in Duckburg"));
    Document inner2 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:two");
    inner2.setFieldValue("name", new StringFieldValue("Uncle Scrooge"));
    inner2.setFieldValue("content", new StringFieldValue("Lives in Duckburg, too."));
    Array<Document> innerArray = (Array<Document>) manager.getDocumentType("outerdoc").getField("innerdocuments").getDataType().createFieldValue();
    innerArray.add(inner1);
    innerArray.add(inner2);
    Document outer = new Document(manager.getDocumentType("outerdoc"), "doc:outer:the:only:one");
    outer.setFieldValue("innerdocuments", innerArray);
    /**
     ** End create documents ***
     */
    Processing p = Processing.of(new DocumentPut(outer));
    splitter.process(p);
    assertEquals(2, p.getDocumentOperations().size());
    assertThat(((DocumentPut) (p.getDocumentOperations().get(0))).getDocument(), sameInstance(inner1));
    assertThat(((DocumentPut) (p.getDocumentOperations().get(1))).getDocument(), sameInstance(inner2));
    assertThat(((DocumentPut) (p.getVariable(cfg.contextFieldName()))).getDocument(), sameInstance(outer));
    assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
    assertTrue(innerArray.isEmpty());
    JoinerDocumentProcessor joiner = new JoinerDocumentProcessor(cfg, docManCfg);
    joiner.process(p);
    assertThat(p.getDocumentOperations().size(), equalTo(1));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument(), sameInstance(outer));
    assertThat(p.getVariable(cfg.contextFieldName()), nullValue());
    assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
    assertThat(innerArray.size(), equalTo(2));
    assertThat(innerArray.get(0), sameInstance(inner1));
    assertThat(innerArray.get(1), sameInstance(inner2));
}
Also used : ConfigGetter(com.yahoo.config.subscription.ConfigGetter) DocumentPut(com.yahoo.document.DocumentPut) SplitterJoinerDocumentProcessorConfig(com.yahoo.config.docproc.SplitterJoinerDocumentProcessorConfig) Document(com.yahoo.document.Document) Processing(com.yahoo.docproc.Processing) Array(com.yahoo.document.datatypes.Array) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Aggregations

Document (com.yahoo.document.Document)109 Test (org.junit.Test)63 DocumentType (com.yahoo.document.DocumentType)41 DocumentPut (com.yahoo.document.DocumentPut)40 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)33 ByteArrayInputStream (java.io.ByteArrayInputStream)23 InputStream (java.io.InputStream)18 DocumentId (com.yahoo.document.DocumentId)16 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)13 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)13 HashMap (java.util.HashMap)13 DocumentTypeManager (com.yahoo.document.DocumentTypeManager)12 FieldValue (com.yahoo.document.datatypes.FieldValue)12 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)12 DocumentOperation (com.yahoo.document.DocumentOperation)10 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)8 Array (com.yahoo.document.datatypes.Array)8