Search in sources :

Example 26 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate 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);
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) HashMap(java.util.HashMap) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Tuple2(com.yahoo.collections.Tuple2) FieldUpdate(com.yahoo.document.update.FieldUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) Test(org.junit.Test)

Example 27 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class JsonReaderTestCase method checkSimpleArrayAdd.

private void checkSimpleArrayAdd(DocumentUpdate update) {
    Set<String> toAdd = new HashSet<>();
    FieldUpdate x = update.getFieldUpdate("actualarray");
    for (ValueUpdate<?> v : x.getValueUpdates()) {
        AddValueUpdate adder = (AddValueUpdate) v;
        toAdd.add(((StringFieldValue) adder.getValue()).getString());
    }
    assertEquals(2, toAdd.size());
    assertTrue(toAdd.contains("person"));
    assertTrue(toAdd.contains("another person"));
}
Also used : AddValueUpdate(com.yahoo.document.update.AddValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) HashSet(java.util.HashSet)

Example 28 with FieldUpdate

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

Example 29 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate 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());
}
Also used : AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) DocumentSerializer(com.yahoo.document.serialization.DocumentSerializer) FieldUpdate(com.yahoo.document.update.FieldUpdate) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 30 with FieldUpdate

use of com.yahoo.document.update.FieldUpdate in project vespa by vespa-engine.

the class UriParserTestCase method requireThatUriFieldsCanBeParsed.

@Test
public void requireThatUriFieldsCanBeParsed() throws Exception {
    DocumentTypeManager mgr = new DocumentTypeManager();
    DocumentType docType = new DocumentType("my_doc");
    docType.addField("my_uri", DataType.URI);
    docType.addField("my_arr", DataType.getArray(DataType.URI));
    mgr.registerDocumentType(docType);
    VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test_uri.xml", mgr);
    Iterator<VespaXMLFeedReader.Operation> it = parser.readAll().iterator();
    Document doc = nextDocument(it);
    assertNotNull(doc);
    assertEquals(new StringFieldValue("scheme://host"), doc.getFieldValue("my_uri"));
    assertNull(doc.getFieldValue("my_arr"));
    assertNotNull(doc = nextDocument(it));
    assertNull(doc.getFieldValue("my_uri"));
    FieldValue val = doc.getFieldValue("my_arr");
    assertNotNull(val);
    assertTrue(val instanceof Array);
    Array arr = (Array) val;
    assertEquals(1, arr.size());
    assertEquals(new StringFieldValue("scheme://host"), arr.get(0));
    DocumentUpdate upd = nextUpdate(it);
    assertNotNull(upd);
    assertEquals(1, upd.getFieldUpdates().size());
    FieldUpdate fieldUpd = upd.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_arr"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AddValueUpdate);
    assertEquals(new StringFieldValue("scheme://host"), valueUpd.getValue());
    assertFalse(it.hasNext());
}
Also used : Array(com.yahoo.document.datatypes.Array) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Aggregations

FieldUpdate (com.yahoo.document.update.FieldUpdate)37 Test (org.junit.Test)17 DocumentUpdate (com.yahoo.document.DocumentUpdate)16 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)15 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)14 ValueUpdate (com.yahoo.document.update.ValueUpdate)12 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)8 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 HashMap (java.util.HashMap)5 DocumentId (com.yahoo.document.DocumentId)4 DocumentType (com.yahoo.document.DocumentType)4 FieldPathUpdate (com.yahoo.document.fieldpathupdate.FieldPathUpdate)4 ArrayList (java.util.ArrayList)4 Field (com.yahoo.document.Field)3 Array (com.yahoo.document.datatypes.Array)3 Struct (com.yahoo.document.datatypes.Struct)3 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)3