Skip to content

Слоты Hive

[Slots][DBR-onetl-hooks-design-high-level-design] that could be implemented by third-party plugins.

Added in 0.7.0

Source code in onetl/connection/db_connection/hive/slots.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 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
@support_hooks
class HiveSlots:
    """[Slots][DBR-onetl-hooks-design-high-level-design] that could be implemented by third-party plugins.

    !!! success "Added in 0.7.0"
    """

    @slot
    @staticmethod
    def normalize_cluster_name(cluster: str) -> str | None:
        """
        Normalize cluster name passed into Hive constructor. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

        If hooks didn't return anything, cluster name is left intact.

        !!! success "Added in 0.7.0"

        Parameters
        ----------
        cluster
            Cluster name (raw)

        Returns
        -------
        :
            Normalized cluster name.

            If hook cannot be applied to a specific cluster, it should return `None`.

        Examples
        --------

        ```python
        from onetl.connection import Hive
        from onetl.hooks import hook


        @Hive.Slots.normalize_cluster_name.bind
        @hook
        def normalize_cluster_name(cluster: str) -> str:
            return cluster.lower()
        ```
        """

    @slot
    @staticmethod
    def get_known_clusters() -> set[str] | None:
        """
        Return collection of known clusters. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

        Cluster passed into Hive constructor should be present in this list.
        If hooks didn't return anything, no validation will be performed.

        !!! success "Added in 0.7.0"

        Returns
        -------
        :
            Collection of cluster names (normalized).

            If hook cannot be applied, it should return `None`.

        Examples
        --------

        ```python
        from onetl.connection import Hive
        from onetl.hooks import hook


        @Hive.Slots.get_known_clusters.bind
        @hook
        def get_known_clusters() -> str[str]:
            return {"rnd-dwh", "rnd-prod"}
        ```
        """

    @slot
    @staticmethod
    def get_current_cluster() -> str | None:
        """
        Get current cluster name. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

        Used in [onetl.connection.db_connection.hive.connection.Hive.check][] method to verify that connection is created only from the same cluster.
        If hooks didn't return anything, no validation will be performed.

        !!! success "Added in 0.7.0"

        Returns
        -------
        :
            Current cluster name (normalized).

            If hook cannot be applied, it should return `None`.

        Examples
        --------

        ```python
        from onetl.connection import Hive
        from onetl.hooks import hook


        @Hive.Slots.get_current_cluster.bind
        @hook
        def get_current_cluster() -> str:
            # some magic here
            return "rnd-dwh"
        ```
        """

normalize_cluster_name(cluster) staticmethod

Normalize cluster name passed into Hive constructor. [support hooks][DBR-onetl-hooks]

If hooks didn't return anything, cluster name is left intact.

Added in 0.7.0

Parameters

cluster Cluster name (raw)

Returns

: Normalized cluster name.

If hook cannot be applied to a specific cluster, it should return `None`.

Examples

from onetl.connection import Hive
from onetl.hooks import hook


@Hive.Slots.normalize_cluster_name.bind
@hook
def normalize_cluster_name(cluster: str) -> str:
    return cluster.lower()
Source code in onetl/connection/db_connection/hive/slots.py
13
14
15
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
@slot
@staticmethod
def normalize_cluster_name(cluster: str) -> str | None:
    """
    Normalize cluster name passed into Hive constructor. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

    If hooks didn't return anything, cluster name is left intact.

    !!! success "Added in 0.7.0"

    Parameters
    ----------
    cluster
        Cluster name (raw)

    Returns
    -------
    :
        Normalized cluster name.

        If hook cannot be applied to a specific cluster, it should return `None`.

    Examples
    --------

    ```python
    from onetl.connection import Hive
    from onetl.hooks import hook


    @Hive.Slots.normalize_cluster_name.bind
    @hook
    def normalize_cluster_name(cluster: str) -> str:
        return cluster.lower()
    ```
    """

get_known_clusters() staticmethod

Return collection of known clusters. [support hooks][DBR-onetl-hooks]

Cluster passed into Hive constructor should be present in this list. If hooks didn't return anything, no validation will be performed.

Added in 0.7.0

Returns

: Collection of cluster names (normalized).

If hook cannot be applied, it should return `None`.

Examples

from onetl.connection import Hive
from onetl.hooks import hook


@Hive.Slots.get_known_clusters.bind
@hook
def get_known_clusters() -> str[str]:
    return {"rnd-dwh", "rnd-prod"}
Source code in onetl/connection/db_connection/hive/slots.py
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
@slot
@staticmethod
def get_known_clusters() -> set[str] | None:
    """
    Return collection of known clusters. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

    Cluster passed into Hive constructor should be present in this list.
    If hooks didn't return anything, no validation will be performed.

    !!! success "Added in 0.7.0"

    Returns
    -------
    :
        Collection of cluster names (normalized).

        If hook cannot be applied, it should return `None`.

    Examples
    --------

    ```python
    from onetl.connection import Hive
    from onetl.hooks import hook


    @Hive.Slots.get_known_clusters.bind
    @hook
    def get_known_clusters() -> str[str]:
        return {"rnd-dwh", "rnd-prod"}
    ```
    """

get_current_cluster() staticmethod

Get current cluster name. [support hooks][DBR-onetl-hooks]

Used in onetl.connection.db_connection.hive.connection.Hive.check method to verify that connection is created only from the same cluster. If hooks didn't return anything, no validation will be performed.

Added in 0.7.0

Returns

: Current cluster name (normalized).

If hook cannot be applied, it should return `None`.

Examples

from onetl.connection import Hive
from onetl.hooks import hook


@Hive.Slots.get_current_cluster.bind
@hook
def get_current_cluster() -> str:
    # some magic here
    return "rnd-dwh"
Source code in onetl/connection/db_connection/hive/slots.py
 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
@slot
@staticmethod
def get_current_cluster() -> str | None:
    """
    Get current cluster name. [![support hooks](https://img.shields.io/badge/%20-support%20hooks-blue)][DBR-onetl-hooks]

    Used in [onetl.connection.db_connection.hive.connection.Hive.check][] method to verify that connection is created only from the same cluster.
    If hooks didn't return anything, no validation will be performed.

    !!! success "Added in 0.7.0"

    Returns
    -------
    :
        Current cluster name (normalized).

        If hook cannot be applied, it should return `None`.

    Examples
    --------

    ```python
    from onetl.connection import Hive
    from onetl.hooks import hook


    @Hive.Slots.get_current_cluster.bind
    @hook
    def get_current_cluster() -> str:
        # some magic here
        return "rnd-dwh"
    ```
    """