2023-06-15 00:21:16 -05:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
from datahub.emitter.mce_builder import make_data_job_urn, make_dataset_urn
|
|
|
|
from datahub.emitter.mcp import MetadataChangeProposalWrapper
|
2024-01-31 14:42:40 +05:30
|
|
|
from datahub.metadata.schema_classes import (
|
|
|
|
DataJobInfoClass,
|
|
|
|
DataJobInputOutputClass,
|
|
|
|
EdgeClass,
|
|
|
|
)
|
2023-06-15 00:21:16 -05:00
|
|
|
from datahub.specific.datajob import DataJobPatchBuilder
|
|
|
|
|
|
|
|
from tests.patch.common_patch_tests import (
|
2024-01-31 14:42:40 +05:30
|
|
|
helper_test_custom_properties_patch,
|
|
|
|
helper_test_dataset_tags_patch,
|
|
|
|
helper_test_entity_terms_patch,
|
|
|
|
helper_test_ownership_patch,
|
|
|
|
)
|
2023-06-15 00:21:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
def _make_test_datajob_urn(
|
|
|
|
seedFlow: str = "SampleAirflowDag", seedTask: str = "SampleAirflowTask"
|
|
|
|
):
|
|
|
|
return make_data_job_urn(
|
|
|
|
orchestrator="airflow",
|
|
|
|
flow_id=f"{seedFlow}{uuid.uuid4()}",
|
|
|
|
job_id=f"{seedTask}{uuid.uuid4()}",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Common Aspect Patch Tests
|
|
|
|
# Ownership
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_datajob_ownership_patch(graph_client):
|
2023-06-15 00:21:16 -05:00
|
|
|
datajob_urn = _make_test_datajob_urn()
|
2024-09-27 11:31:25 -05:00
|
|
|
helper_test_ownership_patch(graph_client, datajob_urn, DataJobPatchBuilder)
|
2023-06-15 00:21:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Tags
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_datajob_tags_patch(graph_client):
|
|
|
|
helper_test_dataset_tags_patch(
|
|
|
|
graph_client, _make_test_datajob_urn(), DataJobPatchBuilder
|
|
|
|
)
|
2023-06-15 00:21:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Terms
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_dataset_terms_patch(graph_client):
|
|
|
|
helper_test_entity_terms_patch(
|
|
|
|
graph_client, _make_test_datajob_urn(), DataJobPatchBuilder
|
|
|
|
)
|
2023-06-15 00:21:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Custom Properties
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_custom_properties_patch(graph_client):
|
2023-06-15 00:21:16 -05:00
|
|
|
orig_datajob_info = DataJobInfoClass(name="test_name", type="TestJobType")
|
|
|
|
helper_test_custom_properties_patch(
|
2024-09-27 11:31:25 -05:00
|
|
|
graph_client,
|
2023-06-15 00:21:16 -05:00
|
|
|
test_entity_urn=_make_test_datajob_urn(),
|
|
|
|
patch_builder_class=DataJobPatchBuilder,
|
|
|
|
custom_properties_aspect_class=DataJobInfoClass,
|
|
|
|
base_aspect=orig_datajob_info,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# Specific Aspect Patch Tests
|
|
|
|
# Input/Output
|
2024-09-27 11:31:25 -05:00
|
|
|
def test_datajob_inputoutput_dataset_patch(graph_client):
|
2023-06-15 00:21:16 -05:00
|
|
|
datajob_urn = _make_test_datajob_urn()
|
|
|
|
|
|
|
|
other_dataset_urn = make_dataset_urn(
|
|
|
|
platform="hive", name=f"SampleHiveDataset2-{uuid.uuid4()}", env="PROD"
|
|
|
|
)
|
|
|
|
|
|
|
|
patch_dataset_urn = make_dataset_urn(
|
|
|
|
platform="hive", name=f"SampleHiveDataset3-{uuid.uuid4()}", env="PROD"
|
|
|
|
)
|
|
|
|
|
|
|
|
inputoutput_lineage = DataJobInputOutputClass(
|
|
|
|
inputDatasets=[],
|
|
|
|
outputDatasets=[],
|
|
|
|
inputDatasetEdges=[EdgeClass(destinationUrn=other_dataset_urn)],
|
|
|
|
)
|
|
|
|
dataset_input_lineage_to_add = EdgeClass(destinationUrn=patch_dataset_urn)
|
|
|
|
mcpw = MetadataChangeProposalWrapper(
|
|
|
|
entityUrn=datajob_urn, aspect=inputoutput_lineage
|
|
|
|
)
|
|
|
|
|
2024-09-27 11:31:25 -05:00
|
|
|
graph_client.emit_mcp(mcpw)
|
|
|
|
inputoutput_lineage_read = graph_client.get_aspect(
|
|
|
|
entity_urn=datajob_urn,
|
|
|
|
aspect_type=DataJobInputOutputClass,
|
|
|
|
)
|
|
|
|
assert inputoutput_lineage_read is not None
|
|
|
|
assert inputoutput_lineage_read.inputDatasetEdges is not None
|
|
|
|
assert (
|
|
|
|
inputoutput_lineage_read.inputDatasetEdges[0].destinationUrn
|
|
|
|
== other_dataset_urn
|
|
|
|
)
|
|
|
|
|
|
|
|
for patch_mcp in (
|
|
|
|
DataJobPatchBuilder(datajob_urn)
|
|
|
|
.add_input_dataset(dataset_input_lineage_to_add)
|
|
|
|
.build()
|
|
|
|
):
|
|
|
|
graph_client.emit_mcp(patch_mcp)
|
|
|
|
pass
|
|
|
|
|
|
|
|
inputoutput_lineage_read = graph_client.get_aspect(
|
|
|
|
entity_urn=datajob_urn,
|
|
|
|
aspect_type=DataJobInputOutputClass,
|
|
|
|
)
|
|
|
|
assert inputoutput_lineage_read is not None
|
|
|
|
assert inputoutput_lineage_read.inputDatasetEdges is not None
|
|
|
|
assert len(inputoutput_lineage_read.inputDatasetEdges) == 2
|
|
|
|
assert (
|
|
|
|
inputoutput_lineage_read.inputDatasetEdges[0].destinationUrn
|
|
|
|
== other_dataset_urn
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
inputoutput_lineage_read.inputDatasetEdges[1].destinationUrn
|
|
|
|
== patch_dataset_urn
|
|
|
|
)
|
|
|
|
|
|
|
|
for patch_mcp in (
|
|
|
|
DataJobPatchBuilder(datajob_urn).remove_input_dataset(patch_dataset_urn).build()
|
|
|
|
):
|
|
|
|
graph_client.emit_mcp(patch_mcp)
|
|
|
|
pass
|
|
|
|
|
|
|
|
inputoutput_lineage_read = graph_client.get_aspect(
|
|
|
|
entity_urn=datajob_urn,
|
|
|
|
aspect_type=DataJobInputOutputClass,
|
|
|
|
)
|
|
|
|
assert inputoutput_lineage_read is not None
|
|
|
|
assert inputoutput_lineage_read.inputDatasetEdges is not None
|
|
|
|
assert len(inputoutput_lineage_read.inputDatasetEdges) == 1
|
|
|
|
assert (
|
|
|
|
inputoutput_lineage_read.inputDatasetEdges[0].destinationUrn
|
|
|
|
== other_dataset_urn
|
|
|
|
)
|