Skip to content

Commit

Permalink
Use tempfile for parquet tests (#1165)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Lamb <[email protected]>
  • Loading branch information
tustvold and alamb authored Jan 16, 2022
1 parent 1626b80 commit e45d118
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 307 deletions.
1 change: 1 addition & 0 deletions parquet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ rand = "0.8"
criterion = "0.3"
rand = "0.8"
snap = "1.0"
tempfile = "3.0"
brotli = "3.3"
flate2 = "1.0"
lz4 = "1.23"
Expand Down
21 changes: 11 additions & 10 deletions parquet/src/arrow/arrow_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ mod tests {
use crate::file::writer::{FileWriter, SerializedFileWriter};
use crate::schema::parser::parse_message_type;
use crate::schema::types::{Type, TypePtr};
use crate::util::test_common::{get_temp_file, get_temp_filename, RandGen};
use crate::util::test_common::RandGen;
use arrow::array::*;
use arrow::datatypes::{DataType as ArrowDataType, Field};
use arrow::record_batch::RecordBatchReader;
Expand All @@ -261,7 +261,8 @@ mod tests {
use std::cmp::min;
use std::convert::TryFrom;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::io::Seek;
use std::path::PathBuf;
use std::sync::Arc;

#[test]
Expand Down Expand Up @@ -703,8 +704,6 @@ mod tests {
})
.collect();

let path = get_temp_filename();

let len = match T::get_physical_type() {
crate::basic::Type::FIXED_LEN_BYTE_ARRAY => rand_max,
crate::basic::Type::INT96 => 12,
Expand All @@ -731,18 +730,21 @@ mod tests {
.clone()
.map(|t| arrow::datatypes::Field::new("leaf", t, false));

let mut file = tempfile::tempfile().unwrap();

generate_single_column_file_with_data::<T>(
&values,
def_levels.as_ref(),
path.as_path(),
file.try_clone().unwrap(), // Cannot use &mut File (#1163)
schema,
arrow_field,
&opts,
)
.unwrap();

let parquet_reader =
SerializedFileReader::try_from(File::open(&path).unwrap()).unwrap();
file.rewind().unwrap();

let parquet_reader = SerializedFileReader::try_from(file).unwrap();
let mut arrow_reader = ParquetFileArrowReader::new(Arc::new(parquet_reader));

let mut record_reader = arrow_reader
Expand Down Expand Up @@ -802,12 +804,11 @@ mod tests {
fn generate_single_column_file_with_data<T: DataType>(
values: &[Vec<T::T>],
def_levels: Option<&Vec<Vec<i16>>>,
path: &Path,
file: File,
schema: TypePtr,
field: Option<arrow::datatypes::Field>,
opts: &TestOptions,
) -> Result<parquet_format::FileMetaData> {
let file = File::create(path)?;
let mut writer_props = opts.writer_props();
if let Some(field) = field {
let arrow_schema = arrow::datatypes::Schema::new(vec![field]);
Expand Down Expand Up @@ -926,7 +927,7 @@ mod tests {
}
}";

let file = get_temp_file("nested_nullability.parquet", &[]);
let file = tempfile::tempfile().unwrap();
let schema = Arc::new(parse_message_type(message_type).unwrap());

{
Expand Down
Loading

0 comments on commit e45d118

Please sign in to comment.