Skip to content

Commit d4efb39

Browse files
jayckaiserjalvord1
andauthored
Rc/0.3.1 (#46)
* Update metadata to version 0.3.1. * Hotfix/ea custom dag (#44) * Add missing default_args argument to EA Custom DAG super init. * Update CHANGELOG. * Feature/manual_uploads (#45) * change date location * lower db name * Update s3_to_snowflake_dag.py * fix copy into with different pathing * manual upload flag plus date/time regex * Back to original datalake path * Fix default source path * Update CHANGELOG. --------- Co-authored-by: jayckaiser <jayckaiser@gmail.com> --------- Co-authored-by: Julianna Alvord <33033206+jalvord1@users.noreply.github.com>
1 parent 2219e5d commit d4efb39

5 files changed

Lines changed: 38 additions & 10 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea/
2+
*egg-info*

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# ea_airflow_util v0.3.1
2+
## New features
3+
- Boolean argument `is_manual_upload` in `S3ToSnowflakeDag` rearranges S3 source pathing to easier structure for partners
4+
5+
## Under the hood
6+
- Copy statement in `S3ToSnowflakeDag` uses regex instead of string-splitting to infer pull-date and pull-timestamp
7+
8+
## Fixes
9+
- Fix bug in `EACustomDAG` where `default_args` were not passed to DAG super init.
10+
11+
112
# ea_airflow_util v0.3.0
213
## New features
314
- Migrate FTP, ShareFile, casing, and ZIP utilities from Rally into `ea_airflow_util`

ea_airflow_util/dags/ea_custom_dag.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(self,
5555
catchup=catchup,
5656
render_template_as_native_obj=render_template_as_native_obj,
5757
max_active_runs=max_active_runs,
58+
default_args=default_args,
5859
user_defined_macros=user_defined_macros,
5960
sla_miss_callback=slack_sla_miss_callback,
6061
**self.subset_kwargs_to_class(DAG, kwargs) # Remove kwargs not expected in DAG.

ea_airflow_util/dags/s3_to_snowflake_dag.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self,
3737
s3_source_conn_id: str,
3838
s3_dest_conn_id: str,
3939
s3_dest_file_extension: str,
40+
is_manual_upload: bool = False,
4041

4142
pool: str,
4243
full_replace: bool = False, #TODO once on latest version of airflow, use dagrun parameter to allow full_replace runs even if not set here at dag level
@@ -59,6 +60,7 @@ def __init__(self,
5960
self.s3_source_conn_id = s3_source_conn_id
6061
self.s3_dest_conn_id = s3_dest_conn_id
6162
self.s3_dest_file_extension = s3_dest_file_extension
63+
self.is_manual_upload = is_manual_upload
6264

6365
self.full_replace = full_replace
6466
self.pool = pool
@@ -70,18 +72,26 @@ def build_s3_to_snowflake_dag(self, **kwargs):
7072

7173
for resource_name in self.resource_names:
7274

73-
s3_source_prefix = os.path.join(
74-
self.tenant_code, self.data_source,
75-
str(self.api_year), '{{ ds_nodash }}',
76-
resource_name
77-
)
78-
75+
# different source prefix depending on whether the upload to external bucket is manual or not
76+
if self.is_manual_upload:
77+
s3_source_prefix = os.path.join(
78+
self.tenant_code, self.data_source,
79+
resource_name, str(self.api_year),
80+
'{{ ds_nodash }}'
81+
)
82+
else:
83+
s3_source_prefix = os.path.join(
84+
self.tenant_code, self.data_source,
85+
str(self.api_year), '{{ ds_nodash }}',
86+
resource_name
87+
)
88+
7989
datalake_prefix = os.path.join(
8090
self.tenant_code, str(self.api_year),
8191
'{{ ds_nodash }}', '{{ ts_nodash }}',
8292
resource_name
8393
)
84-
94+
8595
## List the s3 files from the source bucket
8696
list_s3_objects = S3ListOperator(
8797
task_id=f'list_s3_objects_{resource_name}',
@@ -155,6 +165,10 @@ def copy_from_datalake_to_raw(self, resource_name, datalake_prefix, full_replace
155165
and api_year = '{self.api_year}'
156166
'''
157167

168+
date_regex = "\\\\d{8}"
169+
ts_regex = "\\\\d{8}T\\\\d{6}"
170+
171+
158172
logging.info(f"Copying from data lake to raw: {datalake_prefix}")
159173
copy_sql = f'''
160174
copy into {self.database}.{self.schema}.{self.data_source}__{resource_name}
@@ -163,8 +177,8 @@ def copy_from_datalake_to_raw(self, resource_name, datalake_prefix, full_replace
163177
select
164178
'{self.tenant_code}' as tenant_code,
165179
'{self.api_year}' as api_year,
166-
to_date(split_part(metadata$filename, '/', 3), 'YYYYMMDD') as pull_date,
167-
to_timestamp(split_part(metadata$filename, '/', 4), 'YYYYMMDDTHH24MISS') as pull_timestamp,
180+
TO_DATE(REGEXP_SUBSTR(metadata$filename, '{date_regex}'), 'YYYYMMDD') AS pull_date,
181+
TO_TIMESTAMP(REGEXP_SUBSTR(metadata$filename, '{ts_regex}'), 'YYYYMMDDTHH24MISS') AS pull_timestamp,
168182
metadata$file_row_number as file_row_number,
169183
metadata$filename as filename,
170184
'{resource_name}' as name,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name='ea_airflow_util',
9-
version='0.3.0',
9+
version='0.3.1',
1010
description='EA Airflow tools',
1111
license_files=['LICENSE'],
1212
url='https://github.com/edanalytics/ea_airflow_util',

0 commit comments

Comments
 (0)