Search in sources :

Example 1 with MapValueUpdate

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);
    }
}
Also used : Operator(com.yahoo.document.update.ArithmeticValueUpdate.Operator) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) HashMap(java.util.HashMap) 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) Tuple2(com.yahoo.collections.Tuple2) FieldUpdate(com.yahoo.document.update.FieldUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) Test(org.junit.Test)

Example 2 with MapValueUpdate

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));
}
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 3 with MapValueUpdate

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;
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate)

Example 4 with MapValueUpdate

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");
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate) Field(com.yahoo.document.Field) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StructDataType(com.yahoo.document.StructDataType) Struct(com.yahoo.document.datatypes.Struct) Test(org.junit.Test)

Example 5 with MapValueUpdate

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);
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) HashMap(java.util.HashMap) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Tuple2(com.yahoo.collections.Tuple2) FieldUpdate(com.yahoo.document.update.FieldUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) Test(org.junit.Test)

Aggregations

MapValueUpdate (com.yahoo.document.update.MapValueUpdate)6 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)5 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)4 Test (org.junit.Test)4 DocumentUpdate (com.yahoo.document.DocumentUpdate)3 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)3 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)3 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)3 FieldUpdate (com.yahoo.document.update.FieldUpdate)3 ValueUpdate (com.yahoo.document.update.ValueUpdate)3 HashMap (java.util.HashMap)3 Tuple2 (com.yahoo.collections.Tuple2)2 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)2 ArrayDataType (com.yahoo.document.ArrayDataType)1 CollectionDataType (com.yahoo.document.CollectionDataType)1 Field (com.yahoo.document.Field)1 StructDataType (com.yahoo.document.StructDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 CollectionFieldValue (com.yahoo.document.datatypes.CollectionFieldValue)1