Search in sources :

Example 11 with AssignValueUpdate

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

the class JsonReaderTestCase method testAssignToString.

@Test
public final void testAssignToString() throws IOException {
    DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"something\": {" + " \"assign\": \"orOther\" }}" + " }");
    FieldUpdate f = doc.getFieldUpdate("something");
    assertEquals(1, f.size());
    AssignValueUpdate a = (AssignValueUpdate) f.getValueUpdate(0);
    assertEquals(new StringFieldValue("orOther"), a.getValue());
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) Test(org.junit.Test)

Example 12 with AssignValueUpdate

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

the class JsonReaderTestCase method testAssignToWeightedSet.

@Test
public final void testAssignToWeightedSet() throws IOException {
    DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"assign\": {" + " \"person\": 37," + " \"another person\": 41}}}}");
    FieldUpdate x = doc.getFieldUpdate("actualset");
    assertEquals(1, x.size());
    AssignValueUpdate assign = (AssignValueUpdate) x.getValueUpdate(0);
    WeightedSet<?> w = (WeightedSet<?>) assign.getValue();
    assertEquals(2, w.size());
    assertEquals(new Integer(37), w.get(new StringFieldValue("person")));
    assertEquals(new Integer(41), w.get(new StringFieldValue("another person")));
}
Also used : DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldUpdate(com.yahoo.document.update.FieldUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) WeightedSet(com.yahoo.document.datatypes.WeightedSet) Test(org.junit.Test)

Example 13 with AssignValueUpdate

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

the class JsonReaderTestCase method testEmptyStructUpdate.

@Test
public final void testEmptyStructUpdate() throws IOException {
    DocumentUpdate put = parseUpdate("{\"update\": \"id:unittest:mirrors:g=test:whee\"," + "\"create\": true," + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { }}}}");
    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(0, s.getFieldCount());
    GrowableByteBuffer buf = new GrowableByteBuffer();
    DocumentSerializer serializer = DocumentSerializerFactory.createHead(buf);
    put.serialize(serializer);
    assertEquals(69, 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) 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)

Example 14 with AssignValueUpdate

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

the class VespaDocumentDeserializer42 method getValueUpdate.

public ValueUpdate getValueUpdate(DataType superType, DataType subType) {
    int vuTypeId = getInt(null);
    ValueUpdate.ValueUpdateClassID op = ValueUpdate.ValueUpdateClassID.getID(vuTypeId);
    if (op == null) {
        throw new IllegalArgumentException("Read type " + vuTypeId + " of bytebuffer, but this is not a legal value update type.");
    }
    switch(op) {
        case ADD:
            {
                FieldValue fval = subType.createFieldValue();
                fval.deserialize(this);
                int weight = getInt(null);
                return new AddValueUpdate(fval, weight);
            }
        case ARITHMETIC:
            int opId = getInt(null);
            ArithmeticValueUpdate.Operator operator = ArithmeticValueUpdate.Operator.getID(opId);
            double operand = getDouble(null);
            return new ArithmeticValueUpdate(operator, operand);
        case ASSIGN:
            {
                byte contents = getByte(null);
                FieldValue fval = null;
                if (contents == (byte) 1) {
                    fval = superType.createFieldValue();
                    fval.deserialize(this);
                }
                return new AssignValueUpdate(fval);
            }
        case CLEAR:
            return new ClearValueUpdate();
        case MAP:
            if (superType instanceof ArrayDataType) {
                CollectionDataType type = (CollectionDataType) superType;
                IntegerFieldValue index = new IntegerFieldValue();
                index.deserialize(this);
                ValueUpdate update = getValueUpdate(type.getNestedType(), null);
                return new MapValueUpdate(index, update);
            } else if (superType instanceof WeightedSetDataType) {
                CollectionDataType type = (CollectionDataType) superType;
                FieldValue fval = type.getNestedType().createFieldValue();
                fval.deserialize(this);
                ValueUpdate update = getValueUpdate(DataType.INT, null);
                return new MapValueUpdate(fval, update);
            } else {
                throw new DeserializationException("MapValueUpdate only works for arrays and weighted sets");
            }
        case REMOVE:
            FieldValue fval = ((CollectionDataType) superType).getNestedType().createFieldValue();
            fval.deserialize(this);
            return new RemoveValueUpdate(fval);
        default:
            throw new DeserializationException("Could not deserialize ValueUpdate, unknown valueUpdateClassID type " + vuTypeId);
    }
}
Also used : MapValueUpdate(com.yahoo.document.update.MapValueUpdate) RemoveValueUpdate(com.yahoo.document.update.RemoveValueUpdate) WeightedSetDataType(com.yahoo.document.WeightedSetDataType) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) CollectionDataType(com.yahoo.document.CollectionDataType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) RemoveValueUpdate(com.yahoo.document.update.RemoveValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) CollectionFieldValue(com.yahoo.document.datatypes.CollectionFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FloatFieldValue(com.yahoo.document.datatypes.FloatFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) ReferenceFieldValue(com.yahoo.document.datatypes.ReferenceFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) ByteFieldValue(com.yahoo.document.datatypes.ByteFieldValue) DoubleFieldValue(com.yahoo.document.datatypes.DoubleFieldValue) StructuredFieldValue(com.yahoo.document.datatypes.StructuredFieldValue) PredicateFieldValue(com.yahoo.document.datatypes.PredicateFieldValue) MapFieldValue(com.yahoo.document.datatypes.MapFieldValue) ArrayDataType(com.yahoo.document.ArrayDataType) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate)

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