Search in sources :

Example 6 with AssignValueUpdate

use of com.yahoo.document.update.AssignValueUpdate 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));
}
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) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) HashMap(java.util.HashMap) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 7 with AssignValueUpdate

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

the class DocumentUpdateTestCase method testRequireThatAddAllCombinesFieldUpdates.

public void testRequireThatAddAllCombinesFieldUpdates() {
    DocumentType docType = new DocumentType("my_type");
    Field field = new Field("my_int", DataType.INT);
    docType.addField(field);
    FieldUpdate fooField = FieldUpdate.createAssign(field, new IntegerFieldValue(1));
    DocumentUpdate fooUpdate = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
    fooUpdate.addFieldUpdate(fooField);
    FieldUpdate barField = FieldUpdate.createAssign(field, new IntegerFieldValue(2));
    DocumentUpdate barUpdate = new DocumentUpdate(docType, new DocumentId("doc:foo:"));
    barUpdate.addFieldUpdate(barField);
    fooUpdate.addAll(barUpdate);
    assertEquals(1, fooUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpdate = fooUpdate.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 8 with AssignValueUpdate

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

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

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

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