google-bigquery - BigQuery 表格标签在更新数据后消失
问题描述
我已经使用网络用户界面为 BigQuery 表设置了标签。但是,当我使用 Python 或 Nodejs 客户端库(参见下面的代码示例)将新数据附加到表中时,标签会消失。这是预期的行为吗?如果是这样,有没有办法在不丢失标签的情况下更新表数据?节点:
const metadata = {
sourceFormat: "NEWLINE_DELIMITED_JSON",
autodetect: true,
writeDisposition: "WRITE_APPEND",
};
const [job] = await bigquery
.dataset(datasetId)
.table(tableId)
.load(filename, metadata);
Python:
data.to_gbq(
'datasetname.tablename',
project_id='projectid',
if_exists='replace'
)
解决方案
我尝试使用下面的代码重现您的问题,正如您在图像中看到的那样,标签没有受到影响。
from google.cloud import bigquery
client = bigquery.Client("my-project-id")
filename = "/path/to/file"
dataset_ref = client.dataset("dataset_id")
table_ref = dataset_ref.table("table_id")
job_config = bigquery.LoadJobConfig()
job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
with open(filename, "rb") as source_file:
job = client.load_table_from_file(source_file, table_ref, job_config=job_config)
编辑:
当使用 Pandas 写入 BigQuery 时,如果您将属性“if_exists”设置为“replace”,则该表将被删除并创建另一个表,可以在此处找到。
推荐阅读
- objective-c - 尝试从 MacOS 上的 Objective-C 上传文本以在 IIS Web 服务器文件夹中创建文件时出现错误 405
- c++ - 如何使用 bazel 查看崩溃时的行号
- routes - 导航到页面时Angular 8重复路径
- javascript - 限制 Object.fromEntries 的推断类型
- r - 在自定义函数中使用 ggplots stat_function
- r - 将带有 Excel 日期的列格式化为文本
- vue.js - 怎么知道回不去 VueJS
- architecture - Bob 大叔的干净代码用例定义
- c++ - QSortFilterProxyModel 只过滤子项
- reactjs - 反应导航路线参数