Google cloud platform bigquery.tabledata.insertAll方法的API
下面是我写入BigQuery表的代码:Google cloud platform bigquery.tabledata.insertAll方法的API,google-cloud-platform,google-bigquery,google-apis-explorer,Google Cloud Platform,Google Bigquery,Google Apis Explorer,下面是我写入BigQuery表的代码: 从google.cloud导入bigquery response=bigquery.tabledata.insertAll(projectd=PROJECT\u ID,datasetId=DATASET\u ID, tableId=表的ID, body=data.execute() 但是,我得到了以下错误: no module tabledata in google.cloud.bigquery 有人能帮我吗 我应该在这里使用哪种API 请检查文档。使
从google.cloud导入bigquery
response=bigquery.tabledata.insertAll(projectd=PROJECT\u ID,datasetId=DATASET\u ID,
tableId=表的ID,
body=data.execute()
但是,我得到了以下错误:
no module tabledata in google.cloud.bigquery
有人能帮我吗
我应该在这里使用哪种API 请检查文档。使用python时,需要使用以下函数:
insert_rows(table, rows, selected_fields=None, **kwargs)
通过流式API将行插入到表中。有关更多信息,请参阅以下参考文档
您可以检查Python流式插入示例:
# TODO(developer): Import the client library.
# from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()
# TODO(developer): Set table_id to the ID of the model to fetch.
# table_id = "your-project.your_dataset.your_table"
table = client.get_table(table_id) # Make an API request.
rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)]
errors = client.insert_rows(table, rows_to_insert) # Make an API request.
if errors == []:
print("New rows have been added.")
您还可以使用API调用方法来查看API的请求和响应。您需要指定projectId
,datasetId
,tableId
。您可以看到用于执行请求的JavaScript代码段:
function execute() {
return gapi.client.bigquery.tabledata.insertAll({
"projectId": "<your_projectId>",
"datasetId": "<your_datasetId>",
"tableId": "<your_tableId>",
"resource": {}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
函数执行(){
返回gapi.client.bigquery.tabledata.insertAll({
“projected”:“,
“datasetId”:“,
“tableId”:“,
“资源”:{}
})
.然后(功能(响应){
//在这里处理结果(response.result具有解析的主体)。
控制台日志(“响应”,响应);
},
函数(err){console.error(“executeerror”,err);});
}
让我知道结果。请检查文档。使用python时,需要使用以下函数:
insert_rows(table, rows, selected_fields=None, **kwargs)
通过流式API将行插入到表中。有关更多信息,请参阅以下参考文档
您可以检查Python流式插入示例:
# TODO(developer): Import the client library.
# from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()
# TODO(developer): Set table_id to the ID of the model to fetch.
# table_id = "your-project.your_dataset.your_table"
table = client.get_table(table_id) # Make an API request.
rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)]
errors = client.insert_rows(table, rows_to_insert) # Make an API request.
if errors == []:
print("New rows have been added.")
您还可以使用API调用方法来查看API的请求和响应。您需要指定projectId
,datasetId
,tableId
。您可以看到用于执行请求的JavaScript代码段:
function execute() {
return gapi.client.bigquery.tabledata.insertAll({
"projectId": "<your_projectId>",
"datasetId": "<your_datasetId>",
"tableId": "<your_tableId>",
"resource": {}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
函数执行(){
返回gapi.client.bigquery.tabledata.insertAll({
“projected”:“,
“datasetId”:“,
“tableId”:“,
“资源”:{}
})
.然后(功能(响应){
//在这里处理结果(response.result具有解析的主体)。
控制台日志(“响应”,响应);
},
函数(err){console.error(“executeerror”,err);});
}
让我知道结果。哪种语言?在nodejs上?看起来您正在使用Python,请检查此链接,该链接可能会对您有所帮助(同时检查您的Python版本)@Anwar,请投票/接受答案,让社区了解哪种语言的有用性?在nodejs上?看起来您正在使用Python,请检查此链接,该链接可能会对您有所帮助(同时检查您的Python版本)@Anwar,请投票/接受答案,让社区了解有用性