viirya commented on PR #2040:
URL: https://github.com/apache/arrow-rs/pull/2040#issuecomment-1184793174
I was looking for how the reader knows how to ignore it. But I didn't find
it. Then I realized that previously the writer wrote the entire buffers. For
the reader, it sets offsets from zero and reads the buffers from incorrect
positions.
So I think it is a bug that sliced record batch cannot be read correctly
after IPC. We can reproduce it:
```rust
fn create_batch() -> RecordBatch {
let schema = Schema::new(vec![
Field::new("a", DataType::Int32, true),
Field::new("b", DataType::Utf8, true),
]);
let a = Int32Array::from(vec![1, 2, 3, 4, 5]);
let b = StringArray::from(vec!["a", "b", "c", "d", "e"]);
RecordBatch::try_new(Arc::new(schema), vec![Arc::new(a), Arc::new(b)])
.unwrap()
}
let big_record_batch = create_batch();
let offset = 2;
let record_batch_slice = big_record_batch.slice(offset, 3);
```
Original record batches:
```
RecordBatch { schema: Schema { fields: [Field { name: "a", data_type: Int32,
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None }, Field {
name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: fal
se, metadata: None }], metadata: {} }, columns: [PrimitiveArray<Int32>
[
1,
2,
3,
4,
5,
], StringArray
[
"a",
"b",
"c",
"d",
"e",
]], row_count: 5 }
RecordBatch { schema: Schema { fields: [Field { name: "a", data_type: Int32,
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None }, Field {
name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: fal
se, metadata: None }], metadata: {} }, columns: [PrimitiveArray<Int32>
[
3,
4,
5,
], StringArray
[
"c",
"d",
"e",
]], row_count: 3 }
```
Record batches after IPC serialization/deserialzation:
```
RecordBatch { schema: Schema { fields: [Field { name: "a", data_type: Int32,
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None }, Field {
name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: fal
se, metadata: None }], metadata: {} }, columns: [PrimitiveArray<Int32>
[
1,
2,
3,
4,
5,
], StringArray
[
"a",
"b",
"c",
"d",
"e",
]], row_count: 5 }
RecordBatch { schema: Schema { fields: [Field { name: "a", data_type: Int32,
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: None }, Field {
name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: fal
se, metadata: None }], metadata: {} }, columns: [PrimitiveArray<Int32>
[
null,
null,
5,
], StringArray
[
"a",
"b",
"c",
]], row_count: 3 }
```
--
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]