use of com.yahoo.document.update.AssignValueUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testArrayIndexing.
@SuppressWarnings("rawtypes")
@Test
public final void testArrayIndexing() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testarray::whee\"," + " \"fields\": { " + "\"actualarray\": {" + " \"match\": {" + " \"element\": 3," + " \"assign\": \"nalle\"}}}}");
Map<Number, String> matches = new HashMap<>();
FieldUpdate x = doc.getFieldUpdate("actualarray");
for (ValueUpdate v : x.getValueUpdates()) {
MapValueUpdate adder = (MapValueUpdate) v;
final Number key = ((IntegerFieldValue) adder.getValue()).getNumber();
String op = ((StringFieldValue) ((AssignValueUpdate) adder.getUpdate()).getValue()).getString();
matches.put(key, op);
}
assertEquals(1, matches.size());
Number n = Integer.valueOf(3);
assertEquals("nalle", matches.get(n));
}
use of com.yahoo.document.update.AssignValueUpdate 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.AssignValueUpdate 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.AssignValueUpdate 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.AssignValueUpdate 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());
}
Aggregations