This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e416f0e3 Sort file names in a directory #2730 (#2735)
0e416f0e3 is described below

commit 0e416f0e39d8a76ea13aab9b8f306b64d1133857
Author: yourenawo <[email protected]>
AuthorDate: Thu Jun 16 19:19:28 2022 +0800

    Sort file names in a directory #2730 (#2735)
    
    * Update local.rs
    
    * Update local.rs
    
    * Update local.rs
    
    Added a test case for sorting directories.
---
 datafusion/data-access/src/object_store/local.rs | 48 ++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/datafusion/data-access/src/object_store/local.rs 
b/datafusion/data-access/src/object_store/local.rs
index 7b0cab7cd..4134aa81f 100644
--- a/datafusion/data-access/src/object_store/local.rs
+++ b/datafusion/data-access/src/object_store/local.rs
@@ -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)
     }
 
@@ -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(())
+    }
 }

Reply via email to