Skip to content

Commit e3e796b

Browse files
committed
support fsspec s3 addressing_style
1 parent eb00834 commit e3e796b

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

pyiceberg/io/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
S3_PROXY_URI = "s3.proxy-uri"
6363
S3_CONNECT_TIMEOUT = "s3.connect-timeout"
6464
S3_REQUEST_TIMEOUT = "s3.request-timeout"
65+
S3_ADDRESSING_STYLE = "s3.addressing-style"
6566
S3_SIGNER = "s3.signer"
6667
S3_SIGNER_URI = "s3.signer.uri"
6768
S3_SIGNER_ENDPOINT = "s3.signer.endpoint"

pyiceberg/io/fsspec.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
HF_ENDPOINT,
6868
HF_TOKEN,
6969
S3_ACCESS_KEY_ID,
70+
S3_ADDRESSING_STYLE,
7071
S3_ANONYMOUS,
7172
S3_CONNECT_TIMEOUT,
7273
S3_ENDPOINT,
@@ -168,6 +169,9 @@ def _s3(properties: Properties) -> AbstractFileSystem:
168169
if request_timeout := properties.get(S3_REQUEST_TIMEOUT):
169170
config_kwargs["read_timeout"] = float(request_timeout)
170171

172+
if addressing_style := properties.get(S3_ADDRESSING_STYLE):
173+
config_kwargs["s3"] = {"addressing_style": addressing_style}
174+
171175
if s3_anonymous := properties.get(S3_ANONYMOUS):
172176
anon = strtobool(s3_anonymous)
173177
else:

tests/io/test_fsspec.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,36 @@ def test_fsspec_s3_session_properties() -> None:
306306
)
307307

308308

309+
def test_fsspec_s3_session_properties_with_addressing_style() -> None:
310+
session_properties: Properties = {
311+
"s3.addressing-style": "virtual",
312+
"s3.endpoint": "http://localhost:9000",
313+
"s3.access-key-id": "admin",
314+
"s3.secret-access-key": "password",
315+
"s3.region": "us-east-1",
316+
"s3.session-token": "s3.session-token",
317+
**UNIFIED_AWS_SESSION_PROPERTIES,
318+
}
319+
320+
with mock.patch("s3fs.S3FileSystem") as mock_s3fs:
321+
s3_fileio = FsspecFileIO(properties=session_properties)
322+
filename = str(uuid.uuid4())
323+
324+
s3_fileio.new_input(location=f"s3://warehouse/{filename}")
325+
326+
mock_s3fs.assert_called_with(
327+
anon=False,
328+
client_kwargs={
329+
"endpoint_url": "http://localhost:9000",
330+
"aws_access_key_id": "admin",
331+
"aws_secret_access_key": "password",
332+
"region_name": "us-east-1",
333+
"aws_session_token": "s3.session-token",
334+
},
335+
config_kwargs={"s3": {"addressing_style": "virtual"}},
336+
)
337+
338+
309339
def test_fsspec_s3_session_properties_with_anonymous() -> None:
310340
session_properties: Properties = {
311341
"s3.anonymous": "true",

0 commit comments

Comments
 (0)