|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from datetime import datetime |
4 | | -from typing import TYPE_CHECKING, List, Optional |
| 4 | +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union |
5 | 5 |
|
6 | 6 | from pydantic.v1 import Field, root_validator |
7 | 7 | from pytz import utc # type:ignore[import-untyped] |
8 | 8 |
|
| 9 | +from pyatlan.model.core import AtlanObject |
9 | 10 | from pyatlan.model.enums import AtlanConnectorType, OpenLineageEventType |
10 | 11 | from pyatlan.model.open_lineage.base import OpenLineageBaseEvent |
11 | 12 | from pyatlan.model.open_lineage.input_dataset import OpenLineageInputDataset |
|
14 | 15 | from pyatlan.model.open_lineage.run import OpenLineageRun |
15 | 16 |
|
16 | 17 | if TYPE_CHECKING: |
| 18 | + from pyatlan.client.aio.client import AsyncAtlanClient |
17 | 19 | from pyatlan.client.atlan import AtlanClient |
18 | 20 |
|
19 | 21 |
|
| 22 | +class OpenLineageRawEvent(AtlanObject): |
| 23 | + """ |
| 24 | + Root model for handling raw OpenLineage events. |
| 25 | +
|
| 26 | + This model accepts any arbitrary data structure (dict, list of dicts, string, etc.) and allows |
| 27 | + it to be sent as raw OpenLineage event data to Atlan's API. |
| 28 | +
|
| 29 | + Use the built-in pydantic methods: |
| 30 | + - OpenLineageRawEvent.parse_raw(json_string) |
| 31 | + - OpenLineageRawEvent.parse_obj(any_data) |
| 32 | + """ |
| 33 | + |
| 34 | + __root__: Union[List[Dict[str, Any]], Dict[str, Any], str, Any] |
| 35 | + |
| 36 | + @classmethod |
| 37 | + def from_json(cls, json_str: str) -> OpenLineageRawEvent: |
| 38 | + """ |
| 39 | + Create an OpenLineageRawEvent from a JSON string. |
| 40 | +
|
| 41 | + :param json_str: JSON string containing raw OpenLineage event data |
| 42 | + :returns: New OpenLineageRawEvent instance |
| 43 | + """ |
| 44 | + return cls.parse_raw(json_str) |
| 45 | + |
| 46 | + @classmethod |
| 47 | + def from_dict(cls, data: Dict[str, Any]) -> OpenLineageRawEvent: |
| 48 | + """ |
| 49 | + Create an OpenLineageRawEvent from a dictionary. |
| 50 | +
|
| 51 | + :param data: Dictionary containing raw OpenLineage event data |
| 52 | + :returns: New OpenLineageRawEvent instance |
| 53 | + """ |
| 54 | + return cls.parse_obj(data) |
| 55 | + |
| 56 | + |
20 | 57 | class OpenLineageEvent(OpenLineageBaseEvent): |
21 | 58 | """ |
22 | 59 | Atlan wrapper for abstracting OpenLineage events. |
@@ -81,3 +118,50 @@ def emit(self, client: AtlanClient) -> None: |
81 | 118 | return client.open_lineage.send( |
82 | 119 | request=self, connector_type=AtlanConnectorType.SPARK |
83 | 120 | ) |
| 121 | + |
| 122 | + async def emit_async(self, client: AsyncAtlanClient) -> None: |
| 123 | + """ |
| 124 | + Send the OpenLineage event to Atlan to be processed (async version). |
| 125 | +
|
| 126 | + :param client: async connectivity to an Atlan tenant |
| 127 | + :raises AtlanError: on any API communication issues |
| 128 | + """ |
| 129 | + return await client.open_lineage.send( |
| 130 | + request=self, connector_type=AtlanConnectorType.SPARK |
| 131 | + ) |
| 132 | + |
| 133 | + @classmethod |
| 134 | + def emit_raw( |
| 135 | + cls, |
| 136 | + client: AtlanClient, |
| 137 | + event: Union[OpenLineageRawEvent, List[Dict[str, Any]], Dict[str, Any], str], |
| 138 | + connector_type: AtlanConnectorType = AtlanConnectorType.SPARK, |
| 139 | + ) -> None: |
| 140 | + """ |
| 141 | + Send raw OpenLineage event data to Atlan to be processed. |
| 142 | +
|
| 143 | + :param client: connectivity to an Atlan tenant |
| 144 | + :param event: Raw event(s) as JSON string, dict, list of dicts, or OpenLineageRawEvent |
| 145 | + :param connector_type: connector type for the OpenLineage event |
| 146 | + :raises AtlanError: on any API communication issues |
| 147 | + """ |
| 148 | + return client.open_lineage.send(request=event, connector_type=connector_type) |
| 149 | + |
| 150 | + @classmethod |
| 151 | + async def emit_raw_async( |
| 152 | + cls, |
| 153 | + client: AsyncAtlanClient, |
| 154 | + event: Union[OpenLineageRawEvent, List[Dict[str, Any]], Dict[str, Any], str], |
| 155 | + connector_type: AtlanConnectorType = AtlanConnectorType.SPARK, |
| 156 | + ) -> None: |
| 157 | + """ |
| 158 | + Send raw OpenLineage event data to Atlan to be processed (async version). |
| 159 | +
|
| 160 | + :param client: async connectivity to an Atlan tenant |
| 161 | + :param event: Raw event(s) as JSON string, dict, list of dicts, or OpenLineageRawEvent |
| 162 | + :param connector_type: connector type for the OpenLineage event |
| 163 | + :raises AtlanError: on any API communication issues |
| 164 | + """ |
| 165 | + return await client.open_lineage.send( |
| 166 | + request=event, connector_type=connector_type |
| 167 | + ) |
0 commit comments