use of com.yahoo.document.DocumentUpdate 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;
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class SimpleAdapterFactoryTestCase method requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField.
@Test
public void requireThatFieldUpdateCanHaveManyPartialUpdatesForOneField() {
DocumentType docType = new DocumentType("my_type");
DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:foo:1");
Field field = new Field("my_int", DataType.INT);
docType.addField(field);
FieldUpdate fieldUpdate = FieldUpdate.create(field);
fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(1));
fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(2));
fieldUpdate.addValueUpdate(ValueUpdate.createIncrement(4));
docUpdate.addFieldUpdate(fieldUpdate);
SimpleAdapterFactory factory = new SimpleAdapterFactory();
List<UpdateAdapter> adapters = factory.newUpdateAdapterList(docUpdate);
assertEquals(4, adapters.size());
UpdateAdapter adapter = adapters.get(0);
assertNotNull(adapter);
assertEquals(new IntegerFieldValue(1), adapter.getInputValue("my_int"));
assertNotNull(adapter = adapters.get(1));
assertEquals(new IntegerFieldValue(2), adapter.getInputValue("my_int"));
assertNotNull(adapter = adapters.get(2));
assertEquals(new IntegerFieldValue(4), adapter.getInputValue("my_int"));
assertNotNull(adapter = adapters.get(3));
// always add an adapter for complete updates
assertNull(adapter.getInputValue("my_int"));
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class SimpleAdapterFactoryTestCase method requireThatCompleteUpdatesAreCombined.
@Test
public void requireThatCompleteUpdatesAreCombined() {
DocumentType docType = new DocumentType("my_type");
DocumentUpdate update = new DocumentUpdate(docType, "doc:foo:1");
Field field1 = new Field("int1", DataType.INT);
Field field2 = new Field("int2", DataType.INT);
Field field3 = new Field("int3", DataType.INT);
docType.addField(field1);
docType.addField(field2);
docType.addField(field3);
update.addFieldUpdate(FieldUpdate.createAssign(field1, new IntegerFieldValue(10)));
update.addFieldUpdate(FieldUpdate.createAssign(field2, new IntegerFieldValue(20)));
update.addFieldUpdate(FieldUpdate.createIncrement(field3, 30));
SimpleAdapterFactory factory = new SimpleAdapterFactory();
List<UpdateAdapter> adapters = factory.newUpdateAdapterList(update);
assertEquals(2, adapters.size());
}
Aggregations