use of com.yahoo.document.update.ClearValueUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method readClearField.
@Test
public final void readClearField() {
InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("{\"update\": \"id:unittest:smoke::whee\"," + " \"fields\": { \"int1\": {" + " \"assign\": null }}" + " }"));
JsonReader r = new JsonReader(types, rawDoc, parserFactory);
DocumentUpdate doc = (DocumentUpdate) r.readSingleDocument(DocumentParser.SupportedOperation.UPDATE, "id:unittest:smoke::whee");
FieldUpdate f = doc.getFieldUpdate("int1");
assertEquals(1, f.size());
assertTrue(f.getValueUpdate(0) instanceof ClearValueUpdate);
assertNull(f.getValueUpdate(0).getValue());
}
use of com.yahoo.document.update.ClearValueUpdate in project vespa by vespa-engine.
the class JsonReaderTestCase method testAssignUpdateOfNullTensor.
@Test
public void testAssignUpdateOfNullTensor() {
ClearValueUpdate clearUpdate = (ClearValueUpdate) getTensorField(createAssignUpdateWithMappedTensor(null)).getValueUpdate(0);
assertTrue(clearUpdate != null);
assertTrue(clearUpdate.getValue() == null);
}
use of com.yahoo.document.update.ClearValueUpdate 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);
}
}
Aggregations