You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "AlgoDeveloper400 (via GitHub)" <gi...@apache.org> on 2026/03/17 08:26:35 UTC
[PR] Enhance URI scheme validation for Windows paths [iceberg-python]
AlgoDeveloper400 opened a new pull request, #3161:
URL: https://github.com/apache/iceberg-python/pull/3161
# fix: handle Windows drive letters in `parse_location`
## Rationale for this change
When a Windows user passes a local file path like `C:\Users\file.avro` to `PyArrowFileIO`,
Python's `urlparse` incorrectly treats the Windows drive letter `C` as a URL scheme (like `s3` or `http`).
This caused PyIceberg to crash with:
```
Unrecognized filesystem type in URI: 'c'
```
---
## The Fix
**Before ❌ (Original Code):**
```python
uri = urlparse(location)
if not uri.scheme:
default_scheme = properties.get("DEFAULT_SCHEME", "file")
default_netloc = properties.get("DEFAULT_NETLOC", "")
return default_scheme, default_netloc, os.path.abspath(location)
```
**After ✅ (Fixed Code):**
```python
uri = urlparse(location)
if not uri.scheme or (len(uri.scheme) == 1 and uri.scheme.isalpha()):
# len == 1 and isalpha() catches Windows drive letters like C:\ D:\
default_scheme = properties.get("DEFAULT_SCHEME", "file")
default_netloc = properties.get("DEFAULT_NETLOC", "")
return default_scheme, default_netloc, os.path.abspath(location)
```
**The only change:**
```python
# Before ❌
if not uri.scheme:
# After ✅
if not uri.scheme or (len(uri.scheme) == 1 and uri.scheme.isalpha()):
```
The added condition checks if the scheme is a **single alphabetic character** (e.g. `C`, `D`, `E`)
and treats it as a Windows drive letter instead of a URL scheme.
---
## Example
```python
from pyiceberg.io.pyarrow import PyArrowFileIO
io = PyArrowFileIO()
# Before fix - crashed with: Unrecognized filesystem type in URI: 'c'
# After fix - works correctly
scheme, netloc, path = io.parse_location("C:\\Users\\test\\file.avro")
print(scheme) # 'file'
print(netloc) # ''
print(path) # 'C:\\Users\\test\\file.avro'
```
---
## Impact
This fix affects all local file operations on Windows including:
- Reading local Iceberg tables
- Writing local Iceberg tables
- Any local Avro/Parquet file operations
---
## Are these changes tested?
Yes - existing tests now pass on Windows.
**`tests/test_avro_sanitization.py`**
```
python -m pytest tests/test_avro_sanitization.py -v
```
```
tests/test_avro_sanitization.py::test_comprehensive_field_name_sanitization PASSED
tests/test_avro_sanitization.py::test_comprehensive_avro_compatibility PASSED
tests/test_avro_sanitization.py::test_emoji_field_name_sanitization PASSED
```
**`tests/io/test_pyarrow.py`**
```
python -m pytest tests/io/test_pyarrow.py::test_pyarrow_infer_local_fs_from_path -v
```
```
tests/io/test_pyarrow.py::test_pyarrow_infer_local_fs_from_path PASSED
```
---
## Are there any user-facing changes?
Yes - fixes local file access on Windows for all PyIceberg users.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "AlgoDeveloper400 (via GitHub)" <gi...@apache.org>.
AlgoDeveloper400 commented on PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#issuecomment-4142187373
Okay I will fix the linter,
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#issuecomment-4141448692
@AlgoDeveloper400 can you fix the linter? I think it is reasonable to add this, but we might break it easily since there are no tests to enforce the behavior
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #3161: Enhance URI scheme validation for Windows paths
URL: https://github.com/apache/iceberg-python/pull/3161
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "geruh (via GitHub)" <gi...@apache.org>.
geruh commented on code in PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#discussion_r3083416296
##########
pyiceberg/io/pyarrow.py:
##########
@@ -397,7 +397,8 @@ def parse_location(location: str, properties: Properties = EMPTY_DICT) -> tuple[
"""
uri = urlparse(location)
- if not uri.scheme:
+ if not uri.scheme or (len(uri.scheme) == 1 and uri.scheme.isalpha()):
+ # len == 1 and alpha catches Windows drive letters like C:\ D:\
default_scheme = properties.get("DEFAULT_SCHEME", "file")
default_netloc = properties.get("DEFAULT_NETLOC", "")
return default_scheme, default_netloc, os.path.abspath(location)
Review Comment:
Looks like a few other places use the urlparse and will be affected like fs spec and schema resolution.
https://github.com/apache/iceberg-python/blob/3a993e82b158919b3c1c110df6d21eb044a6616c/pyiceberg/io/__init__.py#L337-L346
Maybe we could create a helper in the init class that all modules could use.
##########
pyiceberg/io/pyarrow.py:
##########
Review Comment:
We could still add against `parse_location` here for the drive something that can ensure we are treating drive letters as local paths and not uri schemes.
How about something like this with the windows paths as parameters
```
def test_parse_location_windows_drive_letter() -> None:
loc = "C:\\Users\\test\\file.avro"
scheme, netloc, _ = PyArrowFileIO.parse_location(loc)
assert scheme == "file"
assert netloc == ""
```
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#issuecomment-4618022241
This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any 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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#issuecomment-4559874545
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "AlgoDeveloper400 (via GitHub)" <gi...@apache.org>.
AlgoDeveloper400 commented on PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#issuecomment-4147597954
@Fokko All the tests are successful and the linter issue has been resolved.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Enhance URI scheme validation for Windows paths [iceberg-python]
Posted by "AlgoDeveloper400 (via GitHub)" <gi...@apache.org>.
AlgoDeveloper400 commented on code in PR #3161:
URL: https://github.com/apache/iceberg-python/pull/3161#discussion_r3146529788
##########
pyiceberg/io/pyarrow.py:
##########
@@ -397,7 +397,8 @@ def parse_location(location: str, properties: Properties = EMPTY_DICT) -> tuple[
"""
uri = urlparse(location)
- if not uri.scheme:
+ if not uri.scheme or (len(uri.scheme) == 1 and uri.scheme.isalpha()):
+ # len == 1 and alpha catches Windows drive letters like C:\ D:\
default_scheme = properties.get("DEFAULT_SCHEME", "file")
default_netloc = properties.get("DEFAULT_NETLOC", "")
return default_scheme, default_netloc, os.path.abspath(location)
Review Comment:
I think that would also work just fine. Especially if it is called in multiple places.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org