On Fri, 30 Jul 2021 18:55:33 +0200
Rares Vernica <rvern...@gmail.com> wrote:
> Hello,
> 
> I have a RecordBatch that I read from an IPC file. I need to run a
> cumulative sum on one of the int64 arrays in the batch. I tried to do:

The ArrayData contents are semantically immutable.  You may want to grab
mutable pointers to the underlying data, but you're generally on your
own.

> but GetMutableValues returns NULL. If I use GetValue, it works fine, but I
> can't run the cumulative sum on the returned pointer since it is read-only.
> I tried creating a copy of ArryaData like so:
> 
> std::shared_ptr<arrow::ArrayData> pos_data =
> batch->column_data(nAtts)->Copy();

ArrayData::Copy() creates a shallow copy of the ArrayData structure.
We do not include a deep copy facility, because often you only want to
change one of the underlying buffers.

> but it did not help. All this data is in CPU buffers so I'm not sure what
> is the problem. What is the best way to mutate or copy & mutate it?

You should probably recreate a new ArrayData with the desired buffers.
To create a buffer, there are several possibilities: allocate it
directly (using AllocateBuffer, for example), use
TypedBufferBuilder<T>, or a hand-rolled method of your choice.

Regards

Antoine.


Reply via email to