You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@arrow.apache.org by Kirill Lykov <ly...@gmail.com> on 2020/08/13 14:54:13 UTC

get element of ListArray as Array

I have a ChunkedArray of type `arrow::list` and I want to take a value
for a particular row in this column and return it as Array.
From example, I see one way of doing it -- get raw pointer using
`values` method and also take `value_offset` to get offset. This way I
will get pointers to the whole range.
If this is the only way, can I somehow create a zero-copy arrow::Array
from this range?

-- 
Best regards,
Kirill Lykov

Re: get element of ListArray as Array

Posted by Sutou Kouhei <ko...@clear-code.com>.
Hi,

The following code will work:


  auto list = std::static_pointer_cast<arrow::ListArray>(data->chunk(0));
  auto currentSeries = list->value_slice(rowIndex);


Thanks,
--
kou

In <CA...@mail.gmail.com>
  "Re: get element of ListArray as Array" on Thu, 13 Aug 2020 18:03:30 +0200,
  Kirill Lykov <ly...@gmail.com> wrote:

> I think I found a way:
> ```
>         // data is arrow:ChunkedArray
>         auto list = std::static_pointer_cast<arrow::ListArray>(data->chunk(0));
>         auto values = list->values();
>         auto startOffset = list->value_offset(rowIndex);
>         auto length = list->value_offset(idx + 1) - startOffset;
>         auto currentSerie = values->Slice(startOffset, length);
> ```
> 
> On Thu, Aug 13, 2020 at 4:54 PM Kirill Lykov <ly...@gmail.com> wrote:
>>
>> I have a ChunkedArray of type `arrow::list` and I want to take a value
>> for a particular row in this column and return it as Array.
>> From example, I see one way of doing it -- get raw pointer using
>> `values` method and also take `value_offset` to get offset. This way I
>> will get pointers to the whole range.
>> If this is the only way, can I somehow create a zero-copy arrow::Array
>> from this range?
>>
>> --
>> Best regards,
>> Kirill Lykov
> 
> 
> 
> -- 
> Best regards,
> Kirill Lykov

Re: get element of ListArray as Array

Posted by Kirill Lykov <ly...@gmail.com>.
I think I found a way:
```
        // data is arrow:ChunkedArray
        auto list = std::static_pointer_cast<arrow::ListArray>(data->chunk(0));
        auto values = list->values();
        auto startOffset = list->value_offset(rowIndex);
        auto length = list->value_offset(idx + 1) - startOffset;
        auto currentSerie = values->Slice(startOffset, length);
```

On Thu, Aug 13, 2020 at 4:54 PM Kirill Lykov <ly...@gmail.com> wrote:
>
> I have a ChunkedArray of type `arrow::list` and I want to take a value
> for a particular row in this column and return it as Array.
> From example, I see one way of doing it -- get raw pointer using
> `values` method and also take `value_offset` to get offset. This way I
> will get pointers to the whole range.
> If this is the only way, can I somehow create a zero-copy arrow::Array
> from this range?
>
> --
> Best regards,
> Kirill Lykov



-- 
Best regards,
Kirill Lykov