jk-shah opened a new issue, #41375:
URL: https://github.com/apache/beam/issues/41375

   ### What happened?
   
   Calling `FileSystems.match(['users.json*'])` (or 
`FileSystems.delete(['users.json*'])` / `fileio.MatchFiles('users.json*')`) 
with a bare relative glob pattern in the current working directory (no 
directory separator) returns `0` matches even when matching files exist in 
`os.getcwd()`, whereas `FileSystems.match(['./users.json*'])` succeeds:
   
   ```python
   import os
   import tempfile
   from apache_beam.io.filesystems import FileSystems
   
   with tempfile.TemporaryDirectory() as d:
     old_cwd = os.getcwd()
     os.chdir(d)
     try:
       with open('users.json-00000-of-00001', 'w') as f:
         f.write('{}\n')
       print(FileSystems.match(['users.json*'])[0].metadata_list)    # [] 
(expected 1 match)
       print(FileSystems.match(['./users.json*'])[0].metadata_list)  # 
[FileMetadata(./users.json-00000-of-00001, ...)]
     finally:
       os.chdir(old_cwd)
   ```
   
   ### Cause
   
   In `FileSystem.match` (`sdks/python/apache_beam/io/filesystem.py`, lines 
`742-759`) and `LocalFileSystem` 
(`sdks/python/apache_beam/io/localfilesystem.py`, lines `87-125`):
   1. For `pattern = 'users.json*'`, `prefix_or_dir` is `'users.json'`.
   2. `self._url_dirname('users.json')` calls `os.path.dirname('users.json')` 
(`localfilesystem.py:96`), returning `''`.
   3. `LocalFileSystem._list('')` checks `if not self.exists(dir_or_prefix): 
return` (`localfilesystem.py:113-114`). Because `os.path.exists('')` is 
`False`, `_list('')` yields nothing.
   4. Note that if `_list` walks `'.'` when `dir_or_prefix == ''`, the leading 
`'./'` (or `'.\'` on Windows) prefix on yielded paths also needs to be stripped 
so `self.match_files(file_metadatas, 'users.json*')` matches the caller's 
relative pattern cleanly.
   
   ### Issue Priority
   
   Priority: 2 (default / most bugs should be filed as P2)
   
   ### Issue Components
   
   - [x] Component: Python SDK
   - [ ] Component: Java SDK
   - [ ] Component: Go SDK
   - [ ] Component: Typescript SDK
   - [x] Component: IO connector
   - [ ] Component: Beam YAML
   - [ ] Component: Beam ML
   - [ ] Component: Beam examples
   - [ ] Component: Beam playground
   - [ ] Component: Beam katas
   - [ ] Component: Website
   - [ ] Component: Infrastructure
   - [ ] Component: Spark Runner
   - [ ] Component: Flink Runner
   - [ ] Component: Prism Runner
   - [ ] Component: Hazelcast Jet Runner
   - [ ] Component: Google Cloud Dataflow Runner
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to