use of com.yahoo.document.update.AssignValueUpdate in project vespa by vespa-engine.
the class GuardTestCase method requireThatInputFieldsAreIncludedByUpdate.
@Test
public void requireThatInputFieldsAreIncludedByUpdate() throws ParseException {
DocumentType docType = new DocumentType("my_input");
docType.addField(new Field("my_lng", DataType.LONG));
docType.addField(new Field("my_str", DataType.STRING));
DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
docUpdate.addFieldUpdate(FieldUpdate.createAssign(docType.getField("my_str"), new StringFieldValue("69")));
assertNotNull(docUpdate = Expression.execute(Expression.fromString("guard { input my_str | to_int | attribute my_lng }"), docUpdate));
assertEquals(0, docUpdate.getFieldPathUpdates().size());
assertEquals(1, docUpdate.getFieldUpdates().size());
FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
assertNotNull(fieldUpd);
assertEquals(docType.getField("my_lng"), fieldUpd.getField());
assertEquals(1, fieldUpd.getValueUpdates().size());
ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
assertNotNull(valueUpd);
assertTrue(valueUpd instanceof AssignValueUpdate);
assertEquals(new LongFieldValue(69), valueUpd.getValue());
}
use of com.yahoo.document.update.AssignValueUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testOldAssignToArray.
@Test
public final void testOldAssignToArray() throws IOException {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testMapStringToArrayOfInt::whee\"," + " \"fields\": { \"actualMapStringToArrayOfInt\": {" + " \"assign\": [" + "{ \"key\": \"bamse\", \"value\": [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.AssignValueUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method assertTensorAssignUpdate.
private static void assertTensorAssignUpdate(String expectedTensor, DocumentUpdate update) {
assertEquals("testtensor", update.getId().getDocType());
assertEquals(TENSOR_DOC_ID, update.getId().toString());
AssignValueUpdate assignUpdate = (AssignValueUpdate) getTensorField(update).getValueUpdate(0);
TensorFieldValue fieldValue = (TensorFieldValue) assignUpdate.getValue();
assertEquals(Tensor.from(expectedTensor), fieldValue.getTensor().get());
}
use of com.yahoo.document.update.AssignValueUpdate 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.AssignValueUpdate 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));
}
Aggregations