Search in sources :

Example 11 with ValueUpdate

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

the class DocumentUpdateTestCase method testUpdatesToTheSameFieldAreCombining.

public void testUpdatesToTheSameFieldAreCombining() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
    update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1)));
    update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2)));
    assertEquals(1, update.getFieldUpdates().size());
    FieldUpdate fieldUpdate = update.getFieldUpdate(0);
    assertNotNull(fieldUpdate);
    assertEquals(field, fieldUpdate.getField());
    assertEquals(2, fieldUpdate.getValueUpdates().size());
    ValueUpdate valueUpdate = fieldUpdate.getValueUpdate(0);
    assertNotNull(valueUpdate);
    assertTrue(valueUpdate instanceof AssignValueUpdate);
    assertEquals(new IntegerFieldValue(1), valueUpdate.getValue());
    assertNotNull(valueUpdate = fieldUpdate.getValueUpdate(1));
    assertTrue(valueUpdate instanceof AssignValueUpdate);
    assertEquals(new IntegerFieldValue(2), valueUpdate.getValue());
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate)

Example 12 with ValueUpdate

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

the class IndexingProcessorTestCase method requireThatIndexerProcessesUpdates.

@Test
public void requireThatIndexerProcessesUpdates() {
    DocumentType inputType = indexer.getDocumentTypeManager().getDocumentType("music");
    DocumentUpdate input = new DocumentUpdate(inputType, "doc:scheme:");
    input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("isbn"), new StringFieldValue("isbnmarker")));
    input.addFieldUpdate(FieldUpdate.createAssign(inputType.getField("artist"), new StringFieldValue("69")));
    DocumentOperation output = process(input);
    assertTrue(output instanceof DocumentUpdate);
    DocumentUpdate docUpdate = (DocumentUpdate) output;
    assertEquals(3, docUpdate.getFieldUpdates().size());
    {
        FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(0);
        assertEquals("song", fieldUpdate.getField().getName());
        assertEquals(1, fieldUpdate.getValueUpdates().size());
        ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
        fieldUpdate = docUpdate.getFieldUpdate(1);
        assertEquals("title", fieldUpdate.getField().getName());
        assertEquals(1, fieldUpdate.getValueUpdates().size());
        valueUpdate = fieldUpdate.getValueUpdate(0);
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
    }
    {
        FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(1);
        ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
        assertEquals("title", fieldUpdate.getField().getName());
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("69"), valueUpdate.getValue());
    }
    {
        FieldUpdate fieldUpdate = docUpdate.getFieldUpdate(2);
        ValueUpdate<?> valueUpdate = fieldUpdate.getValueUpdate(0);
        assertEquals("isbn", fieldUpdate.getField().getName());
        assertTrue(valueUpdate instanceof AssignValueUpdate);
        assertEquals(new StringFieldValue("isbnmarker"), valueUpdate.getValue());
    }
}
Also used : ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) DocumentOperation(com.yahoo.document.DocumentOperation) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) DocumentType(com.yahoo.document.DocumentType) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 13 with ValueUpdate

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

the class JsonReaderTestCase method testStructUpdate.

@Test
public final void testStructUpdate() throws IOException {
    DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { \"sandra\": \"person\"," + " \"cloud\": \"another person\"}}}}");
    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(2, s.getFieldCount());
    assertEquals(new StringFieldValue("person"), s.getFieldValue(s.getField("sandra")));
    GrowableByteBuffer buf = new GrowableByteBuffer();
    DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
    put.serialize(serializer);
    assertEquals(107, 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) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) 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 14 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate 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 15 with ValueUpdate

use of com.yahoo.document.update.ValueUpdate 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

ValueUpdate (com.yahoo.document.update.ValueUpdate)21 Test (org.junit.Test)16 FieldUpdate (com.yahoo.document.update.FieldUpdate)12 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)10 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)8 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)7 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)5 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)5 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)5 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)3 Struct (com.yahoo.document.datatypes.Struct)3 FieldValue (com.yahoo.document.datatypes.FieldValue)2 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)2 DocumentSerializer (com.yahoo.document.serialization.DocumentSerializer)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)2 HashMap (java.util.HashMap)2 Tuple2 (com.yahoo.collections.Tuple2)1 ArrayDataType (com.yahoo.document.ArrayDataType)1 CollectionDataType (com.yahoo.document.CollectionDataType)1