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));
}
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));
}
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"));
}
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());
}
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());
}
Aggregations