Skip to content
Merged
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
4 changes: 4 additions & 0 deletions pyiceberg/io/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
S3_ANONYMOUS,
S3_CONNECT_TIMEOUT,
S3_ENDPOINT,
S3_FORCE_VIRTUAL_ADDRESSING,
S3_PROXY_URI,
S3_REGION,
S3_REQUEST_TIMEOUT,
Expand Down Expand Up @@ -168,6 +169,9 @@ def _s3(properties: Properties) -> AbstractFileSystem:
if request_timeout := properties.get(S3_REQUEST_TIMEOUT):
config_kwargs["read_timeout"] = float(request_timeout)

if _force_virtual_addressing := properties.get(S3_FORCE_VIRTUAL_ADDRESSING):
config_kwargs["s3"] = {"addressing_style": "virtual"}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍
config_kwargs is passed to botocore.client.Config
https://s3fs.readthedocs.io/en/latest/api.html#s3fs.core.S3FileSystem

botocore.client.Config expects botocore.client.Config in s3 dict
https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html


if s3_anonymous := properties.get(S3_ANONYMOUS):
anon = strtobool(s3_anonymous)
else:
Expand Down
30 changes: 30 additions & 0 deletions tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,36 @@ def test_fsspec_s3_session_properties() -> None:
)


def test_fsspec_s3_session_properties_force_virtual_addressing() -> None:
session_properties: Properties = {
"s3.force-virtual-addressing": True,
"s3.endpoint": "http://localhost:9000",
"s3.access-key-id": "admin",
"s3.secret-access-key": "password",
"s3.region": "us-east-1",
"s3.session-token": "s3.session-token",
**UNIFIED_AWS_SESSION_PROPERTIES,
}

with mock.patch("s3fs.S3FileSystem") as mock_s3fs:
s3_fileio = FsspecFileIO(properties=session_properties)
filename = str(uuid.uuid4())

s3_fileio.new_input(location=f"s3://warehouse/{filename}")

mock_s3fs.assert_called_with(
anon=False,
client_kwargs={
"endpoint_url": "http://localhost:9000",
"aws_access_key_id": "admin",
"aws_secret_access_key": "password",
"region_name": "us-east-1",
"aws_session_token": "s3.session-token",
},
config_kwargs={"s3": {"addressing_style": "virtual"}},
)


def test_fsspec_s3_session_properties_with_anonymous() -> None:
session_properties: Properties = {
"s3.anonymous": "true",
Expand Down