Thanks all! I ended up with this and it worked fine:

        std::shared_ptr<arrow::ArrayData> delta_data =
_arrowBatch->column_data(nAtts);

        // COPY delta to pos
        std::vector<std::shared_ptr<arrow::Buffer>> pos_buffers(2);
        pos_buffers[0] = NULL; // No nulls in the array
        ASSIGN_OR_THROW(pos_buffers[1],
                        arrow::Buffer::Copy(delta_data->buffers[1],

arrow::default_cpu_memory_manager()),
                        "Copy delta column");
        std::shared_ptr<arrow::ArrayData> pos_data = arrow::ArrayData::Make(
            arrow::int64(),
            delta_data->length,
            pos_buffers,
            delta_data->null_count);

On Mon, Aug 2, 2021 at 5:45 PM Antoine Pitrou <anto...@python.org> wrote:

> 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