use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class VespaDocumentDeserializerHead method read.
@Override
public void read(DocumentUpdate update) {
update.setId(new DocumentId(this));
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(), 8));
}
int sizeAndFlags = getInt(null);
update.setCreateIfNonExistent(DocumentUpdateFlags.extractFlags(sizeAndFlags).getCreateIfNonExistent());
size = DocumentUpdateFlags.extractValue(sizeAndFlags);
for (int i = 0; i < size; i++) {
int type = getByte(null);
update.addFieldPathUpdate(FieldPathUpdate.create(FieldPathUpdate.Type.valueOf(type), update.getDocumentType(), this));
}
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class IndexingProcessorTestCase method requireThatIndexerProcessesUpdates.
@Test
public void requireThatIndexerProcessesUpdates() {
DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music");
DocumentUpdate input = new DocumentUpdate(inputType, "doc:scheme:");
input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("isbn"), new StringFieldValue("isbnmarker")));
input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("artist"), new StringFieldValue("69")));
DocumentOperation output = process(input);
assertTrue(output instanceof DocumentUpdate);
DocumentUpdate docUpdate = (DocumentUpdate) output;
assertEquals(3, docUpdate.getFieldUpdates().size());
{
FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(0);
assertEquals("song", fieldUpdate.getField().getName());
assertEquals(1, fieldUpdate.getValueUpdates().size());
ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
fieldUpdate = docUpdate.getFieldUpdate(1);
assertEquals("title", fieldUpdate.getField().getName());
assertEquals(1, fieldUpdate.getValueUpdates().size());
valueUpdate = fieldUpdate.getValueUpdate(0);
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
}
{
FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(1);
ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
assertEquals("title", fieldUpdate.getField().getName());
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
}
{
FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(2);
ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
assertEquals("isbn", fieldUpdate.getField().getName());
assertTrue(valueUpdate instanceof AssignValueUpdate);
assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
}
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class DocumentUpdate method toString.
@Override
public String toString() {
StringBuilder string = new StringBuilder();
string.append("update of document '");
string.append(docId);
string.append("': ");
string.append("create-if-non-existent=");
string.append(createIfNonExistent.orElse(false));
string.append(": ");
string.append("[");
for (Iterator<FieldUpdate> i = fieldUpdates.iterator(); i.hasNext(); ) {
FieldUpdate fieldUpdate = i.next();
string.append(fieldUpdate);
if (i.hasNext()) {
string.append(", ");
}
}
string.append("]");
if (fieldPathUpdates.size() > 0) {
string.append(" [ ");
for (FieldPathUpdate up : fieldPathUpdates) {
string.append(up.toString() + " ");
}
string.append(" ]");
}
return string.toString();
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testStructUpdate.
@Test
public final void testStructUpdate() throws IOException {
DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { \"sandra\": \"person\"," + " \"cloud\": \"another person\"}}}}");
assertEquals(1, put.getFieldUpdates().size());
FieldUpdate fu = put.getFieldUpdate(0);
assertEquals(1, fu.getValueUpdates().size());
ValueUpdate vu = fu.getValueUpdate(0);
assertTrue(vu instanceof AssignValueUpdate);
AssignValueUpdate avu = (AssignValueUpdate) vu;
assertTrue(avu.getValue() instanceof Struct);
Struct s = (Struct) avu.getValue();
assertEquals(2, s.getFieldCount());
assertEquals(new StringFieldValue("person"), s.getFieldValue(s.getField("sandra")));
GrowableByteBuffer buf = new GrowableByteBuffer();
DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
put.serialize(serializer);
assertEquals(107, buf.position());
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testAssignToString.
@Test
public final void testAssignToString() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": {" + " \"assign\": \"orOther\" }}" + " }");
FieldUpdate f = doc.getFieldUpdate("something");
assertEquals(1, f.size());
AssignValueUpdate a = (AssignValueUpdate) f.getValueUpdate(0);
assertEquals(new StringFieldValue("orOther"), a.getValue());
}
Aggregations