Skip to content

S3 хранилище

Bases: IcebergWarehouse, FrozenModel

Iceberg S3 Warehouse. [support hooks][DBR-onetl-hooks]

Added in 0.15.0

Note

This warehouse uses a dedicated Iceberg S3 client to access the warehouse data. It does not rely on SparkS3 implementation.

Parameters

path Warehouse path

host S3 endpoint hostname

port S3 endpoint port

protocol Protocol to use for S3 connections

bucket S3 bucket name

path_style_access Whether to use path-style access

access_key S3 access key

secret_key S3 secret key

region S3 region

session_token Session token generated by S3 STS service, if used.

extra Additional S3 configuration parameters

Examples

from onetl.connection import Iceberg

warehouse = Iceberg.S3Warehouse(
    path="/warehouse",
    host="s3.domain.com",
    protocol="http",
    bucket="my-bucket",
    region="us-east-1",
    path_style_access=True,
    access_key="my_access_key",
    secret_key="my_secret_key",
)
Source code in onetl/connection/db_connection/iceberg/warehouse/s3.py
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
@support_hooks
class IcebergS3Warehouse(IcebergWarehouse, FrozenModel):
    """Iceberg S3 Warehouse. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

    !!! success "Added in 0.15.0"

    !!! note

        This warehouse uses a **dedicated Iceberg S3 client** to access the warehouse data.
        It does **not rely on SparkS3 implementation**.

    Parameters
    ----------
    path
        Warehouse path

    host
        S3 endpoint hostname

    port
        S3 endpoint port

    protocol
        Protocol to use for S3 connections

    bucket
        S3 bucket name

    path_style_access
        Whether to use path-style access

    access_key
        S3 access key

    secret_key
        S3 secret key

    region
        S3 region

    session_token
        Session token generated by S3 STS service, if used.

    extra
        Additional S3 configuration parameters

    Examples
    --------

    ```python
    from onetl.connection import Iceberg

    warehouse = Iceberg.S3Warehouse(
        path="/warehouse",
        host="s3.domain.com",
        protocol="http",
        bucket="my-bucket",
        region="us-east-1",
        path_style_access=True,
        access_key="my_access_key",
        secret_key="my_secret_key",
    )
    ```
    """

    path: PurePathProtocol
    host: str
    protocol: Literal["http", "https"] = "https"
    port: int = 443
    bucket: str
    region: str
    path_style_access: bool = False
    access_key: str | None = None
    secret_key: SecretStr | None = None
    session_token: SecretStr | None = None
    extra: dict[str, Any] = Field(default_factory=dict)

    @model_validator(mode="before")
    @classmethod
    def _set_port_based_on_protocol(cls, values):
        port = values.get("port")
        if port is not None:
            return values

        values["port"] = 443 if values.get("protocol", "https") == "https" else 80
        return values

    @slot
    def get_config(self) -> dict[str, str]:
        config = {
            "warehouse": "s3a://" + self.bucket + "/" + self.path.as_posix().lstrip("/"),
            "io-impl": "org.apache.iceberg.aws.s3.S3FileIO",
            "s3.endpoint": f"{self.protocol}://{self.host}{f':{self.port}' if self.port else ''}",
            "s3.access-key-id": self.access_key,
            "s3.secret-access-key": self.secret_key.get_secret_value() if self.secret_key else None,
            "s3.session-token": self.session_token.get_secret_value() if self.session_token else None,
            "s3.path-style-access": stringify(self.path_style_access),
            "client.region": self.region,
            **stringify(self.extra),
        }
        return {k: v for k, v in config.items() if v is not None}

    @slot
    @classmethod
    def get_packages(cls, package_version: str) -> list[str]:
        """
        Get package names to be downloaded by Spark. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

        See [Maven package index](https://mvnrepository.com/artifact/org.apache.iceberg/iceberg-aws-bundle)
        for all available packages.

        Parameters
        ----------
        package_version
            Iceberg package version in format `major.minor.patch`.

        Returns
        -------
        :
            List of Maven coordinates.

        Examples
        --------
        ```python
        from onetl.connection import Iceberg

        # Note: Iceberg 1.10.0 requires Java 11+
        # Note: Iceberg 1.11.0 requires Java 17+
        Iceberg.S3Warehouse.get_packages(package_version="1.10.0")
        ```
        """
        version = Version(package_version).min_digits(3)
        return [f"org.apache.iceberg:iceberg-aws-bundle:{version}"]

    @field_validator("path", mode="before")
    @classmethod
    def _validate_path(cls, path):
        return RemotePath(os.fspath(path))

get_packages(package_version) classmethod

Get package names to be downloaded by Spark. [support hooks][DBR-onetl-hooks]

See Maven package index for all available packages.

Parameters

package_version Iceberg package version in format major.minor.patch.

Returns

: List of Maven coordinates.

Examples

from onetl.connection import Iceberg

# Note: Iceberg 1.10.0 requires Java 11+
# Note: Iceberg 1.11.0 requires Java 17+
Iceberg.S3Warehouse.get_packages(package_version="1.10.0")
Source code in onetl/connection/db_connection/iceberg/warehouse/s3.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
@slot
@classmethod
def get_packages(cls, package_version: str) -> list[str]:
    """
    Get package names to be downloaded by Spark. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

    See [Maven package index](https://mvnrepository.com/artifact/org.apache.iceberg/iceberg-aws-bundle)
    for all available packages.

    Parameters
    ----------
    package_version
        Iceberg package version in format `major.minor.patch`.

    Returns
    -------
    :
        List of Maven coordinates.

    Examples
    --------
    ```python
    from onetl.connection import Iceberg

    # Note: Iceberg 1.10.0 requires Java 11+
    # Note: Iceberg 1.11.0 requires Java 17+
    Iceberg.S3Warehouse.get_packages(package_version="1.10.0")
    ```
    """
    version = Version(package_version).min_digits(3)
    return [f"org.apache.iceberg:iceberg-aws-bundle:{version}"]