czqqqaq opened a new issue, #5242:
URL: https://github.com/apache/arrow-rs/issues/5242
**Describe the bug**
<!--
A clear and concise description of what the bug is.
-->
Can't read file with two DictionaryAraay in one batch
**To Reproduce**
<!--
Steps to reproduce the behavior:
-->
```
use arrow::array::{DictionaryArray, Int32Array, StringArray};
use arrow::datatypes::{DataType, Field, Int32Type, Schema};
use arrow::ipc::reader::StreamReader;
use arrow::ipc::writer::StreamWriter;
use arrow::record_batch::RecordBatch;
use std::fs::File;
use std::sync::Arc;
fn main() {
let schema = Arc::new(Schema::new(vec![
Field::new(
"dict1",
DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Utf8)),
false,
),
Field::new("int", DataType::Int32, false),
Field::new(
"dict2",
DataType::Dictionary(Box::new(DataType::Int32),
Box::new(DataType::Utf8)),
false,
),
]));
let keys = Int32Array::from_iter_values(vec![0, 1, 0, 3]);
let values = Arc::new(StringArray::from_iter_values(vec!["a", "b", "c",
"d"]));
let dict1 = DictionaryArray::<Int32Type>::try_new(keys, values).unwrap();
let keys = Int32Array::from_iter_values(vec![0, 0, 1, 0]);
let values = Arc::new(StringArray::from_iter_values(vec!["A", "B"]));
let dict2 = DictionaryArray::<Int32Type>::try_new(keys, values).unwrap();
let keys = Int32Array::from_iter_values(vec![100, 1000, 10000, 100000]);
let batch = RecordBatch::try_new(
schema,
vec![Arc::new(dict1), Arc::new(keys), Arc::new(dict2)],
)
.unwrap();
// eprintln!("{:?}", batch);
let file = File::create("test_dict.arrow").unwrap();
let mut writer = StreamWriter::try_new(file, &batch.schema()).unwrap();
writer.write(&batch).unwrap();
eprintln!("{:?}",batch);
let mut reader =
StreamReader::try_new(File::open("test_dict.arrow").unwrap(), None).unwrap();
let batch = reader.next().unwrap().unwrap();
eprintln!("{:?}", batch);
}
```
**Expected behavior**
<!--
A clear and concise description of what you expected to happen.
-->
the code can write batch to file successfully, but can't read batch from the
file.
the error content is :
```
called `Result::unwrap()` on an `Err` value: InvalidArgumentError("Value at
position 3 out of bounds: 3 (should be in [0, 1])")
```
**Additional context**
<!--
Add any other context about the problem here.
-->
my leader told me seem like the writer goes wrong :(,still debuging
--
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]