Skip to content

Commit e4f74d8

Browse files
authored
chore: Use tempfile to replace hand-written utils functions (#8147)
# Which issue does this PR close? - Closes #8143 # Rationale for this change Code Cleanup # What changes are included in this PR? Use tempfile to replace hand-written utils functions # Are these changes tested? tested in CI. # Are there any user-facing changes? No Signed-off-by: Xuanwo <[email protected]>
1 parent 48b723f commit e4f74d8

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

arrow-avro/src/writer/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ mod tests {
195195
use crate::test_util::arrow_test_data;
196196
use arrow_array::{ArrayRef, BinaryArray, Int32Array, RecordBatch, StringArray};
197197
use arrow_schema::{DataType, Field, Schema};
198-
use std::fs::{remove_file, File};
198+
use std::fs::File;
199199
use std::io::BufReader;
200200
use std::sync::Arc;
201+
use tempfile::NamedTempFile;
201202

202203
fn make_schema() -> Schema {
203204
Schema::new(vec![
@@ -220,16 +221,6 @@ mod tests {
220221
haystack.windows(needle.len()).any(|w| w == needle)
221222
}
222223

223-
fn unique_temp_path(prefix: &str) -> std::path::PathBuf {
224-
let mut p = std::env::temp_dir();
225-
let nanos = std::time::SystemTime::now()
226-
.duration_since(std::time::UNIX_EPOCH)
227-
.unwrap()
228-
.as_nanos();
229-
p.push(format!("{}_{}_{}.avro", prefix, std::process::id(), nanos));
230-
p
231-
}
232-
233224
#[test]
234225
fn test_ocf_writer_generates_header_and_sync() -> Result<(), ArrowError> {
235226
let batch = make_batch();
@@ -315,7 +306,8 @@ mod tests {
315306
let input_batches = reader.collect::<Result<Vec<_>, _>>()?;
316307
let original =
317308
arrow::compute::concat_batches(&schema, &input_batches).expect("concat input");
318-
let out_path = unique_temp_path("arrow_avro_roundtrip");
309+
let tmp = NamedTempFile::new().expect("create temp file");
310+
let out_path = tmp.into_temp_path();
319311
let out_file = File::create(&out_path).expect("create temp avro");
320312
let mut writer = AvroWriter::new(out_file, original.schema().as_ref().clone())?;
321313
if rel.contains(".snappy.") {
@@ -343,7 +335,6 @@ mod tests {
343335
"Round-trip batch mismatch for file: {}",
344336
rel
345337
);
346-
let _ = remove_file(&out_path);
347338
}
348339
Ok(())
349340
}

0 commit comments

Comments
 (0)