Last active
February 23, 2024 12:54
-
-
Save salvadorgascon/04e429141b98ab94089699785c2fe364 to your computer and use it in GitHub Desktop.
Create table object in Google Cloud BigQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BIGQUERY_PROJECT_NAME = "project-XXXXX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import bigquery | |
from google.cloud.exceptions import NotFound | |
from google.api_core.exceptions import Conflict | |
from shared.loaders.bigquery_constants import BIGQUERY_PROJECT_NAME | |
def BigQueryCreateTable(bigquery_client, bigquery_dataset_name, bigquery_table_name, table_schema): | |
print("Creating table object if not exists " + f'{BIGQUERY_PROJECT_NAME}.{bigquery_dataset_name}.{bigquery_table_name}') | |
table_definition = bigquery.Table(f'{BIGQUERY_PROJECT_NAME}.{bigquery_dataset_name}.{bigquery_table_name}', | |
schema = table_schema) | |
try: | |
table = bigquery_client.create_table(table_definition) | |
except Conflict as inst: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment