Search in sources :

Example 1 with AddValueUpdate

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

the class DocumentUpdateTestCase method requireThatArrayOfStructElementAddIsProcessedCorrectly.

@Test
public void requireThatArrayOfStructElementAddIsProcessedCorrectly() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_str", DataType.getArray(DataType.STRING)));
    docType.addField(new Field("my_pos", DataType.getArray(PositionDataType.INSTANCE)));
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
    docUpdate.addFieldUpdate(FieldUpdate.createAdd(docType.getField("my_str"), new StringFieldValue("6;9")));
    docUpdate = Expression.execute(Expression.fromString("input my_str | for_each { to_pos } | index my_pos"), docUpdate);
    assertNotNull(docUpdate);
    assertEquals(0, docUpdate.getFieldPathUpdates().size());
    assertEquals(1, docUpdate.getFieldUpdates().size());
    FieldUpdate fieldUpd = docUpdate.getFieldUpdate(0);
    assertNotNull(fieldUpd);
    assertEquals(docType.getField("my_pos"), fieldUpd.getField());
    assertEquals(1, fieldUpd.getValueUpdates().size());
    ValueUpdate valueUpd = fieldUpd.getValueUpdate(0);
    assertNotNull(valueUpd);
    assertTrue(valueUpd instanceof AddValueUpdate);
    Object val = valueUpd.getValue();
    assertNotNull(val);
    assertTrue(val instanceof Struct);
    Struct pos = (Struct) val;
    assertEquals(PositionDataType.INSTANCE, pos.getDataType());
    assertEquals(new IntegerFieldValue(6), PositionDataType.getXValue(pos));
    assertEquals(new IntegerFieldValue(9), PositionDataType.getYValue(pos));
}
Also used : 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) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 2 with AddValueUpdate

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

the class JsonReaderTestCase method testUpdateWeighted.

@Test
public final void testUpdateWeighted() throws IOException {
    DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"add\": {" + " \"person\": 37," + " \"another person\": 41}}}}");
    Map<String, Integer> weights = new HashMap<>();
    FieldUpdate x = doc.getFieldUpdate("actualset");
    for (ValueUpdate<?> v : x.getValueUpdates()) {
        AddValueUpdate adder = (AddValueUpdate) v;
        final String s = ((StringFieldValue) adder.getValue()).getString();
        weights.put(s, adder.getWeight());
    }
    assertEquals(2, weights.size());
    final String o = "person";
    final String o2 = "another person";
    assertTrue(weights.containsKey(o));
    assertTrue(weights.containsKey(o2));
    assertEquals(Integer.valueOf(37), weights.get(o));
    assertEquals(Integer.valueOf(41), weights.get(o2));
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) HashMap(java.util.HashMap) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) FieldUpdate(com.yahoo.document.update.FieldUpdate) Test(org.junit.Test)

Example 3 with AddValueUpdate

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

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

the class VespaXMLReaderTestCase method testNews5.

@Test
public void testNews5() throws Exception {
    // Adding a few new fields to a Document using different syntax
    VespaXMLFeedReader parser = new VespaXMLFeedReader("src/test/vespaxmlparser/test05.xml", manager);
    VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
    parser.read(op);
    assertEquals(VespaXMLFeedReader.OperationType.UPDATE, op.getType());
    DocumentUpdate docUpdate = op.getDocumentUpdate();
    // url
    assertNull(docUpdate.getFieldUpdate("url"));
    // title
    assertNull(docUpdate.getFieldUpdate("title"));
    // last_downloaded
    assertNull(docUpdate.getFieldUpdate("last_downloaded"));
    // value_long
    // assertNull(docUpdate.getFieldUpdate("value_long"));
    // value_content
    assertNull(docUpdate.getFieldUpdate("value_content"));
    // stringarr
    // .getValueUpdate(0).getValue();
    List stringarr = docUpdate.getFieldUpdate("stringarr").getValueUpdates();
    assertEquals(new StringFieldValue("addString1"), ((ValueUpdate) stringarr.get(0)).getValue());
    assertEquals(new StringFieldValue("addString2"), ((ValueUpdate) stringarr.get(1)).getValue());
    // intarr
    assertNull(docUpdate.getFieldUpdate("intarr"));
    // longarr
    List longarr = docUpdate.getFieldUpdate("longarr").getValueUpdates();
    assertEquals(new LongFieldValue((long) 5), ((ValueUpdate) longarr.get(0)).getValue());
    // bytearr
    assertNull(docUpdate.getFieldUpdate("bytearr"));
    // floatarr
    assertNull(docUpdate.getFieldUpdate("floatarr"));
    // weightedsetint
    assertEquals(new IntegerFieldValue(11), docUpdate.getFieldUpdate("weightedsetint").getValueUpdate(0).getValue());
    assertEquals(new Integer(11), (Integer) ((AddValueUpdate) docUpdate.getFieldUpdate("weightedsetint").getValueUpdate(0)).getWeight());
    assertEquals(new IntegerFieldValue(12), docUpdate.getFieldUpdate("weightedsetint").getValueUpdate(1).getValue());
    assertEquals(new Integer(12), (Integer) ((AddValueUpdate) docUpdate.getFieldUpdate("weightedsetint").getValueUpdate(1)).getWeight());
    // weightedsetstring
    assertEquals(new StringFieldValue("add13"), docUpdate.getFieldUpdate("weightedsetstring").getValueUpdate(0).getValue());
    assertEquals(new Integer(1), (Integer) ((AddValueUpdate) docUpdate.getFieldUpdate("weightedsetstring").getValueUpdate(0)).getWeight());
}
Also used : AddValueUpdate(com.yahoo.document.update.AddValueUpdate) List(java.util.List) Test(org.junit.Test)

Example 5 with AddValueUpdate

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

AddValueUpdate (com.yahoo.document.update.AddValueUpdate)6 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 Test (org.junit.Test)4 ValueUpdate (com.yahoo.document.update.ValueUpdate)3 FieldValue (com.yahoo.document.datatypes.FieldValue)2 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)2 ArrayDataType (com.yahoo.document.ArrayDataType)1 CollectionDataType (com.yahoo.document.CollectionDataType)1 DocumentUpdate (com.yahoo.document.DocumentUpdate)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 Array (com.yahoo.document.datatypes.Array)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)1 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)1 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)1 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)1 PredicateFieldValue (com.yahoo.document.datatypes.PredicateFieldValue)1 ReferenceFieldValue (com.yahoo.document.datatypes.ReferenceFieldValue)1