use of com.yahoo.document.DocumentUpdate 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());
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testUpdateMatch.
@Test
public final void testUpdateMatch() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"match\": {" + " \"element\": \"person\"," + " \"increment\": 13}}}}");
Map<String, Tuple2<Number, String>> matches = new HashMap<>();
FieldUpdate x = doc.getFieldUpdate("actualset");
for (ValueUpdate<?> v : x.getValueUpdates()) {
MapValueUpdate adder = (MapValueUpdate) v;
final String key = ((StringFieldValue) adder.getValue()).getString();
String op = ((ArithmeticValueUpdate) adder.getUpdate()).getOperator().toString();
Number n = ((ArithmeticValueUpdate) adder.getUpdate()).getOperand();
matches.put(key, new Tuple2<>(n, op));
}
assertEquals(1, matches.size());
final String o = "person";
assertEquals("ADD", matches.get(o).second);
assertEquals(Double.valueOf(13), matches.get(o).first);
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testAssignToWeightedSet.
@Test
public final void testAssignToWeightedSet() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"assign\": {" + " \"person\": 37," + " \"another person\": 41}}}}");
FieldUpdate x = doc.getFieldUpdate("actualset");
assertEquals(1, x.size());
AssignValueUpdate assign = (AssignValueUpdate) x.getValueUpdate(0);
WeightedSet<?> w = (WeightedSet<?>) assign.getValue();
assertEquals(2, w.size());
assertEquals(new Integer(37), w.get(new StringFieldValue("person")));
assertEquals(new Integer(41), w.get(new StringFieldValue("another person")));
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testEmptyStructUpdate.
@Test
public final void testEmptyStructUpdate() throws IOException {
DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { }}}}");
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(0, s.getFieldCount());
GrowableByteBuffer buf = new GrowableByteBuffer();
DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
put.serialize(serializer);
assertEquals(69, buf.position());
}
use of com.yahoo.document.DocumentUpdate in project vespa by vespa-engine.
the class DocumentUpdateJsonSerializerTest method deSerializeDocumentUpdate.
private static DocumentUpdate deSerializeDocumentUpdate(String jsonDoc, String docId) {
final InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes(jsonDoc));
JsonReader reader = new JsonReader(types, rawDoc, parserFactory);
return (DocumentUpdate) reader.readSingleDocument(DocumentParser.SupportedOperation.UPDATE, docId);
}
Aggregations