Skip to content

Apache DataFusion SQL Query Engine

fix: Windows paths crashing core tests (#17231)

Nuno Faria541fdfbc0d88
diff --git a/datafusion/common/src/test_util.rs b/datafusion/common/src/test_util.rs
index 199807ac1c..2bd702f06a 100644
--- a/datafusion/common/src/test_util.rs
+++ b/datafusion/common/src/test_util.rs
@@ -255,7 +255,14 @@ pub fn arrow_test_data() -> String {
#[cfg(feature = "parquet")]
pub fn parquet_test_data() -> String {
match get_data_dir("PARQUET_TEST_DATA", "../../parquet-testing/data") {
- Ok(pb) => pb.display().to_string(),
+ Ok(pb) => {
+ let mut path = pb.display().to_string();
+ if cfg!(target_os = "windows") {
+ // Replace backslashes (Windows paths; avoids some test issues).
+ path = path.replace("\\", "/");
+ }
+ path
+ }
Err(err) => panic!("failed to get parquet data dir: {err}"),
}
}
diff --git a/datafusion/core/tests/parquet/encryption.rs b/datafusion/core/tests/parquet/encryption.rs
index a71a4f1ea2..c32310752c 100644
--- a/datafusion/core/tests/parquet/encryption.rs
+++ b/datafusion/core/tests/parquet/encryption.rs
@@ -284,7 +284,17 @@ fn verify_file_encrypted(
options
.options
.insert("test_key".to_string(), "test value".to_string());
- let object_path = object_store::path::Path::from(file_path.to_str().unwrap());
+
+ let file_path_str = if cfg!(target_os = "windows") {
+ // Windows backslashes are eventually converted to slashes when writing the Parquet files,
+ // through `ListingTableUrl::parse`, making `encryption_factory.encryption_keys` store them
+ // it that format. So we also replace backslashes here to ensure they match.
+ file_path.to_str().unwrap().replace("\\", "/")
+ } else {
+ file_path.to_str().unwrap().to_owned()
+ };
+
+ let object_path = object_store::path::Path::from(file_path_str);
let decryption_properties = encryption_factory
.get_file_decryption_properties(&options, &object_path)?
.unwrap();
diff --git a/datafusion/core/tests/tracing/mod.rs b/datafusion/core/tests/tracing/mod.rs
index df8a28c021..0b66a49eea 100644
--- a/datafusion/core/tests/tracing/mod.rs
+++ b/datafusion/core/tests/tracing/mod.rs
@@ -76,7 +76,13 @@ async fn run_query() {
let ctx = SessionContext::new();
// Get the test data directory
- let test_data = parquet_test_data();
+ let test_data = if cfg!(target_os = "windows") {
+ // Prefix Windows paths with "/", since they start with <Drive>:/ but the URI should be
+ // test:///C:/... (https://datatracker.ietf.org/doc/html/rfc8089#appendix-E.2)
+ format!("/{}", parquet_test_data())
+ } else {
+ parquet_test_data()
+ };
// Define a Parquet file format with pruning enabled
let file_format = ParquetFormat::default().with_enable_pruning(true);