From 1fb254ee732d4c4aeea94b613cc427aab8814823 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 16:27:30 +0530 Subject: [PATCH 1/3] feat(io): accept the Java S3 client properties Java configs use s3.path-style-access, http-client.proxy-endpoint and http-client.connection-timeout-ms. Fold them into the property names the PyArrow and fsspec backends read, keeping the native keys when both are set. --- pyiceberg/io/__init__.py | 21 ++++++++++++++++++++- pyiceberg/io/fsspec.py | 3 ++- pyiceberg/io/pyarrow.py | 3 ++- tests/io/test_fsspec.py | 22 ++++++++++++++++++++++ tests/io/test_pyarrow.py | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/pyiceberg/io/__init__.py b/pyiceberg/io/__init__.py index cc63530195..c1ea35a709 100644 --- a/pyiceberg/io/__init__.py +++ b/pyiceberg/io/__init__.py @@ -40,7 +40,7 @@ from pyiceberg.io.content_cache import ContentCache from pyiceberg.typedef import EMPTY_DICT, Properties -from pyiceberg.utils.properties import property_as_bool, property_as_int +from pyiceberg.utils.properties import property_as_bool, property_as_float, property_as_int logger = logging.getLogger(__name__) @@ -89,6 +89,9 @@ def _is_local_path(path: str) -> bool: S3_ALLOW_DELAYED_OPEN = "s3.allow-delayed-open" S3_SERVER_SIDE_ENCRYPTION = "s3.server-side-encryption" S3_SSE_KMS_KEY_ID = "s3.sse-kms-key-id" +S3_PATH_STYLE_ACCESS = "s3.path-style-access" +S3_PROXY_ENDPOINT = "http-client.proxy-endpoint" +S3_CONNECT_TIMEOUT_MS = "http-client.connection-timeout-ms" HDFS_HOST = "hdfs.host" HDFS_PORT = "hdfs.port" HDFS_USER = "hdfs.user" @@ -132,6 +135,22 @@ def _is_local_path(path: str) -> bool: IO_MANIFEST_CACHE_EXPIRATION_INTERVAL_MS_DEFAULT = 60_000 +def _resolve_s3_properties(properties: Properties) -> Properties: + resolved: Properties = dict(properties) + + if S3_FORCE_VIRTUAL_ADDRESSING not in resolved and resolved.get(S3_PATH_STYLE_ACCESS) not in (None, ""): + virtual_addressing = not property_as_bool(resolved, S3_PATH_STYLE_ACCESS, False) + resolved[S3_FORCE_VIRTUAL_ADDRESSING] = str(virtual_addressing).lower() + + if S3_PROXY_URI not in resolved and (proxy_endpoint := resolved.get(S3_PROXY_ENDPOINT)) not in (None, ""): + resolved[S3_PROXY_URI] = proxy_endpoint + + if S3_CONNECT_TIMEOUT not in resolved and (timeout_ms := property_as_float(resolved, S3_CONNECT_TIMEOUT_MS)) is not None: + resolved[S3_CONNECT_TIMEOUT] = str(timeout_ms / 1000) + + return resolved + + @runtime_checkable class InputStream(Protocol): """A protocol for the file-like object returned by InputFile.open(...). diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py index 505b5eebbf..3b1d513d64 100644 --- a/pyiceberg/io/fsspec.py +++ b/pyiceberg/io/fsspec.py @@ -93,6 +93,7 @@ OutputFile, OutputStream, _is_local_path, + _resolve_s3_properties, ) from pyiceberg.typedef import Properties from pyiceberg.types import strtobool @@ -470,7 +471,7 @@ class FsspecFileIO(_TransientStateMixin, FileIO): def __init__(self, properties: Properties): self._scheme_to_fs: dict[str, Callable[..., AbstractFileSystem]] = dict(SCHEME_TO_FS) self._init_transient() - super().__init__(properties=properties) + super().__init__(properties=_resolve_s3_properties(properties)) def _init_transient(self) -> None: self._thread_locals = threading.local() diff --git a/pyiceberg/io/pyarrow.py b/pyiceberg/io/pyarrow.py index 6094093540..b7d411070c 100644 --- a/pyiceberg/io/pyarrow.py +++ b/pyiceberg/io/pyarrow.py @@ -131,6 +131,7 @@ OutputFile, OutputStream, _is_local_path, + _resolve_s3_properties, ) from pyiceberg.io.fileformat import DataFileStatistics as DataFileStatistics from pyiceberg.io.fileformat import FileFormatFactory, FileFormatModel, FileFormatWriter @@ -413,7 +414,7 @@ class PyArrowFileIO(_TransientStateMixin, FileIO): def __init__(self, properties: Properties = EMPTY_DICT): self._init_transient() - super().__init__(properties=properties) + super().__init__(properties=_resolve_s3_properties(properties)) def _init_transient(self) -> None: self.fs_by_scheme = lru_cache(self._initialize_fs) diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py index 9c76e535fe..05ea8f69d3 100644 --- a/tests/io/test_fsspec.py +++ b/tests/io/test_fsspec.py @@ -370,6 +370,28 @@ def test_fsspec_s3_session_properties_force_virtual_addressing( ) +def test_fsspec_s3_accepts_java_client_properties() -> None: + session_properties: Properties = { + "s3.path-style-access": "false", + "http-client.proxy-endpoint": "http://proxy:8080", + "http-client.connection-timeout-ms": "1500", + "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: + FsspecFileIO(properties=session_properties).new_input(location=f"s3://warehouse/{uuid.uuid4()}") + + config_kwargs = mock_s3fs.call_args.kwargs["config_kwargs"] + assert config_kwargs["s3"] == {"addressing_style": "virtual"} + assert config_kwargs["proxies"] == {"http": "http://proxy:8080", "https": "http://proxy:8080"} + assert config_kwargs["connect_timeout"] == 1.5 + + def test_fsspec_s3_session_properties_with_anonymous() -> None: session_properties: Properties = { "s3.anonymous": "true", diff --git a/tests/io/test_pyarrow.py b/tests/io/test_pyarrow.py index 658f10bb10..91cc09773f 100644 --- a/tests/io/test_pyarrow.py +++ b/tests/io/test_pyarrow.py @@ -522,6 +522,45 @@ def test_pyarrow_s3_allow_delayed_open_requires_supported_pyarrow_version() -> N PyArrowFileIO(properties={S3_ALLOW_DELAYED_OPEN: "true"}).new_input(location=f"s3://warehouse/{uuid.uuid4()}") +def test_pyarrow_s3_accepts_java_client_properties() -> None: + session_properties: Properties = { + "s3.region": "us-east-1", + "s3.path-style-access": "true", + "http-client.proxy-endpoint": "http://proxy:8080", + "http-client.connection-timeout-ms": "1500", + } + + with patch("pyarrow.fs.S3FileSystem") as mock_s3fs, patch("pyarrow.fs.resolve_s3_region") as mock_s3_region_resolver: + mock_s3_region_resolver.side_effect = OSError("S3 bucket is not found") + PyArrowFileIO(properties=session_properties).new_input(location=f"s3://warehouse/{uuid.uuid4()}") + + client_kwargs = mock_s3fs.call_args.kwargs + assert client_kwargs["force_virtual_addressing"] is False + assert client_kwargs["proxy_options"] == "http://proxy:8080" + assert client_kwargs["connect_timeout"] == 1.5 + + +def test_pyarrow_s3_native_properties_take_precedence_over_java_properties() -> None: + session_properties: Properties = { + "s3.region": "us-east-1", + "s3.path-style-access": "true", + "s3.force-virtual-addressing": "true", + "http-client.proxy-endpoint": "http://java-proxy:8080", + "s3.proxy-uri": "http://native-proxy:8080", + "http-client.connection-timeout-ms": "1500", + "s3.connect-timeout": "2", + } + + with patch("pyarrow.fs.S3FileSystem") as mock_s3fs, patch("pyarrow.fs.resolve_s3_region") as mock_s3_region_resolver: + mock_s3_region_resolver.side_effect = OSError("S3 bucket is not found") + PyArrowFileIO(properties=session_properties).new_input(location=f"s3://warehouse/{uuid.uuid4()}") + + client_kwargs = mock_s3fs.call_args.kwargs + assert client_kwargs["force_virtual_addressing"] is True + assert client_kwargs["proxy_options"] == "http://native-proxy:8080" + assert client_kwargs["connect_timeout"] == 2.0 + + def test_pyarrow_s3_session_properties_with_anonymous() -> None: session_properties: Properties = { "s3.anonymous": "true", From 312124dfd3340e0df0cb5b1777ab27527b5bea80 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 21:17:50 +0530 Subject: [PATCH 2/3] feat(io): accept the Java S3 socket timeout property http-client.socket-timeout-ms is the Java name for the read timeout. Map it to s3.request-timeout in seconds when the native key is absent. --- pyiceberg/io/__init__.py | 4 ++++ tests/io/test_fsspec.py | 2 ++ tests/io/test_pyarrow.py | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/pyiceberg/io/__init__.py b/pyiceberg/io/__init__.py index c1ea35a709..ff5ce0409c 100644 --- a/pyiceberg/io/__init__.py +++ b/pyiceberg/io/__init__.py @@ -92,6 +92,7 @@ def _is_local_path(path: str) -> bool: S3_PATH_STYLE_ACCESS = "s3.path-style-access" S3_PROXY_ENDPOINT = "http-client.proxy-endpoint" S3_CONNECT_TIMEOUT_MS = "http-client.connection-timeout-ms" +S3_SOCKET_TIMEOUT_MS = "http-client.socket-timeout-ms" HDFS_HOST = "hdfs.host" HDFS_PORT = "hdfs.port" HDFS_USER = "hdfs.user" @@ -148,6 +149,9 @@ def _resolve_s3_properties(properties: Properties) -> Properties: if S3_CONNECT_TIMEOUT not in resolved and (timeout_ms := property_as_float(resolved, S3_CONNECT_TIMEOUT_MS)) is not None: resolved[S3_CONNECT_TIMEOUT] = str(timeout_ms / 1000) + if S3_REQUEST_TIMEOUT not in resolved and (timeout_ms := property_as_float(resolved, S3_SOCKET_TIMEOUT_MS)) is not None: + resolved[S3_REQUEST_TIMEOUT] = str(timeout_ms / 1000) + return resolved diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py index 05ea8f69d3..7b77ae014f 100644 --- a/tests/io/test_fsspec.py +++ b/tests/io/test_fsspec.py @@ -375,6 +375,7 @@ def test_fsspec_s3_accepts_java_client_properties() -> None: "s3.path-style-access": "false", "http-client.proxy-endpoint": "http://proxy:8080", "http-client.connection-timeout-ms": "1500", + "http-client.socket-timeout-ms": "2500", "s3.endpoint": "http://localhost:9000", "s3.access-key-id": "admin", "s3.secret-access-key": "password", @@ -390,6 +391,7 @@ def test_fsspec_s3_accepts_java_client_properties() -> None: assert config_kwargs["s3"] == {"addressing_style": "virtual"} assert config_kwargs["proxies"] == {"http": "http://proxy:8080", "https": "http://proxy:8080"} assert config_kwargs["connect_timeout"] == 1.5 + assert config_kwargs["read_timeout"] == 2.5 def test_fsspec_s3_session_properties_with_anonymous() -> None: diff --git a/tests/io/test_pyarrow.py b/tests/io/test_pyarrow.py index 91cc09773f..3a60444893 100644 --- a/tests/io/test_pyarrow.py +++ b/tests/io/test_pyarrow.py @@ -528,6 +528,7 @@ def test_pyarrow_s3_accepts_java_client_properties() -> None: "s3.path-style-access": "true", "http-client.proxy-endpoint": "http://proxy:8080", "http-client.connection-timeout-ms": "1500", + "http-client.socket-timeout-ms": "2500", } with patch("pyarrow.fs.S3FileSystem") as mock_s3fs, patch("pyarrow.fs.resolve_s3_region") as mock_s3_region_resolver: @@ -538,6 +539,7 @@ def test_pyarrow_s3_accepts_java_client_properties() -> None: assert client_kwargs["force_virtual_addressing"] is False assert client_kwargs["proxy_options"] == "http://proxy:8080" assert client_kwargs["connect_timeout"] == 1.5 + assert client_kwargs["request_timeout"] == 2.5 def test_pyarrow_s3_native_properties_take_precedence_over_java_properties() -> None: @@ -549,6 +551,8 @@ def test_pyarrow_s3_native_properties_take_precedence_over_java_properties() -> "s3.proxy-uri": "http://native-proxy:8080", "http-client.connection-timeout-ms": "1500", "s3.connect-timeout": "2", + "http-client.socket-timeout-ms": "2500", + "s3.request-timeout": "3", } with patch("pyarrow.fs.S3FileSystem") as mock_s3fs, patch("pyarrow.fs.resolve_s3_region") as mock_s3_region_resolver: @@ -559,6 +563,7 @@ def test_pyarrow_s3_native_properties_take_precedence_over_java_properties() -> assert client_kwargs["force_virtual_addressing"] is True assert client_kwargs["proxy_options"] == "http://native-proxy:8080" assert client_kwargs["connect_timeout"] == 2.0 + assert client_kwargs["request_timeout"] == 3.0 def test_pyarrow_s3_session_properties_with_anonymous() -> None: From 67cc022bf09b4b36370f901571de9695cea750b5 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Wed, 2 Dec 2026 22:00:37 +0530 Subject: [PATCH 3/3] feat(io): accept the Java S3 SSE properties Java configs set s3.sse.type and s3.sse.key. Map s3, kms and dsse-kms to the server-side encryption values s3fs expects, and use sse.key as the KMS key for the KMS types. Unsupported types raise instead of silently leaving the object unencrypted. --- pyiceberg/io/__init__.py | 18 +++++++++++++ tests/io/test_fsspec.py | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/pyiceberg/io/__init__.py b/pyiceberg/io/__init__.py index ff5ce0409c..8360bfcb33 100644 --- a/pyiceberg/io/__init__.py +++ b/pyiceberg/io/__init__.py @@ -89,10 +89,18 @@ def _is_local_path(path: str) -> bool: S3_ALLOW_DELAYED_OPEN = "s3.allow-delayed-open" S3_SERVER_SIDE_ENCRYPTION = "s3.server-side-encryption" S3_SSE_KMS_KEY_ID = "s3.sse-kms-key-id" +S3_SSE_TYPE = "s3.sse.type" +S3_SSE_KEY = "s3.sse.key" S3_PATH_STYLE_ACCESS = "s3.path-style-access" S3_PROXY_ENDPOINT = "http-client.proxy-endpoint" S3_CONNECT_TIMEOUT_MS = "http-client.connection-timeout-ms" S3_SOCKET_TIMEOUT_MS = "http-client.socket-timeout-ms" + +S3_SSE_TYPE_TO_ENCRYPTION = { + "s3": "AES256", + "kms": "aws:kms", + "dsse-kms": "aws:kms:dsse", +} HDFS_HOST = "hdfs.host" HDFS_PORT = "hdfs.port" HDFS_USER = "hdfs.user" @@ -152,6 +160,16 @@ def _resolve_s3_properties(properties: Properties) -> Properties: if S3_REQUEST_TIMEOUT not in resolved and (timeout_ms := property_as_float(resolved, S3_SOCKET_TIMEOUT_MS)) is not None: resolved[S3_REQUEST_TIMEOUT] = str(timeout_ms / 1000) + if S3_SERVER_SIDE_ENCRYPTION not in resolved and (sse_type := resolved.get(S3_SSE_TYPE)) not in (None, ""): + normalized_sse_type = str(sse_type).lower() + if normalized_sse_type != "none": + if (encryption := S3_SSE_TYPE_TO_ENCRYPTION.get(normalized_sse_type)) is None: + raise ValueError(f"Unsupported {S3_SSE_TYPE}: {sse_type}") + resolved[S3_SERVER_SIDE_ENCRYPTION] = encryption + if normalized_sse_type in ("kms", "dsse-kms") and S3_SSE_KMS_KEY_ID not in resolved: + if (sse_key := resolved.get(S3_SSE_KEY)) not in (None, ""): + resolved[S3_SSE_KMS_KEY_ID] = sse_key + return resolved diff --git a/tests/io/test_fsspec.py b/tests/io/test_fsspec.py index 7b77ae014f..5f013a0d4c 100644 --- a/tests/io/test_fsspec.py +++ b/tests/io/test_fsspec.py @@ -394,6 +394,62 @@ def test_fsspec_s3_accepts_java_client_properties() -> None: assert config_kwargs["read_timeout"] == 2.5 +@pytest.mark.parametrize( + ("sse_type", "server_side_encryption", "kms_key_id"), + [ + ("s3", "AES256", None), + ("kms", "aws:kms", "test-key"), + ("dsse-kms", "aws:kms:dsse", "test-key"), + ("none", None, None), + ], +) +def test_fsspec_s3_accepts_java_sse_type(sse_type: str, server_side_encryption: str | None, kms_key_id: str | None) -> None: + session_properties: Properties = { + "s3.sse.type": sse_type, + "s3.sse.key": "test-key", + "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: + FsspecFileIO(properties=session_properties).new_input(location=f"s3://warehouse/{uuid.uuid4()}") + + additional_kwargs = mock_s3fs.call_args.kwargs.get("s3_additional_kwargs", {}) + assert additional_kwargs.get("ServerSideEncryption") == server_side_encryption + assert additional_kwargs.get("SSEKMSKeyId") == kms_key_id + + +def test_fsspec_s3_native_sse_takes_precedence_over_java_sse_type() -> None: + session_properties: Properties = { + "s3.sse.type": "kms", + "s3.sse.key": "java-key", + "s3.server-side-encryption": "AES256", + "s3.sse-kms-key-id": "native-key", + "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: + FsspecFileIO(properties=session_properties).new_input(location=f"s3://warehouse/{uuid.uuid4()}") + + additional_kwargs = mock_s3fs.call_args.kwargs["s3_additional_kwargs"] + assert additional_kwargs["ServerSideEncryption"] == "AES256" + assert additional_kwargs["SSEKMSKeyId"] == "native-key" + + +def test_fsspec_s3_rejects_unsupported_java_sse_type() -> None: + with pytest.raises(ValueError, match="Unsupported s3.sse.type: custom"): + FsspecFileIO(properties={"s3.sse.type": "custom"}) + + def test_fsspec_s3_session_properties_with_anonymous() -> None: session_properties: Properties = { "s3.anonymous": "true",