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

Fix reading nested lists from parquet files #1517

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions parquet/src/arrow/array_reader/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ impl<'a> TypeVisitor<Option<Box<dyn ArrayReader>>, &'a ArrayReaderBuilderContext
)?;

if cur_type.get_basic_info().repetition() == Repetition::REPEATED {
Err(ArrowError(
"Reading repeated field is not supported yet!".to_string(),
))
Err(ArrowError(format!(
"Reading repeated field ({:?}) is not supported yet!",
cur_type.name()
)))
} else {
Ok(Some(reader))
}
Expand Down Expand Up @@ -189,9 +190,10 @@ impl<'a> TypeVisitor<Option<Box<dyn ArrayReader>>, &'a ArrayReaderBuilderContext
if cur_type.get_basic_info().has_repetition()
&& cur_type.get_basic_info().repetition() == Repetition::REPEATED
{
Err(ArrowError(
"Reading repeated field is not supported yet!".to_string(),
))
Err(ArrowError(format!(
"Reading repeated field ({:?}) is not supported yet!",
cur_type.name(),
)))
} else {
Ok(Some(reader))
}
Expand Down Expand Up @@ -698,7 +700,12 @@ impl<'a> ArrayReaderBuilder {
ArrowType::Struct(fields) => {
field = fields.iter().find(|f| f.name() == part)
}
ArrowType::List(list_field) => field = Some(list_field.as_ref()),
ArrowType::List(list_field) => match list_field.data_type() {
ArrowType::Struct(fields) => {
field = fields.iter().find(|f| f.name() == part)
}
_ => field = Some(list_field.as_ref()),
},
Comment on lines +704 to +709
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was tested by using the example in #1515. Not sure if it is easy to add a unit test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we put the example parquet file into parquet-testing too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally we would construct a parquet file with this pattern programmatically (aka write it out in a test and then read it back in).

if that is not possible / feasible, adding an example in parquet-testing would be second best

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Let me try to make one. Thanks.

_ => field = None,
}
} else {
Expand All @@ -710,14 +717,13 @@ impl<'a> ArrayReaderBuilder {
}
}


#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;
use crate::arrow::parquet_to_arrow_schema;
use crate::file::reader::{FileReader, SerializedFileReader};
use crate::util::test_common::get_test_file;
use super::*;
use std::sync::Arc;

#[test]
fn test_create_array_reader() {
Expand All @@ -730,15 +736,15 @@ mod tests {
file_metadata.schema_descr(),
file_metadata.key_value_metadata(),
)
.unwrap();
.unwrap();

let array_reader = build_array_reader(
file_reader.metadata().file_metadata().schema_descr_ptr(),
Arc::new(arrow_schema),
vec![0usize].into_iter(),
Box::new(file_reader),
)
.unwrap();
.unwrap();

// Create arrow types
let arrow_type = ArrowType::Struct(vec![Field::new(
Expand All @@ -749,4 +755,4 @@ mod tests {

assert_eq!(array_reader.get_data_type(), &arrow_type);
}
}
}