use of com.yahoo.document.update.MapValueUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testArithmeticOperators.
@SuppressWarnings({ "cast", "unchecked", "rawtypes" })
@Test
public final void testArithmeticOperators() throws IOException {
Tuple2[] operations = new Tuple2[] { new Tuple2<String, Operator>(UPDATE_DECREMENT, ArithmeticValueUpdate.Operator.SUB), new Tuple2<String, Operator>(UPDATE_DIVIDE, ArithmeticValueUpdate.Operator.DIV), new Tuple2<String, Operator>(UPDATE_INCREMENT, ArithmeticValueUpdate.Operator.ADD), new Tuple2<String, Operator>(UPDATE_MULTIPLY, ArithmeticValueUpdate.Operator.MUL) };
for (Tuple2<String, Operator> operator : operations) {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"match\": {" + " \"element\": \"person\"," + " \"" + (String) operator.first + "\": 13}}}}");
Map<String, Tuple2<Number, Operator>> matches = new HashMap<>();
FieldUpdate x = doc.getFieldUpdate("actualset");
for (ValueUpdate v : x.getValueUpdates()) {
MapValueUpdate adder = (MapValueUpdate) v;
final String key = ((StringFieldValue) adder.getValue()).getString();
Operator op = ((ArithmeticValueUpdate) adder.getUpdate()).getOperator();
Number n = ((ArithmeticValueUpdate) adder.getUpdate()).getOperand();
matches.put(key, new Tuple2<>(n, op));
}
assertEquals(1, matches.size());
final String o = "person";
assertSame(operator.second, matches.get(o).second);
assertEquals(Double.valueOf(13), matches.get(o).first);
}
}
use of com.yahoo.document.update.MapValueUpdate 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));
}
use of com.yahoo.document.update.MapValueUpdate in project vespa by vespa-engine.
the class MapReader method createMapUpdate.
@SuppressWarnings("rawtypes")
public static ValueUpdate createMapUpdate(TokenBuffer buffer, Field field) {
buffer.next();
MapValueUpdate m = (MapValueUpdate) MapReader.createMapUpdate(buffer, field.getDataType(), null, null);
buffer.next();
// must generate the field value in parallell with the actual
return m;
}
use of com.yahoo.document.update.MapValueUpdate in project vespa by vespa-engine.
the class DocumentScriptTestCase method requireThatLinguisticsSpanTreeIsRemovedFromStructStringFields.
@Test
public void requireThatLinguisticsSpanTreeIsRemovedFromStructStringFields() {
StructDataType structType = new StructDataType("myStruct");
structType.addField(new Field("myString", DataType.STRING));
Struct in = new Struct(structType);
in.setFieldValue("myString", newString(SpanTrees.LINGUISTICS, "mySpanTree"));
Struct out = (Struct) processDocument(in);
assertSpanTrees(out.getFieldValue("myString"), "mySpanTree");
StringFieldValue str = (StringFieldValue) ((MapValueUpdate) processFieldUpdate(in)).getUpdate().getValue();
assertSpanTrees(str, "mySpanTree");
str = (StringFieldValue) ((MapValueUpdate) processFieldUpdate(in)).getUpdate().getValue();
assertSpanTrees(str, "mySpanTree");
}
use of com.yahoo.document.update.MapValueUpdate 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);
}
Aggregations