kdn36 opened a new issue, #4504:
URL: https://github.com/apache/iceberg-python/issues/4504
### Apache Iceberg version
0.12.0 (and main)
### Please describe the bug 🐞
(With AI) This bug was found, reproduced and written up with AI. Human in
the loop.
`FileIO.delete` can delete a different file than the one named.
- `FsspecFileIO.delete` calls `fs.rm(location)`. On S3 (s3fs) `rm` expands
`*`, `?` and `[...]` as a glob, so it deletes every file the name matches as a
pattern. The named file itself stays.
- `PyArrowFileIO.delete` parses the location as a URL, which drops a
`?query` or a `#fragment`. It then deletes the file named by the shortened path.
Iceberg file paths are names, not patterns or URLs with fragments. A path
with these characters can reach `delete` through `purge_table` (for example a
data file registered with `add_files`), or through `_delete_old_metadata` with
`write.metadata.delete-after-commit.enabled`.
Reproduction against any S3-compatible store:
```python
import uuid
from pyiceberg.io.fsspec import FsspecFileIO
from pyiceberg.io.pyarrow import PyArrowFileIO
props = {
"s3.endpoint": "http://localhost:9000",
"s3.access-key-id": "...",
"s3.secret-access-key": "...",
"s3.region": "us-east-1",
}
prefix = f"s3://bucket/repro-{uuid.uuid4().hex[:8]}"
io = FsspecFileIO(props)
fs = io.get_fs("s3")
def write(name):
with io.new_output(f"{prefix}/{name}").create(overwrite=True) as f:
f.write(b"x")
def names():
fs.invalidate_cache()
return sorted(p.rsplit("/", 1)[-1] for p in
fs.ls(prefix.removeprefix("s3://")))
for name in ("data-1.parquet", "data-2.parquet", "data-[12].parquet"):
write(name)
io.delete(f"{prefix}/data-[12].parquet")
print(names()) # ['data-[12].parquet']: data-1 and data-2 were deleted
for name in ("data.parquet", "data.parquet#1"):
write(name)
PyArrowFileIO(props).delete(f"{prefix}/data.parquet#1")
print(names()) # [..., 'data.parquet#1']: data.parquet was deleted
```
A possible fix: delete the exact path through the filesystem, without glob
expansion or URL parsing of the key. For example `fs.delete_file` with the
literal bucket and key for PyArrow. For fsspec, `rm_file` avoids the glob,
though s3fs still reads a literal `?versionId=` out of a key, so a path with
`?` or `#` may need to be refused there.
### Willingness to contribute
- [ ] I can contribute a fix for this bug independently
- [x] I would be willing to contribute a fix for this bug with guidance from
the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]