Search in sources :

Example 1 with AssignValueUpdate

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());
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Example 2 with AssignValueUpdate

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));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Array(com.yahoo.document.datatypes.Array) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 3 with AssignValueUpdate

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());
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate)

Example 4 with AssignValueUpdate

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);
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 5 with 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));
}
Also used : MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) Array(com.yahoo.document.datatypes.Array) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Aggregations

AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)14 FieldUpdate (com.yahoo.document.update.FieldUpdate)12 Test (org.junit.Test)10 DocumentUpdate (com.yahoo.document.DocumentUpdate)9 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 ValueUpdate (com.yahoo.document.update.ValueUpdate)8 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)4 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)4 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)4 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)4 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)4 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)3 Array (com.yahoo.document.datatypes.Array)2 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)2 Struct (com.yahoo.document.datatypes.Struct)2 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)2 DocumentSerializer (com.yahoo.document.serialization.DocumentSerializer)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)2 ArrayDataType (com.yahoo.document.ArrayDataType)1 CollectionDataType (com.yahoo.document.CollectionDataType)1