-
Notifications
You must be signed in to change notification settings - Fork 0
/
m-mingalov_5_Rick_and_Morty.py
54 lines (45 loc) · 2.04 KB
/
m-mingalov_5_Rick_and_Morty.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Создайте в GreenPlum'е таблицу с названием "<ваш_логин>_ram_location" с полями id, name, type, dimension, resident_cnt.
С помощью API (https://rickandmortyapi.com/documentation/#location) найдите три локации сериала "Рик и Морти"
с наибольшим количеством резидентов.
Запишите значения соответствующих полей этих трёх локаций в таблицу. resident_cnt — длина списка в поле residents.
"""
from airflow import DAG
from airflow.utils.dates import days_ago
from airflow.operators.dummy import DummyOperator
from airflow.providers.postgres.operators.postgres import PostgresOperator
from m_mingalov_plugins.rick_and_morty_operator import TopLocationsRickAndMorty
DEFAULT_ARGS = {
'start_date': days_ago(1),
'owner': 'm-mingalov',
'poke_interval': 606
}
with DAG("m-mingalov_5_Rick_and_Morty",
schedule_interval=None,
default_args=DEFAULT_ARGS,
max_active_runs=1,
tags=['m-mingalov']
) as dag:
start_process = DummyOperator(task_id='start_process')
create_or_truncate_table = PostgresOperator(
task_id='create_or_truncate_table',
postgres_conn_id='conn_greenplum_write',
sql=[
'''
CREATE TABLE IF NOT EXISTS "m-mingalov_ram_location"
(
id INTEGER PRIMARY KEY,
name VARCHAR(256),
type VARCHAR(256),
dimension VARCHAR(256),
resident_cnt INTEGER
)
DISTRIBUTED BY (id);''',
'''TRUNCATE TABLE "m-mingalov_ram_location";'''
],
autocommit=True
)
top_locations_rick_and_morty = TopLocationsRickAndMorty(task_id='top_locations_rick_and_morty')
end_process = DummyOperator(task_id='end_process')
#DAG
start_process >> create_or_truncate_table >> top_locations_rick_and_morty >> end_process