Closed heehehe closed 11 months ago
from google.cloud import bigquery
# 클라이언트를 생성하고, GCP 프로젝트 ID를 설정합니다.
client = bigquery.Client(project='your_project_id')
# 업로드할 데이터셋과 테이블을 설정합니다.
dataset_id = 'your_dataset_id'
table_id = 'your_table_id'
# 데이터셋과 테이블을 참조합니다.
dataset_ref = client.dataset(dataset_id)
table_ref = dataset_ref.table(table_id)
# JSON 형태의 데이터를 준비합니다.
# 예를 들면, 다음과 같은 데이터가 있을 수 있습니다.
rows_to_insert = [
{"column_name1": "value1", "column_name2": "value2"},
{"column_name1": "value3", "column_name2": "value4"},
]
# API를 통해 데이터를 업로드합니다.
errors = client.insert_rows_json(table=table_ref, json_rows=rows_to_insert)
if errors == []:
print("New rows have been added.")
else:
print("Errors occurred:", errors)
bq load \
--source_format=[FORMAT] \
[DATASET].[TABLE] \
[PATH_TO_SOURCE] \
[SCHEMA]
(ex)
bq load \
--source_format=CSV \
--autodetect \ # 스키마를 자동으로 감지
--skip_leading_rows=1 \
mydataset.mytable \
gs://mybucket/mydata.csv