Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/io/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def delete(self, location: str | InputFile | OutputFile) -> None:

uri = urlparse(str_location)
fs = self._get_fs_from_uri(uri, str_location)
fs.rm(str_location)
fs.rm_file(str_location)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the glob expansion, but not ?/#. s3fs split_path does keypart.partition("?versionId=") regardless of version_aware, so rm_file("s3://b/data.parquet?versionId=1") still deletes data.parquet. gcsfs (when version_aware) treats a numeric # or ?generation= as a generation, and adlfs parses ?versionid=.

Also a small behavior change: rm raised FileNotFoundError for a missing path through expand_path, while rm_file on S3 is a silent delete_object. Probably fine for the callers, but worth noting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept this PR to the glob fix (rm to rm_file plus the local test). The s3fs/gcsfs/adlfs versionId behavior goes with the parse_location discussion, so it is not part of this change.


def _get_fs_from_uri(self, uri: "ParseResult", location: str = "") -> AbstractFileSystem:
"""Get a filesystem from a parsed URI, using hostname for ADLS account resolution."""
Expand Down
12 changes: 12 additions & 0 deletions tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def test_fsspec_local_fs_can_create_path_without_parent_dir(fsspec_fileio: Fsspe
pytest.fail("Failed to write to file without parent directory")


def test_fsspec_delete_does_not_expand_glob(fsspec_fileio: FsspecFileIO) -> None:
"""Test delete removes only the named file when the name contains glob characters"""
with tempfile.TemporaryDirectory() as tmpdirname:
for name in ("data-1.parquet", "data-2.parquet", "data-[12].parquet"):
with open(f"{tmpdirname}/{name}", "wb") as f:
f.write(b"foo")

fsspec_fileio.delete(f"{tmpdirname}/data-[12].parquet")

assert sorted(os.listdir(tmpdirname)) == ["data-1.parquet", "data-2.parquet"]


def test_fsspec_get_fs_instance_per_thread_caching(fsspec_fileio: FsspecFileIO) -> None:
"""Test that filesystem instances are cached per-thread by `FsspecFileIO.get_fs`"""
fs_instances: list[AbstractFileSystem] = []
Expand Down
Loading