use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class DocumentUpdateTestCase method testRequireThatAddAllCombinesFieldUpdates.
public void testRequireThatAddAllCombinesFieldUpdates() {
DocumentType docType = new DocumentType("my_type");
Field field = new Field("my_int", DataType.INT);
docType.addField(field);
FieldUpdate fooField = FieldUpdate.createAssign(field, new IntegerFieldValue(1));
DocumentUpdate fooUpdate = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
fooUpdate.addFieldUpdate(fooField);
FieldUpdate barField = FieldUpdate.createAssign(field, new IntegerFieldValue(2));
DocumentUpdate barUpdate = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
barUpdate.addFieldUpdate(barField);
fooUpdate.addAll(barUpdate);
assertEquals(1, fooUpdate.getFieldUpdates().size());
FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(0);
assertNotNull(fieldUpdate);
assertEquals(field, fieldUpdate.getField());
assertEquals(2, fieldUpdate.getValueUpdates().size());
ValueUpdate valueUpdate = fieldUpdate.getValueUpdate(0);
assertNotNull(valueUpdate);
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new IntegerFieldValue(1), valueUpdate.getValue());
assertNotNull(valueUpdate = fieldUpdate.getValueUpdate(1));
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new IntegerFieldValue(2), valueUpdate.getValue());
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class DocumentUpdateTestCase method testUpdatesToTheSameFieldAreCombining.
public void testUpdatesToTheSameFieldAreCombining() {
DocumentType docType = new DocumentType("my_type");
Field field = new Field("my_int", DataType.INT);
docType.addField(field);
DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1)));
update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2)));
assertEquals(1, update.getFieldUpdates().size());
FieldUpdate fieldUpdate = update.getFieldUpdate(0);
assertNotNull(fieldUpdate);
assertEquals(field, fieldUpdate.getField());
assertEquals(2, fieldUpdate.getValueUpdates().size());
ValueUpdate valueUpdate = fieldUpdate.getValueUpdate(0);
assertNotNull(valueUpdate);
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new IntegerFieldValue(1), valueUpdate.getValue());
assertNotNull(valueUpdate = fieldUpdate.getValueUpdate(1));
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new IntegerFieldValue(2), valueUpdate.getValue());
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class VespaDocumentDeserializer42 method read.
public void read(DocumentUpdate update) {
short serializationVersion = getShort(null);
update.setId(new DocumentId(this));
byte contents = getByte(null);
if ((contents & 0x1) == 0) {
throw new DeserializationException("Cannot deserialize DocumentUpdate without doctype");
}
update.setDocumentType(readDocumentType());
int size = getInt(null);
for (int i = 0; i < size; i++) {
// TODO: Should use checked method, but doesn't work according to test now.
update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), serializationVersion));
}
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class VespaXMLUpdateReader method readArithmeticField.
FieldUpdate readArithmeticField(DocumentUpdate update, String type) throws XMLStreamException {
Field f = null;
for (int i = 0; i < reader.getAttributeCount(); i++) {
if ("field".equals(reader.getAttributeName(i).toString())) {
f = update.getDocumentType().getField(reader.getAttributeValue(i));
}
}
if (f == null) {
throw newDeserializeException("Assignment update without \"field\" attribute");
}
FieldUpdate fu = FieldUpdate.create(f);
readArithmetic(update, type, f, fu);
return fu;
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class VespaJsonDocumentReader method addFieldUpdates.
private void addFieldUpdates(DocumentUpdate update, TokenBuffer buffer, String fieldName) {
Field field = update.getType().getField(fieldName);
int localNesting = buffer.nesting();
FieldUpdate fieldUpdate = FieldUpdate.create(field);
buffer.next();
while (localNesting <= buffer.nesting()) {
switch(buffer.currentName()) {
case UPDATE_REMOVE:
createRemoves(buffer, field, fieldUpdate);
break;
case UPDATE_ADD:
createAdds(buffer, field, fieldUpdate);
break;
case UPDATE_MATCH:
fieldUpdate.addValueUpdate(createMapUpdate(buffer, field));
break;
default:
String action = buffer.currentName();
fieldUpdate.addValueUpdate(readSingleUpdate(buffer, field.getDataType(), action));
}
buffer.next();
}
update.addFieldUpdate(fieldUpdate);
}
Aggregations