Jörn Horstmann created ARROW-7559:
-------------------------------------

             Summary: 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


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)

Reply via email to