forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(airflow): fix AthenaOperator extraction (datahub-project#11857)
Co-authored-by: Harshal Sheth <[email protected]>
- Loading branch information
Showing
6 changed files
with
1,440 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
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
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, | ||
}, | ||
output_location="s3://athena-results-bucket/", | ||
) |
Oops, something went wrong.