@@ -95,4 +95,41 @@ def _transform_to_csv(infile, outfile):
95
95
dag = dag ,
96
96
)
97
97
98
- fetch_data >> transform_to_csv >> normalize_covid_csv >> create_covid_data_table >> load_csv_to_postgres_dwh
98
+ # fetch_data >> transform_to_csv >> normalize_covid_csv >> create_covid_data_table>> load_csv_to_postgres_dwh
99
+
100
+ def _test_transform (infile , outfile ):
101
+ pathlib .Path ("/tmp/data/stg" ).mkdir (parents = True , exist_ok = True )
102
+ data = pd .read_json (infile )
103
+ data = data .set_index ("date_of_interest" )
104
+ data = data [['date_of_interest' , 'case_count' ]]
105
+ data .to_csv (outfile )
106
+ logging .info (f"INFO: Processed { infile } and moved it to { outfile } " )
107
+
108
+ test_transform = PythonOperator (
109
+ task_id = "test_transform" ,
110
+ python_callable = _test_transform ,
111
+ dag = dag ,
112
+ op_kwargs = {
113
+ "infile" : "/tmp/data/raw/covid_data_{{ ds }}.json" ,
114
+ "outfile" : "/tmp/data/raw/covid_data_{{ ds }}.csv" ,
115
+ },
116
+
117
+ )
118
+
119
+ create_covid_test_table = PostgresOperator (
120
+ task_id = "create_covid_test_table" ,
121
+ postgres_conn_id = "covid_postgres" ,
122
+ sql = "sql/create_test.sql" ,
123
+ dag = dag
124
+ )
125
+
126
+
127
+ test_data_load = LoadCsvtoPostgresOperator (
128
+ task_id = 'test_data_load' ,
129
+ postgres_conn_id = "covid_postgres" ,
130
+ table = "covid_test" ,
131
+ file_path = "/tmp/data/stg/covid_data_{{ ds }}.csv" ,
132
+ dag = dag ,
133
+ )
134
+
135
+ fetch_data >> test_transform >> normalize_covid_csv >> create_covid_test_table >> test_data_load
0 commit comments