Skip to content

Commit

Permalink
Sort file names in a directory apache#2730 (apache#2735)
Browse files Browse the repository at this point in the history
* Update local.rs

* Update local.rs

* Update local.rs

Added a test case for sorting directories.
  • Loading branch information
yourenawo authored and waynexia committed Jun 20, 2022
1 parent e53f6c5 commit 28352fd
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions datafusion/data-access/src/object_store/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ async fn list_all(prefix: String) -> Result<FileMetaStream> {
files.push(get_meta(child_path.to_owned(), metadata))
}
}
files.sort_by(|a, b| a.path().cmp(b.path()));
Ok(files)
}

Expand Down Expand Up @@ -317,4 +318,51 @@ mod tests {

Ok(())
}
#[tokio::test]
async fn test_list_all_sort_by_filename() -> Result<()> {
// tmp/file_23590.parquet
// tmp/file_13690.parquet
// tmp/file_12590.parquet
// tmp/file_03590.parquet
let tmp = tempdir()?;
let a_path = tmp.path().join("file_23590.parquet");
let b_path = tmp.path().join("file_13690.parquet");
let c_path = tmp.path().join("file_12590.parquet");
let d_path = tmp.path().join("file_03590.parquet");
File::create(&a_path)?;
File::create(&b_path)?;
File::create(&c_path)?;
File::create(&d_path)?;

let mut files = list_all(tmp.path().to_str().unwrap().to_string()).await?;
let mut list_files_name = Vec::new();
while let Some(file) = files.next().await {
let file = file?;
list_files_name.push(file.path().to_owned());
}
let sort_files_name = [
tmp.path()
.join("file_03590.parquet")
.to_str()
.unwrap()
.to_string(),
tmp.path()
.join("file_12590.parquet")
.to_str()
.unwrap()
.to_string(),
tmp.path()
.join("file_13690.parquet")
.to_str()
.unwrap()
.to_string(),
tmp.path()
.join("file_23590.parquet")
.to_str()
.unwrap()
.to_string(),
];
assert_eq!(list_files_name, sort_files_name);
Ok(())
}
}

0 comments on commit 28352fd

Please sign in to comment.