vikramsqr opened a new issue #972:
URL: https://github.com/apache/arrow-rs/issues/972


   **Describe the bug**
   Attempting to write/read dictionaries nested in a list to an IPC stream 
results in an error:
   
   **To Reproduce**
   ```
   use std::sync::Arc;
   use arrow::record_batch::RecordBatch;
   use arrow::array::{Array, DictionaryArray, ListBuilder, StringBuilder, 
StringDictionaryBuilder, PrimitiveBuilder};
   use arrow::datatypes::{Field, Int32Type, Schema};
   
   fn send_receive() -> std::result::Result<(), Box<dyn std::error::Error>> {
       let fields_vec = vec!["fields1", "fields2"];
       let fields_list = {
               let mut b = 
ListBuilder::with_capacity(StringDictionaryBuilder::new(PrimitiveBuilder::<Int32Type>::new(2),
 StringBuilder::new(2)), 1);
               for f in &fields_vec {
                   b.values().append(f).unwrap();
                   }
               b.append(true)?;
               b.finish()
           };
       let schema = Arc::new(Schema::new(vec![Field::new("fields", 
fields_list.data_type().clone(), false)]));
       let batch = 
RecordBatch::try_new(schema.clone(),vec![Arc::new(fields_list)])?;
       let buf = Vec::with_capacity(1024 * 32);
       let mut writer = arrow::ipc::writer::StreamWriter::try_new(buf, 
&schema)?;
       writer.write(&batch)?;
       writer.finish()?;    let reader = &writer.into_inner()?[..];
       let mut reader = arrow::ipc::reader::StreamReader::try_new(reader)?;
       while let Some(n) = reader.next() {
           let b = n?;
           println!("Parsed batch: {:?}", b);
       }
       Ok(())
   }
   
   fn main() {
       println!("Sending DictionaryArray in a list");
       match send_receive() {
           Ok(_) => println!("Encoded and decoded successfully"),
           Err(e) => panic!("{:?}", e)
       }
   } 
   ```
   
   **Actual behavior**
   Result in the error:
   ```
   Sending DictionaryArray in a list
   thread 'main' panicked at 'index out of bounds: the len is 1 but the index 
is 1', 
.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-6.2.0/src/ipc/reader.rs:176:31
   stack backtrace:
      0: rust_begin_unwind
      1: core::panicking::panic_fmt
      2: core::panicking::panic_bounds_check
      3: arrow::ipc::reader::create_array
                at 
.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-6.2.0/src/ipc/reader.rs:176:31
      4: arrow::ipc::reader::create_array
                at 
.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-6.2.0/src/ipc/reader.rs:100:26
      5: arrow::ipc::reader::read_record_batch
                at 
.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-6.2.0/src/ipc/reader.rs:432:22
      6: arrow::ipc::reader::StreamReader<R>::maybe_next
                at 
.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-6.2.0/src/ipc/reader.rs:875:17
      7: <arrow::ipc::reader::StreamReader<R> as 
core::iter::traits::iterator::Iterator>::next
                at 
.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-6.2.0/src/ipc/reader.rs:908:9
      8: rust_arrow::send_receive
                at ./src/main.rs:58:25
      9: rust_arrow::main
                at ./src/main.rs:81:11
   ```
   
   **Expected behavior**
   The message is written and read successfully.
   
   **Additional context**
   Using arrow 6.2.0
   Support for dictionaries nested inside Structs and Unions was added in #870 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to