Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Resolve coding error on check if file exists. #855

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def load_process_filegroup_data(
)
zip_file = zip_file_list[0] if zip_file_list else ""
if zip_file != "":
if os.path.isfile(zip_file):
if fetch_gcs_file_names(target_gcs_bucket, zip_file):
source_location_gcs = os.path.join("gs://", target_gcs_bucket, zip_file)
download_file_gcs(
project_id=project_id,
Expand All @@ -154,6 +154,10 @@ def load_process_filegroup_data(
target_file=os.path.join(zip_path, os.path.basename(zip_file)),
target_gcs_bucket=target_gcs_bucket,
)
else:
raise (
f"File gs://{target_gcs_bucket}/{zip_file} does not exist. Cannot continue."
)
else:
# zip file does not exist
logging.info(
Expand Down Expand Up @@ -219,7 +223,7 @@ def load_source_data(
project_id=project_id,
dataset_id=dataset_id,
table_id=table_id,
schema_filepath=schema_filepath,
schema_filepath=f"{schema_filepath}/{str.lower(process_filegroup)}_schema.json",
bucket_name=target_gcs_bucket,
)
if table_exists:
Expand Down Expand Up @@ -261,7 +265,7 @@ def create_dest_table(
project_id: str,
dataset_id: str,
table_id: str,
schema_filepath: list,
schema_filepath: str,
bucket_name: str,
) -> bool:
table_ref = f"{project_id}.{dataset_id}.{table_id}"
Expand All @@ -277,18 +281,18 @@ def create_dest_table(
if not table:
logging.info(
(
f"Table {table_ref} currently does not exist. Attempting to create table."
f"Table {table_ref} currently does not exist. Attempting to create table from filepath {schema_filepath}."
)
)
file_name = os.path.split(schema_filepath)[1]
file_path = os.path.split(schema_filepath)[0]
if check_gcs_file_exists(schema_filepath, bucket_name):
schema = create_table_schema([], bucket_name, schema_filepath)
table = bigquery.Table(table_ref, schema=schema)
client.create_table(table)
logging.info(f"Table {table_ref} was created".format(table_id))
table_exists = True
else:
file_name = os.path.split(schema_filepath)[1]
file_path = os.path.split(schema_filepath)[0]
logging.info(
f"Error: Unable to create table {table_ref} because schema file {file_name} does not exist in location {file_path} in bucket {bucket_name}"
)
Expand Down
16 changes: 8 additions & 8 deletions datasets/nlm_rxnorm/pipelines/nlm_rxnorm/nlm_rxnorm_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxnatomarchive_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand All @@ -118,7 +118,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxnconso_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand All @@ -143,7 +143,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxncui_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand All @@ -168,7 +168,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxncuichange_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand All @@ -193,7 +193,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxndoc_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand All @@ -218,7 +218,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxnrel_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand All @@ -243,7 +243,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxnsab_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand Down Expand Up @@ -293,7 +293,7 @@
"CHUNKSIZE": "750000",
"TARGET_GCS_BUCKET": "{{ var.value.composer_bucket }}",
"TARGET_GCS_PATH": "data/nlm_rxnorm",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema/rxnsty_schema.json",
"SCHEMA_FILEPATH": "data/nlm_rxnorm/schema",
"PROJECT_ID": "{{ var.value.gcp_project }}",
"DATASET_ID": "nlm_rxnorm",
},
Expand Down
16 changes: 8 additions & 8 deletions datasets/nlm_rxnorm/pipelines/nlm_rxnorm/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxnatomarchive_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand All @@ -112,7 +112,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxnconso_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand All @@ -136,7 +136,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxncui_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand All @@ -160,7 +160,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxncuichange_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand All @@ -184,7 +184,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxndoc_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand All @@ -208,7 +208,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxnrel_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand All @@ -232,7 +232,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxnsab_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand Down Expand Up @@ -280,7 +280,7 @@ dag:
CHUNKSIZE: "750000"
TARGET_GCS_BUCKET: "{{ var.value.composer_bucket }}"
TARGET_GCS_PATH: "data/nlm_rxnorm"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema/rxnsty_schema.json"
SCHEMA_FILEPATH: "data/nlm_rxnorm/schema"
PROJECT_ID: "{{ var.value.gcp_project }}"
DATASET_ID: "nlm_rxnorm"

Expand Down
Loading