Skip to content

Commit 541fdfb

Browse files
authored
fix: Windows paths crashing core tests (#17231)
* fix: Windows paths crashing core tests * Replace backslashes directly in parquet_test_data, Clarify comments
1 parent 64bc58d commit 541fdfb

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

datafusion/common/src/test_util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,14 @@ pub fn arrow_test_data() -> String {
255255
#[cfg(feature = "parquet")]
256256
pub fn parquet_test_data() -> String {
257257
match get_data_dir("PARQUET_TEST_DATA", "../../parquet-testing/data") {
258-
Ok(pb) => pb.display().to_string(),
258+
Ok(pb) => {
259+
let mut path = pb.display().to_string();
260+
if cfg!(target_os = "windows") {
261+
// Replace backslashes (Windows paths; avoids some test issues).
262+
path = path.replace("\\", "/");
263+
}
264+
path
265+
}
259266
Err(err) => panic!("failed to get parquet data dir: {err}"),
260267
}
261268
}

datafusion/core/tests/parquet/encryption.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,17 @@ fn verify_file_encrypted(
284284
options
285285
.options
286286
.insert("test_key".to_string(), "test value".to_string());
287-
let object_path = object_store::path::Path::from(file_path.to_str().unwrap());
287+
288+
let file_path_str = if cfg!(target_os = "windows") {
289+
// Windows backslashes are eventually converted to slashes when writing the Parquet files,
290+
// through `ListingTableUrl::parse`, making `encryption_factory.encryption_keys` store them
291+
// it that format. So we also replace backslashes here to ensure they match.
292+
file_path.to_str().unwrap().replace("\\", "/")
293+
} else {
294+
file_path.to_str().unwrap().to_owned()
295+
};
296+
297+
let object_path = object_store::path::Path::from(file_path_str);
288298
let decryption_properties = encryption_factory
289299
.get_file_decryption_properties(&options, &object_path)?
290300
.unwrap();

datafusion/core/tests/tracing/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ async fn run_query() {
7676
let ctx = SessionContext::new();
7777

7878
// Get the test data directory
79-
let test_data = parquet_test_data();
79+
let test_data = if cfg!(target_os = "windows") {
80+
// Prefix Windows paths with "/", since they start with <Drive>:/ but the URI should be
81+
// test:///C:/... (https://datatracker.ietf.org/doc/html/rfc8089#appendix-E.2)
82+
format!("/{}", parquet_test_data())
83+
} else {
84+
parquet_test_data()
85+
};
8086

8187
// Define a Parquet file format with pruning enabled
8288
let file_format = ParquetFormat::default().with_enable_pruning(true);

0 commit comments

Comments
 (0)