Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(airflow): add DatahubRestHook.make_graph method #12116

Merged
merged 2 commits into from
Dec 15, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""This example DAG demonstrates how to create and use a DataHubGraph client."""

from datetime import timedelta

import pendulum
from airflow.decorators import dag, task
from datahub.ingestion.graph.client import DataHubGraph, RemovedStatusFilter

from datahub_airflow_plugin.hooks.datahub import DatahubRestHook


@dag(
schedule_interval=timedelta(days=1),
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
catchup=False,
)
def datahub_graph_usage_sample_dag():
@task()
def use_the_graph():
graph: DataHubGraph = DatahubRestHook("my_datahub_rest_conn_id").make_graph()
graph.test_connection()

# Example usage: Find all soft-deleted BigQuery DEV entities
# in DataHub, and hard delete them.
for urn in graph.get_urns_by_filter(
platform="bigquery",
env="DEV",
status=RemovedStatusFilter.ONLY_SOFT_DELETED,
):
graph.hard_delete_entity(urn)

use_the_graph()


datahub_graph_usage_sample_dag()
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from datahub.emitter.kafka_emitter import DatahubKafkaEmitter
from datahub.emitter.rest_emitter import DataHubRestEmitter
from datahub.emitter.synchronized_file_emitter import SynchronizedFileEmitter
from datahub.ingestion.graph.client import DataHubGraph
from datahub.ingestion.sink.datahub_kafka import KafkaSinkConfig


Expand Down Expand Up @@ -94,6 +95,9 @@ def make_emitter(self) -> "DataHubRestEmitter":
host, token, **extra_args
)

def make_graph(self) -> "DataHubGraph":
return self.make_emitter().to_graph()

def emit(
self,
items: Sequence[
Expand Down
Loading