IPC reads do not return mutable buffers right now, so
Buffer::mutable_data will return nullptr. You need to use Buffer::Copy

https://github.com/apache/arrow/blob/master/cpp/src/arrow/buffer.h#L251

You could potentially use const_cast to get a mutable pointer to a
buffer returned by IPC reads, which are always immutable buffers — we
could potentially add a flag to IpcReadOptions to permit returning
mutable buffers.

On Fri, Jul 30, 2021 at 12:49 PM Niranda Perera
<niranda.per...@gmail.com> wrote:
>
> Hi Rares,
>
> ArrayData::GetMutableValues would return a nullptr if the requested buffer
> is not available.
> https://github.com/apache/arrow/blob/557a7c63d49aa04508564517c77c71f3657d19ff/cpp/src/arrow/array/data.h#L199
>
> What does nAtts stand for? could it be that it is OOB?
>
> On Fri, Jul 30, 2021 at 12:55 PM 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:
> >
> > std::shared_ptr<arrow::ArrayData> pos_data = batch->column_data(nAtts);
> > auto pos_values = pos_data->GetMutableValues<int64_t>(1);
> > for (auto i = 1; i < pos_data->length; i++)
> > pos_values[i] += pos_values[i - 1];
> >
> > 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();
> >
> > 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?
> >
> > Thanks!
> > Rares
> >
>
>
> --
> Niranda Perera
> https://niranda.dev/
> @n1r44 <https://twitter.com/N1R44>

Reply via email to