def setUp(self): self.project_id = app_identity.get_application_id() self.dataset_id = os.environ.get('UNIONED_DATASET_ID') self.fq_person = f'{self.project_id}.{self.dataset_id}.person' self.fq_person_ext = f'{self.project_id}.{self.dataset_id}.person_ext' self.table_ids = [self.fq_person, self.fq_person_ext] self.person = Table.from_string(self.fq_person) self.person_ext = Table.from_string(self.fq_person_ext) self.client = bq.get_client(self.project_id) for table in self.table_ids: self.client.delete_table(table, not_found_ok=True) bq.create_tables(self.client, self.project_id, self.table_ids) self.populate_tables()
def create_table(schema_file_name): # Creates table named bq_table_inventory to store metadata credentials2 = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_KEY_FILE_PATH2) ct_bigquery_client = client.Client(project=PROJECT_ID2, credentials=credentials2) table1 = Table.from_string(PROJECT_ID2 + "." + DATASET_ID + "." + TABLE_ID) table1.schema = prepare_schema(schema_file_name) table1.partitioning_type = 'DAY' ct_bigquery_client.create_table(table1, exists_ok=True)
def _get_table(*, project_id: str, client, dataset: str, table_name: str) -> Optional[Table]: """Returns a Table object found in BQ from the provided |project_id|, |dataset|, and |table_name|.""" table_id = f'{project_id}.{dataset}.{table_name}' table = Table.from_string(table_id) return client.get_table(table)