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

Inconsistent Arrow Schema When Projecting Nested Parquet File #1652

Closed
tustvold opened this issue May 5, 2022 · 0 comments · Fixed by #1682
Closed

Inconsistent Arrow Schema When Projecting Nested Parquet File #1652

tustvold opened this issue May 5, 2022 · 0 comments · Fixed by #1682
Assignees
Labels
bug parquet Changes to the parquet crate

Comments

@tustvold
Copy link
Contributor

tustvold commented May 5, 2022

Describe the bug

#[test]
  fn test_read_structs() {
      let testdata = arrow::util::test_util::parquet_test_data();
      let path = format!("{}/nested_structs.rust.parquet", testdata);
      let parquet_file_reader =
          SerializedFileReader::try_from(File::open(&path).unwrap()).unwrap();
      let mut arrow_reader = ParquetFileArrowReader::new(Arc::new(parquet_file_reader));
     
      let mut projected = arrow_reader.get_record_reader_by_columns(vec![0], 60).unwrap();

      let batch = projected.next().unwrap().unwrap();
      assert_eq!(projected.schema, batch.schema());

      let schema = batch.schema();
      assert_eq!(batch.column(0).data_type(), schema.field(0).data_type());
  }

This test fails because the schema is computed based on filtering the root nodes.

i.e. It think this is the projected schema

required group field_id=-1 schema {
  required group field_id=-1 roll_num {
    required int64 field_id=-1 min (Int(bitWidth=64, isSigned=true));
    required int64 field_id=-1 max (Int(bitWidth=64, isSigned=true));
    required int64 field_id=-1 mean (Int(bitWidth=64, isSigned=true));
    required int64 field_id=-1 count (Int(bitWidth=64, isSigned=false));
    required int64 field_id=-1 sum (Int(bitWidth=64, isSigned=true));
    required int64 field_id=-1 variance (Int(bitWidth=64, isSigned=true));
  }
}

When it is actually

required group field_id=-1 schema {
  required group field_id=-1 roll_num {
    required int64 field_id=-1 min (Int(bitWidth=64, isSigned=true))
  }
}

This is because the column indices provided to get_record_reader_by_columns is the parquet column indices, not the arrow field index.

To Reproduce

Run test, it fails

Expected behavior

The computed schema should be correct

Additional context

Related to apache/datafusion#2439 and #1651

@tustvold tustvold added the bug label May 5, 2022
@tustvold tustvold self-assigned this May 5, 2022
tustvold added a commit to tustvold/arrow-rs that referenced this issue May 9, 2022
Don't treat embedded arrow schema as authoritative (apache#1663)

Fix projection of nested parquet files (apache#1652) (apache#1654)
tustvold added a commit to tustvold/arrow-rs that referenced this issue May 9, 2022
Don't treat embedded arrow schema as authoritative (apache#1663)

Fix projection of nested parquet files (apache#1652) (apache#1654)

Fix schema inference for repeated fields (apache#1681)

Support reading alternative list representations from parquet (apache#1680)
tustvold added a commit to tustvold/arrow-rs that referenced this issue May 9, 2022
Don't treat embedded arrow schema as authoritative (apache#1663)

Fix projection of nested parquet files (apache#1652) (apache#1654)

Fix schema inference for repeated fields (apache#1681)

Support reading alternative list representations from parquet (apache#1680)

Consistent handling of unsupported arrow types in parquet (apache#1666)
tustvold added a commit to tustvold/arrow-rs that referenced this issue May 11, 2022
Don't treat embedded arrow schema as authoritative (apache#1663)

Fix projection of nested parquet files (apache#1652) (apache#1654)

Fix schema inference for repeated fields (apache#1681)

Support reading alternative list representations from parquet (apache#1680)
alamb pushed a commit that referenced this issue May 13, 2022
* Separate parquet -> arrow conversion logic (#1655)

Don't treat embedded arrow schema as authoritative (#1663)

Fix projection of nested parquet files (#1652) (#1654)

Fix schema inference for repeated fields (#1681)

Support reading alternative list representations from parquet (#1680)

* Add more tests

* Pass pointers by reference

* More docs

* Fix lint

* Review feedback

* Review feedback

* Fix test failures related to #1697
@alamb alamb added the parquet Changes to the parquet crate label May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants