use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method getTensorField.
private static FieldUpdate getTensorField(DocumentUpdate update) {
FieldUpdate fieldUpdate = update.getFieldUpdate("mappedtensorfield");
assertEquals(1, fieldUpdate.size());
return fieldUpdate;
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method readSingleDocumentUpdate.
@Test
public final void readSingleDocumentUpdate() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": {" + " \"assign\": \"orOther\" }}" + " }"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentUpdate doc = (DocumentUpdate) r.readSingleDocument(DocumentParser.SupportedOperation.UPDATE, "id:unittest:smoke::whee");
FieldUpdate f = doc.getFieldUpdate("something");
assertEquals(1, f.size());
assertTrue(f.getValueUpdate(0) instanceof AssignValueUpdate);
}
use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testAssignToArray.
@Test
public final void testAssignToArray() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": {" + " \"assign\": { \"bamse\": [1, 2, 3] }}}}");
FieldUpdate f = doc.getFieldUpdate("actualMapStringToArrayOfInt");
assertEquals(1, f.size());
AssignValueUpdate assign = (AssignValueUpdate) f.getValueUpdate(0);
MapFieldValue<?, ?> m = (MapFieldValue<?, ?>) assign.getValue();
Array<?> a = (Array<?>) m.get(new StringFieldValue("bamse"));
assertEquals(3, a.size());
assertEquals(new IntegerFieldValue(1), a.get(0));
assertEquals(new IntegerFieldValue(2), a.get(1));
assertEquals(new IntegerFieldValue(3), a.get(2));
}
use of com.yahoo.document.update.FieldUpdate 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.FieldUpdate in project vespa by vespa-engine.
the class DocumentUpdateTestCase method testGenerateSerializedFile.
public void testGenerateSerializedFile() throws IOException {
docMan = DocumentTestCase.setUpCppDocType();
DocumentType type = docMan.getDocumentType("serializetest");
DocumentUpdate upd = new DocumentUpdate(type, new DocumentId("doc:update:test"));
FieldUpdate serAssign = FieldUpdate.createAssign(type.getField("intfield"), new IntegerFieldValue(4));
upd.addFieldUpdate(serAssign);
FieldUpdate serClearField = FieldUpdate.createClearField(type.getField("floatfield"));
upd.addFieldUpdate(serClearField);
List<FloatFieldValue> arrayOfFloat = new ArrayList<>();
arrayOfFloat.add(new FloatFieldValue(5.00f));
arrayOfFloat.add(new FloatFieldValue(4.23f));
arrayOfFloat.add(new FloatFieldValue(-1.00f));
FieldUpdate serAdd = FieldUpdate.createAddAll(type.getField("arrayoffloatfield"), arrayOfFloat);
upd.addFieldUpdate(serAdd);
GrowableByteBuffer buf = new GrowableByteBuffer(100, 2.0f);
upd.serialize(buf);
int size = buf.position();
buf.position(0);
FileOutputStream fos = new FileOutputStream("src/tests/data/serializeupdatejava.dat");
fos.write(buf.array(), 0, size);
fos.close();
}
Aggregations