From d5aa768b2d4bca72ef98f8d533fe3f99624b172f Mon Sep 17 00:00:00 2001 From: utkarsh sharma Date: Thu, 18 Aug 2022 15:07:21 +0530 Subject: [PATCH] Add the readme.md dag to example dags --- example_dags/calculate_popular_movies.py | 37 ++++++++++++++++++++++++ tests/test_example_dags.py | 1 + 2 files changed, 38 insertions(+) create mode 100644 example_dags/calculate_popular_movies.py diff --git a/example_dags/calculate_popular_movies.py b/example_dags/calculate_popular_movies.py new file mode 100644 index 000000000..6c1d0d2b9 --- /dev/null +++ b/example_dags/calculate_popular_movies.py @@ -0,0 +1,37 @@ +from datetime import datetime + +from airflow import DAG + +from astro import sql as aql +from astro.files import File +from astro.sql.table import Table + + +@aql.transform() +def top_five_animations(input_table: Table): + return """ + SELECT Title, Rating + FROM {{input_table}} + WHERE Genre1=='Animation' + ORDER BY Rating desc + LIMIT 5; + """ + + +with DAG( + "calculate_popular_movies", + schedule_interval=None, + start_date=datetime(2000, 1, 1), + catchup=False, +) as dag: + imdb_movies = aql.load_file( + File( + "https://raw.githubusercontent.com/astronomer/astro-sdk/main/tests/data/imdb.csv" + ), + output_table=Table(conn_id="sqlite_default"), + ) + top_five_animations( + input_table=imdb_movies, + output_table=Table(name="top_animation"), + ) + aql.cleanup() diff --git a/tests/test_example_dags.py b/tests/test_example_dags.py index a7ab6d197..581eb25f2 100644 --- a/tests/test_example_dags.py +++ b/tests/test_example_dags.py @@ -61,6 +61,7 @@ def session(): "example_load_file", "example_transform", "example_merge_bigquery", + "calculate_popular_movies", ], ) def test_example_dag(session, dag_id):