根据Google BigQuery中的查询结果创建一个表格
我们通过Python API使用 Google BigQuery 。我如何从查询结果中创建一个表(新的或覆盖旧的表)?我查阅了查询文档,但我没有觉得它有用。
We're using Google BigQuery via the Python API. How would I create a table (new one or overwrite old one) from query results? I reviewed the query documentation, but I didn't find it useful.
我们要模拟:
We want to simulate:
SELEC ... INTO ...from ANSI SQL。
"SELEC ... INTO ..." from ANSI SQL.
您可以通过在查询中指定目标表来执行此操作。您需要使用 Jobs.insert
API而不是 Jobs.query
调用,并且您应该指定 writeDisposition = WRITE_APPEND
并填写目标表。
You can do this by specifying a destination table in the query. You would need to use the Jobs.insert
API rather than the Jobs.query
call, and you should specify writeDisposition=WRITE_APPEND
and fill out the destination table.
以下是配置的样子,如果您使用的是原始API。如果您使用的是Python,Python客户端应该为这些字段提供访问者:
Here is what the configuration would look like, if you were using the raw API. If you're using Python, the Python client should give accessors to these same fields:
"configuration": {
"query": {
"query": "select count(*) from foo.bar",
"destinationTable": {
"projectId": "my_project",
"datasetId": "my_dataset",
"tableId": "my_table"
},
"createDisposition": "CREATE_IF_NEEDED",
"writeDisposition": "WRITE_APPEND",
}
}