Skip to content

test: allow external_access_plan run on windows #13531

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

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ datafusion/sqllogictests/test_files/tpch/data/*
# Scratch temp dir for sqllogictests
datafusion/sqllogictest/test_files/scratch*

# temp file for core
datafusion/core/*.parquet

# rat
filtered_rat.txt
rat.txt
78 changes: 42 additions & 36 deletions datafusion/core/tests/parquet/external_access_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ use datafusion_physical_plan::ExecutionPlan;
use parquet::arrow::arrow_reader::{RowSelection, RowSelector};
use parquet::arrow::ArrowWriter;
use parquet::file::properties::WriterProperties;
use std::sync::{Arc, OnceLock};
use std::path::Path;
use std::sync::Arc;
use tempfile::NamedTempFile;

#[tokio::test]
Expand Down Expand Up @@ -314,12 +315,19 @@ impl TestFull {

let TestData {
_temp_file: _,
schema,
file_name,
file_size,
ref schema,
ref file_name,
ref file_size,
} = get_test_data();

let mut partitioned_file = PartitionedFile::new(file_name, *file_size);
let new_file_name = if cfg!(target_os = "windows") {
// Windows path separator is different from Unix
file_name.replace("\\", "/")
} else {
file_name.clone()
};

let mut partitioned_file = PartitionedFile::new(new_file_name, *file_size);

// add the access plan, if any, as an extension
if let Some(access_plan) = access_plan {
Expand Down Expand Up @@ -355,6 +363,8 @@ impl TestFull {
pretty_format_batches(&results).unwrap()
);

std::fs::remove_file(file_name).unwrap();

Ok(MetricsFinder::find_metrics(plan.as_ref()).unwrap())
}
}
Expand All @@ -369,45 +379,41 @@ struct TestData {
file_size: u64,
}

static TEST_DATA: OnceLock<TestData> = OnceLock::new();

/// Return a parquet file with 2 row groups each with 5 rows
fn get_test_data() -> &'static TestData {
TEST_DATA.get_or_init(|| {
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason to use the TEST_DATA thing was to avoid creating the same file over and over again.

Do we need to remove TEST_DATA?

It seems like the core difference is the use of tempfile_in rather than the change from static

Copy link
Contributor

Choose a reason for hiding this comment

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

If we aren't going to use TEST_DATA anymore perhaps we can remove it (rather than name it starting with _ to avoid a compiler error) 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason to use the TEST_DATA thing was to avoid creating the same file over and over again.

Do we need to remove TEST_DATA?

It seems like the core difference is the use of tempfile_in rather than the change from static

There is no chance for delete TEST_DATA. Because there is no main test function to lead minor test cases.

Copy link
Contributor Author

@zhuliquan zhuliquan Nov 25, 2024

Choose a reason for hiding this comment

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

If we aren't going to use TEST_DATA anymore perhaps we can remove it (rather than name it starting with _ to avoid a compiler error) 🤔

@alamb Yeah, I share same point with you, I remove it now.

let scenario = Scenario::UTF8;
let row_per_group = 5;
fn get_test_data() -> TestData {
let scenario = Scenario::UTF8;
let row_per_group = 5;

let mut temp_file = tempfile::Builder::new()
.prefix("user_access_plan")
.suffix(".parquet")
.tempfile()
.expect("tempfile creation");
let mut temp_file = tempfile::Builder::new()
.prefix("user_access_plan")
.suffix(".parquet")
.tempfile_in(Path::new(""))
.expect("tempfile creation");

let props = WriterProperties::builder()
.set_max_row_group_size(row_per_group)
.build();
let props = WriterProperties::builder()
.set_max_row_group_size(row_per_group)
.build();

let batches = create_data_batch(scenario);
let schema = batches[0].schema();
let batches = create_data_batch(scenario);
let schema = batches[0].schema();

let mut writer =
ArrowWriter::try_new(&mut temp_file, schema.clone(), Some(props)).unwrap();
let mut writer =
ArrowWriter::try_new(&mut temp_file, schema.clone(), Some(props)).unwrap();

for batch in batches {
writer.write(&batch).expect("writing batch");
}
writer.close().unwrap();
for batch in batches {
writer.write(&batch).expect("writing batch");
}
writer.close().unwrap();

let file_name = temp_file.path().to_string_lossy().to_string();
let file_size = temp_file.path().metadata().unwrap().len();
let file_name = temp_file.path().to_string_lossy().to_string();
let file_size = temp_file.path().metadata().unwrap().len();

TestData {
_temp_file: temp_file,
schema,
file_name,
file_size,
}
})
TestData {
_temp_file: temp_file,
schema,
file_name,
file_size,
}
}

/// Return the total value of the specified metric name
Expand Down
2 changes: 0 additions & 2 deletions datafusion/core/tests/parquet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ use std::sync::Arc;
use tempfile::NamedTempFile;

mod custom_reader;
// Don't run on windows as tempfiles don't seem to work the same
#[cfg(not(target_os = "windows"))]
mod external_access_plan;
mod file_statistics;
#[cfg(not(target_family = "windows"))]
Expand Down