use of com.yahoo.document.Document in project vespa by vespa-engine.
the class SplitterDocumentProcessor method process.
@Override
public Progress process(Processing processing) {
if (processing.getDocumentOperations().size() != 1) {
// we were given more than one document, return
log.log(LogLevel.DEBUG, "More than one document given, returning. (Was given " + processing.getDocumentOperations().size() + " documents).");
return Progress.DONE;
}
if (!doProcessOuterDocument(processing.getDocumentOperations().get(0), documentTypeName)) {
return Progress.DONE;
}
Document outerDoc = ((DocumentPut) processing.getDocumentOperations().get(0)).getDocument();
;
@SuppressWarnings("unchecked") Array<Document> innerDocuments = (Array<Document>) outerDoc.getFieldValue(arrayFieldName);
if (innerDocuments == null) {
// the document does not have the field, return
log.log(LogLevel.DEBUG, "The given Document does not have a field value for field " + arrayFieldName + ", returning. (Was given " + outerDoc + ").");
return Progress.DONE;
}
if (innerDocuments.size() == 0) {
// the array is empty, return
log.log(LogLevel.DEBUG, "The given Document does not have any elements in array field " + arrayFieldName + ", returning. (Was given " + outerDoc + ").");
return Progress.DONE;
}
split(processing, innerDocuments);
return Progress.DONE;
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class ProcessingUpdateTestCase method testProcessingUpdates.
public void testProcessingUpdates() {
DocumentType articleType = new DocumentType("article");
articleType.addField(new Field("body", DataType.STRING, true));
articleType.addField(new Field("title", DataType.STRING, true));
dtm = new DocumentTypeManager();
dtm.registerDocumentType(articleType);
put = new DocumentPut(articleType, "doc:banana:apple");
put.getDocument().setFieldValue("body", "this is the body of the article, blah blah blah");
FieldUpdate upd = FieldUpdate.createAssign(articleType.getField("body"), new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"));
update = new DocumentUpdate(articleType, new DocumentId("doc:grape:orange"));
update.addFieldUpdate(upd);
DocprocService service = new DocprocService("update");
DocumentProcessor firstP = new TitleDocumentProcessor();
service.setCallStack(new CallStack().addLast(firstP));
service.setInService(true);
Processing p = new Processing();
p.addDocumentOperation(put);
p.addDocumentOperation(update);
service.process(p);
while (service.doWork()) {
}
List<DocumentOperation> operations = p.getDocumentOperations();
Document first = ((DocumentPut) operations.get(0)).getDocument();
assertEquals(new StringFieldValue("this is the body of the article, blah blah blah"), first.getFieldValue("body"));
assertEquals(new StringFieldValue("body blah blah blah "), first.getFieldValue("title"));
DocumentUpdate second = (DocumentUpdate) operations.get(1);
FieldUpdate firstUpd = second.getFieldUpdate(0);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, firstUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"), firstUpd.getValueUpdate(0).getValue());
FieldUpdate secondUpd = second.getFieldUpdate(1);
assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, secondUpd.getValueUpdate(0).getValueUpdateClassID());
assertEquals(new StringFieldValue("body blahdi blahdi blahdi "), secondUpd.getValueUpdate(0).getValue());
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonReaderTestCase method testMap.
@Test
public final void testMap() throws IOException {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"put\": \"id:unittest:testmap::whee\"," + " \"fields\": { \"actualmap\": {" + " \"nalle\": \"kalle\", \"tralle\": \"skalle\"}}}"));
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(doc.getField("actualmap"));
assertSame(MapFieldValue.class, f.getClass());
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) f;
assertEquals(2, m.size());
assertEquals(new StringFieldValue("kalle"), m.get(new StringFieldValue("nalle")));
assertEquals(new StringFieldValue("skalle"), m.get(new StringFieldValue("tralle")));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonReaderTestCase method testCompleteFeedWithCreateAndCondition.
@Test
public final void testCompleteFeedWithCreateAndCondition() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": \"smoketest\"," + " \"nalle\": \"bamse\"}}" + ", " + "{" + "\"condition\":\"bla\"," + "\"update\": \"id:unittest:testarray::whee\"," + " \"create\":true," + " \"fields\": { " + "\"actualarray\": {" + " \"add\": [" + " \"person\"," + " \"another person\"]}}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation d = r.next();
Document doc = ((DocumentPut) d).getDocument();
smokeTestDoc(doc);
d = r.next();
DocumentUpdate update = (DocumentUpdate) d;
checkSimpleArrayAdd(update);
assertThat(update.getCreateIfNonExistent(), is(true));
assertThat(update.getCondition().getSelection(), is("bla"));
d = r.next();
DocumentRemove remove = (DocumentRemove) d;
assertEquals("smoke", remove.getId().getDocType());
assertNull(r.next());
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JsonReaderTestCase method testCompleteFeedWithEmptyDoc.
@Test
public final void testCompleteFeedWithEmptyDoc() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[{\"put\": \"id:unittest:smoke::whee\"," + " \"fields\": {}}" + ", " + "{\"update\": \"id:unittest:testarray::whee\"," + " \"fields\": {}}" + ", " + "{\"remove\": \"id:unittest:smoke::whee\"}]"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentOperation d = r.next();
Document doc = ((DocumentPut) d).getDocument();
assertEquals("smoke", doc.getId().getDocType());
d = r.next();
DocumentUpdate update = (DocumentUpdate) d;
assertEquals("testarray", update.getId().getDocType());
d = r.next();
DocumentRemove remove = (DocumentRemove) d;
assertEquals("smoke", remove.getId().getDocType());
assertNull(r.next());
}
Aggregations