from google.cloud import bigquery
# Create BQ Client
client = bigquery.Client()
table_id = "gcp-dev-409815.bq_gcs_loads.peoples"
# Creating the schema for BQ tables
schema = [
bigquery.SchemaField("index", "INTEGER"),
bigquery.SchemaField("user_id", "STRING"),
bigquery.SchemaField("first_name", "STRING"),
bigquery.SchemaField("last_name", "STRING"),
bigquery.SchemaField("gender", "STRING"),
bigquery.SchemaField("email", "STRING"),
bigquery.SchemaField("phone", "STRING"),
bigquery.SchemaField("dob", "DATE"),
bigquery.SchemaField("job_title", "STRING")
]
# Create Job Configuration
job_config = bigquery.LoadJobConfig(schema=schema, skip_leading_rows=1, source_format=bigquery.SourceFormat.CSV)
uri = "gs://gcp-dev-409815/csv_data/people-100.csv"
load_job = client.load_table_from_uri(uri, table_id, job_config=job_config)
load_job.result()
destination_table = client.get_table(table_id)
print(f"Total number of records in table : {destination_table.num_rows}")
Ещё видео!