[
https://issues.apache.org/jira/browse/ARROW-7559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17014817#comment-17014817
]
Paddy Horan commented on ARROW-7559:
------------------------------------
Thanks [~jhorstmann].
It took a while to convince myself but I agree with your suggested fix, I
posted a PR [here|https://github.com/apache/arrow/pull/6180] to fix it.
FYI - `ArrayData` is fairly low level, you can use the other builders so you
don't have to manage the offsets, etc. yourself, see the test I added in the PR
(which is basically your exact example above).
> [Rust] Possibly incorrect index check assertion in StringArray and BinaryArray
> ------------------------------------------------------------------------------
>
> Key: ARROW-7559
> URL: https://issues.apache.org/jira/browse/ARROW-7559
> Project: Apache Arrow
> Issue Type: Bug
> Components: Rust
> Affects Versions: 0.16.0
> Reporter: Jörn Horstmann
> Assignee: Paddy Horan
> Priority: Major
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The following code tries to build a list array based on an underlying string
> array and panics on master (commit acfcdee75acb4b1814f2e727c150a7403d618e8f)
> {code:java}
> #[test]
> fn nested_string_array() {
> let strarray = StringArray::from(vec!["foo", "bar", "foobar"]);
> let nestedData =
> ArrayData::builder(DataType::List(Box::new(DataType::Utf8)))
> .len(2)
> .add_buffer(Buffer::from(&[0, 2, 3].to_byte_slice()))
> .add_child_data(ArrayData::builder(DataType::Utf8)
> .len(strarray.len())
> .add_buffer(strarray.value_offsets())
> .add_buffer(strarray.value_data())
> .build())
> .build();
> let nestedArray = ListArray::from(nestedData);
> dbg!(nestedArray);
> }{code}
> My guess is that the index check in StringArray.value is incorrect, instead
> of
> {code:java}
> pub fn value(&self, i: usize) -> &str {
> assert!(
> i + self.offset() < self.data.len(),
> "StringArray out of bounds access"
> );
> {code}
> it should probably compare {{i}} without adding the offset. The same check is
> also done in {{BinaryArray}}. Changing this results in the expected output of
> {code:java}
> [arrow/src/array/array.rs:2460] nestedArray = ListArray
> [
> StringArray
> [
> "foo",
> "bar",
> ],
> StringArray
> [
> "foobar",
> ],
> ]
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)