From e7cb8fd2c4a82b8186d09e83253df3d6573d9cd4 Mon Sep 17 00:00:00 2001 From: okzapradhana Date: Tue, 22 Jun 2021 10:15:56 +0800 Subject: [PATCH] fix get column difference logic --- services/bigquery_client.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/services/bigquery_client.py b/services/bigquery_client.py index 19775e4..5c5ee6e 100644 --- a/services/bigquery_client.py +++ b/services/bigquery_client.py @@ -66,7 +66,10 @@ def insert(self, table, values, **schema): ''') - self.client.query(insert_query, job_config=self.job_config) + job_config = bigquery.QueryJobConfig( + dry_run=True, use_query_cache=False) + + self.client.query(insert_query, job_config=job_config) # Commit query by enqueue it if Dry Run Queue produces no error self.commit(insert_query) @@ -181,10 +184,11 @@ def delete(self, table, values, **schema): def get_column_differences(self, table, column_names): current_table_column = self.get_table_columns(table) - if len(column_names) > len(current_table_column): - column_differences = set(column_names).symmetric_difference( - set(current_table_column)) + # Get differences column from column names in payload with column names in target table + column_differences = set(column_names).difference( + set(current_table_column)) + if len(column_differences) > 0: raise ValueError("Column {} are not exist in table {}!".format( ', '.join(column_differences), table))