@SuppressWarnings({ "unchecked" })
    private static FieldValue applyUpdate(ValueUpdate update, FieldValue value) {
        if (update instanceof ClearValueUpdate) {
            return value;
        } else if (update instanceof AssignValueUpdate) {
            value.assign(update.getValue());
            return value;
        } else if (update instanceof AddValueUpdate) {
            if (value instanceof Array) {
                ((Array)value).add(update.getValue());
            } else if (value instanceof WeightedSet) {
                ((WeightedSet)value).put(update.getValue(), ((AddValueUpdate)update).getWeight());
            }
            return value;
        } else if (update instanceof ArithmeticValueUpdate) {
            if (((ArithmeticValueUpdate)update).getOperator() == ArithmeticValueUpdate.Operator.DIV &&
                ((ArithmeticValueUpdate)update).getOperand().doubleValue() == 0) {
                throw new IllegalArgumentException("Division by zero");
            }
            value.assign(update.getValue());
            return value;
        } else if (update instanceof RemoveValueUpdate) {
            if (value instanceof Array) {
                ((Array)value).add(update.getValue());
            } else if (value instanceof WeightedSet) {
                ((WeightedSet)value).put(update.getValue(), 1);
            }
            return value;
        } else if (update instanceof MapValueUpdate) {
            if (value instanceof Array) {
                var nestedUpdate = ((MapValueUpdate)update).getUpdate();
                if (nestedUpdate instanceof AssignValueUpdate) {
                    // Can't assign an array's value type directly to the array, so we have to add it as a
                    // singular element to the partial document.
                    ((Array)value).add(nestedUpdate.getValue());
                    return value;
                } else {
                    return applyUpdate(nestedUpdate, value);
                }
            } else if (value instanceof MapFieldValue) {
                throw new UnsupportedOperationException("Can not map into a " + value.getClass().getName());
            } else if (value instanceof StructuredFieldValue) {
                Field field = ((StructuredFieldValue)value).getField(String.valueOf(update.getValue()));
                if (field == null) {
                    throw new IllegalArgumentException("Field '" + update.getValue() + "' not found");
                }
                ((StructuredFieldValue)value).setFieldValue(field, applyUpdate(((MapValueUpdate)update).getUpdate(), field.getDataType().createFieldValue()
                ));
                return value;
            } else if (value instanceof WeightedSet) {
                FieldValue weight = applyUpdate(((MapValueUpdate)update).getUpdate(), new IntegerFieldValue());
                if (!(weight instanceof IntegerFieldValue)) {
                    throw new IllegalArgumentException("Expected integer, got " + weight.getClass().getName());
                }
                ((WeightedSet)value).put(update.getValue(), ((IntegerFieldValue)weight).getInteger());
                return value;
            } else {
                throw new IllegalArgumentException("Expected multi-value data type, got " + value.getDataType().getName());
            }
        } else if (update instanceof TensorModifyUpdate) {
            return value;
        } else if (update instanceof TensorAddUpdate) {
            return value;
        } else if (update instanceof TensorRemoveUpdate) {
            return value;
        }
        throw new UnsupportedOperationException("Value update type " + update.getClass().getName() + " not supported");
    }
Applies the given update to the given (empty) field value.
indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateHelper.java