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

Use tempfile for parquet tests #1165

Merged
merged 3 commits into from
Jan 16, 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
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
19 changes: 10 additions & 9 deletions parquet/src/arrow/arrow_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ mod tests {
use crate::file::reader::{FileReader, SerializedFileReader};
use crate::file::writer::{FileWriter, SerializedFileWriter};
use crate::schema::types::{Type, TypePtr};
use crate::util::test_common::{get_temp_filename, RandGen};
use crate::util::test_common::RandGen;
use arrow::array::*;
use arrow::datatypes::DataType as ArrowDataType;
use arrow::record_batch::RecordBatchReader;
Expand All @@ -260,7 +260,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 @@ -702,8 +703,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 @@ -730,18 +729,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 @@ -801,12 +803,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
Loading