-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ingestion/airflow-plugin): fix AthenaOperator extraction
The GenericSqlExtractor which is currently by the DataHub Airflow plugin to extract lineage information does not properly support the AthenaOperator and crashes with "AttributeError: 'AthenaOperator' object has no attribute 'sql'". This patch introduces a AthenaOperatorExtractor following the BigQueryInsertJobOperatorExtractor example to fix support for the AthenaOperator.
- Loading branch information
Showing
5 changed files
with
748 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
metadata-ingestion-modules/airflow-plugin/tests/integration/dags/athena_operator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from datetime import datetime | ||
|
||
from airflow import DAG | ||
from airflow.providers.amazon.aws.operators.athena import AthenaOperator | ||
|
||
ATHENA_COST_TABLE = "costs" | ||
ATHENA_PROCESSED_TABLE = "processed_costs" | ||
|
||
|
||
def _fake_athena_execute(*args, **kwargs): | ||
pass | ||
|
||
|
||
with DAG( | ||
"athena_operator", | ||
start_date=datetime(2023, 1, 1), | ||
schedule_interval=None, | ||
catchup=False, | ||
) as dag: | ||
# HACK: We don't want to send real requests to Athena. As a workaround, | ||
# we can simply monkey-patch the operator. | ||
AthenaOperator.execute = _fake_athena_execute # type: ignore | ||
|
||
transform_cost_table = AthenaOperator( | ||
aws_conn_id="my_aws", | ||
task_id="transform_cost_table", | ||
database="athena_db", | ||
query=""" | ||
CREATE OR REPLACE TABLE {{ params.out_table_name }} AS | ||
SELECT | ||
id, | ||
month, | ||
total_cost, | ||
area, | ||
total_cost / area as cost_per_area | ||
FROM {{ params.in_table_name }} | ||
""", | ||
params={ | ||
"in_table_name": ATHENA_COST_TABLE, | ||
"out_table_name": ATHENA_PROCESSED_TABLE, | ||
}, | ||
) |
Oops, something went wrong.