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 Parquet Reader's Arrow Schema Inference #1682

Merged
merged 8 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion parquet/src/arrow/array_reader/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ fn build_primitive_reader(

let physical_type = primitive_type.get_physical_type();

// We don't track the column path in ParquetField as it adds a potential source
// of bugs when the arrow mapping converts more than one level in the parquet
// schema into a single arrow field.
//
// None of the readers actually use this field, but it is required for this type,
// so just stick a placeholder in
let column_desc = Arc::new(ColumnDescriptor::new(
primitive_type,
field.def_level,
Expand Down Expand Up @@ -305,7 +311,6 @@ fn build_primitive_reader(
}
}

/// Constructs struct array reader without considering repetition.
fn build_struct_reader(
field: &ParquetField,
row_groups: &dyn RowGroupCollection,
Expand Down
2 changes: 1 addition & 1 deletion parquet/src/arrow/arrow_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ mod tests {
let stocks_field = Field::new(
"stocks",
DataType::Map(
Box::new(Field::new("entries", entries_struct_type, true)),
Box::new(Field::new("entries", entries_struct_type, false)),
false,
),
true,
Expand Down
18 changes: 18 additions & 0 deletions parquet/src/arrow/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,24 @@ mod tests {
for i in 0..arrow_fields.len() {
assert_eq!(arrow_fields[i], converted_fields[i]);
}

let err =
parquet_to_arrow_schema_by_columns(&parquet_schema, vec![3, 2, 4], None)
.unwrap_err()
.to_string();

assert!(
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

err.contains("out of order projection is not supported"),
"{}",
err
);

let err =
parquet_to_arrow_schema_by_columns(&parquet_schema, vec![3, 3, 4], None)
.unwrap_err()
.to_string();

assert!(err.contains("repeated column projection is not supported, column 3 appeared multiple times"), "{}", err);
}

#[test]
Expand Down
6 changes: 5 additions & 1 deletion parquet/src/arrow/schema/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl Visitor {
let map_field = Field::new(
map_key_value.name(),
DataType::Struct(vec![key_field, value_field]),
nullable,
false, // The inner map field is always non-nullable (#1697)
)
.with_metadata(arrow_map.and_then(|f| f.metadata().cloned()));

Expand Down Expand Up @@ -560,6 +560,10 @@ pub fn convert_schema<T: IntoIterator<Item = usize>>(
if i < last_idx {
return Err(general_err!("out of order projection is not supported"));
}
if leaf_mask[i] {
return Err(general_err!("repeated column projection is not supported, column {} appeared multiple times", i));
}

last_idx = i;
leaf_mask[i] = true;
}
Expand Down