Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC reader may break on projection #1735

Closed
iyupeng opened this issue May 24, 2022 · 0 comments · Fixed by #1736
Closed

IPC reader may break on projection #1735

iyupeng opened this issue May 24, 2022 · 0 comments · Fixed by #1736
Labels
arrow Changes to the arrow crate bug

Comments

@iyupeng
Copy link
Contributor

iyupeng commented May 24, 2022

Describe the bug
A clear and concise description of what the bug is.

Function read_record_batch deals with projection in arrow/src/ipc/reader.rs.

Current logic may not advance the node_index and buffer_index correctly because it does not call create_array for skipped nodes.

To Reproduce
Steps to reproduce the behavior:

[dependencies]
arrow = "14.0.0"
use std::fs::File;
use std::sync::Arc;

use arrow::array::*;
use arrow::datatypes::*;
use arrow::ipc::reader::*;
use arrow::ipc::writer::*;
use arrow::record_batch::RecordBatch;

fn main() {
    let schema = Schema::new(vec![
        Field::new("f0", DataType::UInt32, false),
        Field::new("f1", DataType::Utf8, false),
        Field::new("f2", DataType::Boolean, false),
    ]);
    
    let array0 = UInt32Array::from(vec![1, 2, 3]);
    let array1 = StringArray::from(vec!["foo", "bar", "baz"]);
    let array2 = BooleanArray::from(vec![true, false, true]);

    let record_batch = RecordBatch::try_new(
        Arc::new(schema.clone()),
        vec![Arc::new(array0), Arc::new(array1), Arc::new(array2)]
    ).unwrap();

    {
        let file = File::create("./test.arrow_file").unwrap();
        let mut writer = FileWriter::try_new(file, &schema).unwrap();

        writer.write(&record_batch).unwrap();
        writer.finish().unwrap();
    }

    let projection = vec![1];
    let file = File::open("./test.arrow_file").unwrap();
    let arrow_reader = FileReader::try_new(file, Some(projection.clone()));
    let batch = arrow_reader.unwrap().next();
    println!("{:?}", batch);
}

Above code will produce:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidArgumentError("First offset 1 in Utf8 is smaller than last offset 0")', /home/yupeng/.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-14.0.0/src/ipc/reader.rs:287:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior
Output:

Some(Ok(RecordBatch { schema: Schema { fields: [Field { name: "f1", data_type: Utf8, nullable: false, dict_id: 0, dict_is_ordered: false, metadata: None }], metadata: {} }, columns: [StringArray
[
  "foo",
  "bar",
  "baz",
]], row_count: 3 }))

Additional context
Add any other context about the problem here.

@iyupeng iyupeng added the bug label May 24, 2022
@alamb alamb added the arrow Changes to the arrow crate label May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants