Skip to content

Commit

Permalink
feat(airflow): add DatahubRestHook.make_graph method (#12116)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Dec 15, 2024
1 parent 2291c71 commit ecf6c8c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
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

0 comments on commit ecf6c8c

Please sign in to comment.