Skip to content

Commit

Permalink
Merge pull request #5 from hotgluexyz/feature/createMissingColumns
Browse files Browse the repository at this point in the history
create column if it is missing
  • Loading branch information
hsyyid authored Oct 5, 2022
2 parents 4400ffc + 4c3caac commit e87b2e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="target-bigquery",
version="0.11.4",
version="0.11.5",
description="Singer.io target for writing data to Google BigQuery",
author="Adswerve",
url="https://github.com/adswerve/target-bigquery",
Expand Down
12 changes: 6 additions & 6 deletions target_bigquery/processhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,12 @@ def _do_temp_table_based_load(self, rows):
self.truncate = True

except Exception as e:
if "Unrecognized name: _time_" not in str(e):
raise
else:
if "Unrecognized name: " in str(e):
# Add the missing fields
insert_cols = ", ".join(f"ADD COLUMN IF NOT EXISTS {x.name} {x.field_type}" for x in self.bq_schemas[stream])
query ="""ALTER TABLE `{table}`
ADD COLUMN IF NOT EXISTS _time_extracted TIMESTAMP,
ADD COLUMN IF NOT EXISTS _time_loaded TIMESTAMP;
""".format(table=table_id)
{insert_cols};
""".format(table=table_id, insert_cols=insert_cols)
job_config = QueryJobConfig()
query_job = self.client.query(query, job_config=job_config)
query_job.result()
Expand Down Expand Up @@ -332,6 +330,8 @@ def _do_temp_table_based_load(self, rows):
query_job.result()
self.logger.info(f'LOADED {query_job.num_dml_affected_rows} rows')
incremental_success = True
else:
raise

if not incremental_success:
truncate = self.truncate if stream not in self.partially_loaded_streams else False
Expand Down

0 comments on commit e87b2e1

Please sign in to comment.