首先,确保已经安装Google Cloud的Python SDK并验证您的身份验证信息。
在代码中添加以下引用:
from google.cloud.bigquery_storage_v1beta1 import BigQueryStorageClient from google.cloud.bigquery_storage_v1beta1.types import StreamPosition
client = BigQueryStorageClient()
table_ref = "projects/{project_id}/datasets/{dataset_id}/tables/{table_id}".format(project_id=project_id, dataset_id=dataset_id, table_id=table_id) stream_position = StreamPosition(stream=Stream(stream_name=stream_name, stream_offset=stream_offset)) data = [row1, row2, row3]
response = client.write_rows(table_ref, stream_position, data)