Skip to content

IO: Delete the exact file path instead of expanding globs - #4512

Open
Anurag-S1ngh wants to merge 3 commits into
apache:mainfrom
Anurag-S1ngh:fix/4504-fileio-delete-exact
Open

Anurag-S1ngh wants to merge 3 commits into
apache:mainfrom
Anurag-S1ngh:fix/4504-fileio-delete-exact

Conversation

@Anurag-S1ngh

@Anurag-S1ngh Anurag-S1ngh commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

Part of #4504.

FsspecFileIO.delete used fs.rm, which expands *, ? and [...] as glob patterns. Deleting data-[12].parquet also removed data-1.parquet and data-2.parquet. It now uses fs.rm_file, which deletes the literal path.

The PyArrow query and fragment handling is split out. parse_location strips them on write as well, so changing delete alone would leave the two operations disagreeing.

Are these changes tested?

Yes. Added a test that deleting a local file with a [...] name leaves its sibling files untouched.

tests/io/test_fsspec.py tests/io/test_pyarrow.py -m unit -k delete: 25 passed.

Are there any user-facing changes?

No API changes. Delete now targets exactly the named file.

FsspecFileIO.delete used fs.rm, which expands glob characters in the path. PyArrowFileIO.delete parsed the location as a URL, dropping ?query and #fragment from the object key. Delete the literal file in both backends.

@Fokko Fokko left a comment

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.

Thanks for picking this up! The rm -> rm_file change looks good to me, but I have some concerns about the ?/# handling. Could we split this: land the glob fix with the local test on its own, and take the URI semantics to a separate discussion?

Comment thread pyiceberg/io/pyarrow.py Resolved
Comment thread pyiceberg/io/pyarrow.py Resolved
Comment thread pyiceberg/io/fsspec.py Resolved
Comment thread tests/io/test_fsspec.py Resolved
Comment thread tests/io/test_pyarrow.py Resolved
The query and fragment handling only covered PyArrowFileIO.delete while
parse_location still strips them on write, so a location could be written
and deleted under different keys. Split that out; this change only stops
fsspec from expanding glob characters in the file name.
@Anurag-S1ngh

Copy link
Copy Markdown
Contributor Author

Reduced the PR to the glob fix. FsspecFileIO.delete now uses fs.rm_file, with the local test that a [...] name leaves its siblings untouched. The PyArrow query/fragment change and its two tests are gone.

The ?/# behavior does belong in parse_location, and the double append you described on a local path reproduces. I can file a separate issue covering that and the versionId handling in s3fs, gcsfs and adlfs. Want me to?

@Anurag-S1ngh Anurag-S1ngh changed the title IO: Delete only the exact file path IO: Delete the exact file path instead of expanding globs Nov 30, 2026
@Fokko

Fokko commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix! The integration-test-s3 failure is caused by this change, though the change itself is fine. One test depended on how delete used to work.

test_s3v4_rest_signer_write_read_delete fails here:

>       assert len(request_bodies) == 1
E       assert 0 == 1
tests/io/test_fsspec.py:1201

With s3fs, fs.rm() goes through _bulk_delete, which sends a DeleteObjects POST with an XML body. fs.rm_file() calls delete_object, a plain DELETE with no body. The REST signer only forwards the request body for DeleteObjects (added in #4039). This test checks that by calling fileio.delete() and expecting a forwarded body containing <Key>{filename}</Key>. The delete itself still works: the exists() assertion just before it passes.

Could you update the test so it still covers #4039? For example:

  1. Assert that fileio.delete(location) removes the file and that the signer received a DELETE for that key (signer_body["method"] == "DELETE", with the key in signer_body["uri"]).
  2. Exercise body forwarding through the bulk path directly, e.g. fileio.get_fs("s3").rm([location]), and keep the <Key>…</Key> body assertion there.

delete now signs a plain DELETE instead of a DeleteObjects body. Assert the DELETE goes to the signer and keep the body forwarding check on the bulk path.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants