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
1 change: 1 addition & 0 deletions mkdocs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ For the FileIO there are several configuration options available:
| s3.server-side-encryption | aws:kms | Configure server-side encryption (e.g. `AES256` or `aws:kms`). Only supported by `FsspecFileIO`. |
| s3.sse-kms-key-id | alias/my-key | Configure the SSE-KMS key id (or ARN) for multipart uploads. Only supported by `FsspecFileIO`. |
| s3.ssl.ca-cert | /etc/ssl/certs/ca.pem | Path to a CA certificate bundle used to verify TLS connections to the S3 endpoint. Only supported by `PyArrowFileIO`, and requires pyarrow 21.0.0 or later. |
| s3.allow-delayed-open | True | Whether file-open methods may return before the object is actually opened. When enabled, writes of objects smaller than the multipart part size (10 MiB) are sent as a single `PutObject` request instead of a multipart upload (3 requests). Errors such as a missing bucket are then reported on write or close instead of on open. Only supported by `PyArrowFileIO`, and requires pyarrow 21.0.0 or later. |

<!-- markdown-link-check-enable-->

Expand Down
1 change: 1 addition & 0 deletions pyiceberg/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def _is_local_path(path: str) -> bool:
S3_ROLE_SESSION_NAME = "s3.role-session-name"
S3_FORCE_VIRTUAL_ADDRESSING = "s3.force-virtual-addressing"
S3_RETRY_STRATEGY_IMPL = "s3.retry-strategy-impl"
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"
HDFS_HOST = "hdfs.host"
Expand Down
13 changes: 13 additions & 0 deletions pyiceberg/io/pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
HDFS_PORT,
HDFS_USER,
S3_ACCESS_KEY_ID,
S3_ALLOW_DELAYED_OPEN,
S3_ANONYMOUS,
S3_CONNECT_TIMEOUT,
S3_ENDPOINT,
Expand Down Expand Up @@ -479,6 +480,16 @@ def _set_tls_ca_file_path(self, client_kwargs: dict[str, Any]) -> None:
)
client_kwargs["tls_ca_file_path"] = tls_ca_file_path

def _set_allow_delayed_open(self, client_kwargs: dict[str, Any]) -> None:
if self.properties.get(S3_ALLOW_DELAYED_OPEN) is not None:
min_pyarrow_version_supporting_allow_delayed_open = (21, 0)
if tuple(map(int, pa.__version__.split(".")[:2])) < min_pyarrow_version_supporting_allow_delayed_open:
raise ImportError(
"pyarrow version >= 21.0.0 required for S3FileSystem allow_delayed_open support, "
f"but found version {pa.__version__}."
)
client_kwargs["allow_delayed_open"] = property_as_bool(self.properties, S3_ALLOW_DELAYED_OPEN, False)

def _initialize_oss_fs(self) -> FileSystem:
from pyarrow.fs import S3FileSystem

Expand Down Expand Up @@ -512,6 +523,7 @@ def _initialize_oss_fs(self) -> FileSystem:
client_kwargs["anonymous"] = strtobool(s3_anonymous)

self._set_tls_ca_file_path(client_kwargs)
self._set_allow_delayed_open(client_kwargs)

return S3FileSystem(**client_kwargs)

Expand Down Expand Up @@ -570,6 +582,7 @@ def _initialize_s3_fs(self, netloc: str | None) -> FileSystem:
client_kwargs["anonymous"] = strtobool(s3_anonymous)

self._set_tls_ca_file_path(client_kwargs)
self._set_allow_delayed_open(client_kwargs)

return S3FileSystem(**client_kwargs)

Expand Down
55 changes: 54 additions & 1 deletion tests/io/test_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@
Or,
)
from pyiceberg.expressions.literals import literal
from pyiceberg.io import ADLS_ACCOUNT_NAME, S3_RETRY_STRATEGY_IMPL, S3_SSL_CA_CERT, InputStream, OutputStream, load_file_io
from pyiceberg.io import (
ADLS_ACCOUNT_NAME,
S3_ALLOW_DELAYED_OPEN,
S3_RETRY_STRATEGY_IMPL,
S3_SSL_CA_CERT,
InputStream,
OutputStream,
load_file_io,
)
from pyiceberg.io.pyarrow import (
ICEBERG_SCHEMA,
PYARROW_PARQUET_FIELD_ID_KEY,
Expand Down Expand Up @@ -469,6 +477,51 @@ def test_pyarrow_s3_ssl_ca_cert_requires_supported_pyarrow_version() -> None:
PyArrowFileIO(properties=session_properties).new_input(location=f"s3://warehouse/{uuid.uuid4()}")


@pytest.mark.parametrize("value, expected", [("true", True), ("false", False)])
def test_pyarrow_s3_allow_delayed_open(value: str, expected: bool) -> None:
session_properties: Properties = {S3_ALLOW_DELAYED_OPEN: value}

with (
patch("pyiceberg.io.pyarrow.pa.__version__", "21.0.0"),
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()}")

assert mock_s3fs.call_args.kwargs["allow_delayed_open"] is expected


def test_pyarrow_s3_allow_delayed_open_not_set_by_default() -> None:
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={"s3.region": "us-east-1"}).new_input(location=f"s3://warehouse/{uuid.uuid4()}")

assert "allow_delayed_open" not in mock_s3fs.call_args.kwargs


def test_pyarrow_oss_allow_delayed_open() -> None:
with (
patch("pyiceberg.io.pyarrow.pa.__version__", "21.0.0"),
patch("pyarrow.fs.S3FileSystem") as mock_s3fs,
):
PyArrowFileIO(properties={S3_ALLOW_DELAYED_OPEN: "true"}).new_input(location=f"oss://warehouse/{uuid.uuid4()}")

assert mock_s3fs.call_args.kwargs["allow_delayed_open"] is True


def test_pyarrow_s3_allow_delayed_open_requires_supported_pyarrow_version() -> None:
with (
patch("pyiceberg.io.pyarrow.pa.__version__", "20.0.0"),
patch("pyarrow.fs.S3FileSystem"),
patch("pyarrow.fs.resolve_s3_region") as mock_s3_region_resolver,
):
mock_s3_region_resolver.side_effect = OSError("S3 bucket is not found")

with pytest.raises(ImportError, match="pyarrow version >= 21.0.0 required for S3FileSystem allow_delayed_open"):
PyArrowFileIO(properties={S3_ALLOW_DELAYED_OPEN: "true"}).new_input(location=f"s3://warehouse/{uuid.uuid4()}")


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