-
Notifications
You must be signed in to change notification settings - Fork 838
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
Add tests for bad parquet files #6262
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule parquet-testing
updated
7 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Tests that reading invalid parquet files returns an error | ||
|
||
use arrow::util::test_util::parquet_test_data; | ||
use parquet::arrow::arrow_reader::ArrowReaderBuilder; | ||
use parquet::errors::ParquetError; | ||
use std::collections::HashSet; | ||
use std::path::PathBuf; | ||
|
||
static KNOWN_FILES: &[&str] = &[ | ||
"PARQUET-1481.parquet", | ||
"ARROW-GH-41317.parquet", | ||
"ARROW-GH-41321.parquet", | ||
"ARROW-RS-GH-6229-DICTHEADER.parquet", | ||
"ARROW-RS-GH-6229-LEVELS.parquet", | ||
"README.md", | ||
]; | ||
|
||
/// Returns the path to 'parquet-testing/bad_data' | ||
fn bad_data_dir() -> PathBuf { | ||
// points to parquet-testing/data | ||
let parquet_testing_data = parquet_test_data(); | ||
PathBuf::from(parquet_testing_data) | ||
.parent() | ||
.expect("was in parquet-testing/data") | ||
.join("bad_data") | ||
} | ||
|
||
#[test] | ||
// Ensure that if we add a new test the files are added to the tests. | ||
fn test_invalid_files() { | ||
let known_files: HashSet<_> = KNOWN_FILES.iter().cloned().collect(); | ||
let mut seen_files = HashSet::new(); | ||
|
||
let files = std::fs::read_dir(bad_data_dir()).unwrap(); | ||
|
||
for file in files { | ||
let file_name = file | ||
.unwrap() | ||
.path() | ||
.file_name() | ||
.unwrap() | ||
.to_str() | ||
.unwrap() | ||
.to_string(); | ||
|
||
// If you see this error, please add a test for the new file following the model below | ||
assert!( | ||
known_files.contains(file_name.as_str()), | ||
"Found new file in bad_data, please add test: {file_name}" | ||
); | ||
seen_files.insert(file_name); | ||
} | ||
for expected_file in known_files { | ||
assert!( | ||
seen_files.contains(expected_file), | ||
"Expected file not found in bad_data directory: {expected_file}" | ||
); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_parquet_1481() { | ||
let err = read_file("PARQUET-1481.parquet").unwrap_err(); | ||
assert_eq!( | ||
err.to_string(), | ||
"Parquet error: unexpected parquet type: -7" | ||
); | ||
} | ||
|
||
#[test] | ||
#[should_panic(expected = "assertion failed: self.current_value.is_some()")] | ||
fn test_arrow_gh_41321() { | ||
let err = read_file("ARROW-GH-41321.parquet").unwrap_err(); | ||
assert_eq!(err.to_string(), "TBD (currently panics)"); | ||
} | ||
|
||
#[test] | ||
fn test_arrow_gh_41317() { | ||
let err = read_file("ARROW-GH-41317.parquet").unwrap_err(); | ||
assert_eq!( | ||
err.to_string(), | ||
"External: Parquet argument error: External: bad data" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_arrow_rs_gh_6229_dict_header() { | ||
let err = read_file("ARROW-RS-GH-6229-DICTHEADER.parquet").unwrap_err(); | ||
assert_eq!( | ||
err.to_string(), | ||
"External: Parquet argument error: EOF: eof decoding byte array" | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_arrow_rs_gh_6229_dict_levels() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prior to #6232 this test generated an infinite loop |
||
let err = read_file("ARROW-RS-GH-6229-LEVELS.parquet").unwrap_err(); | ||
assert_eq!( | ||
err.to_string(), | ||
"External: Parquet argument error: Parquet error: Insufficient repetition levels read from column" | ||
); | ||
} | ||
|
||
/// Reads the file and tries to return the total row count | ||
/// Returns an error if the file is invalid | ||
fn read_file(name: &str) -> Result<usize, ParquetError> { | ||
let path = bad_data_dir().join(name); | ||
println!("Reading file: {:?}", path); | ||
|
||
let file = std::fs::File::open(&path).unwrap(); | ||
let reader = ArrowReaderBuilder::try_new(file)?.build()?; | ||
|
||
let mut num_rows = 0; | ||
for batch in reader { | ||
let batch = batch?; | ||
num_rows += batch.num_rows(); | ||
} | ||
Ok(num_rows) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha!