利用 BigQuery 分析链上数据
1. 将链上数据导入 BigQuery
可以使用以下 Python 脚本将 Google Cloud Storage(GCS)中的 .csv 文件数据加载到 BigQuery 表中:
client = bigquery.Client()
dataset_id = "your_dataset"
table_id = "your_table"
job_config = bigquery.LoadJobConfig(
source_format=bigquery.SourceFormat.CSV, skip_leading_rows=1,
autodetect=True)
# Get the URI for the blob
uri = f"gs://{bucket_name}/{blob_name}"
load_job = client.load_table_from_uri(
uri, f"{dataset_id}.{table_id}", job_config=job_config
)
# Wait for the load job to complete.
load_job.result()
destination_table = client.get_table(f"{dataset_id}.{table_id}")
print("Loaded {} rows.".format(destination_table.num_rows))
此脚本会自动检测数据类型( autodetect=True ),请将 your-
BigQuery分析链上数据指南
超级会员免费看
订阅专栏 解锁全文
75

被折叠的 条评论
为什么被折叠?



