流导入Big Query时请求中不存在任何行

时间:2015-04-16 00:36:48

标签: streaming google-bigquery google-api-ruby-client

我尝试使用tabledata.insert_all

将数据导入大查询
job_data = {
  kind: 'bigquery#tableDataInsertAllRequest',
  rows: [
    { json: { column_name: value} }
  ]
}

response = execute(
  api_method: bigquery.tabledata.insert_all,
  parameters: {
    projectId: config['project_id'],
    datasetId: DATASET_ID,
    tableId: table_id
  },
  body_object: job_data
)

但我总是收到以下错误消息

Google::APIClient::Request Sending API request post https://www.googleapis.com/bigquery/v2/projects/propane-tribute-90023/datasets/development/tables/api_requests_20150414/insertAll {"User-Agent"=>"My Test App/1.0 google-api-ruby-client/0.8.5 Mac OS X/10.9.5\n (gzip)", "Content-Type"=>"application/json", "Accept-Encoding"=>"gzip", "Authorization"=>"Bearer ya29.VgFYvU2nxGDhWiCdS47XRw0J-7GLenRry0Cd3AA2D1RDzMh5gnf-m85I5GeSr9oNW51OuUb9mdwObg", "Cache-Control"=>"no-store"}

Decompressing gzip encoded response (155 bytes)
Decompressed (261 bytes)
Google::APIClient::Request Result: 400 {"Vary"=>"X-Origin", "Content-Type"=>"application/json; charset=UTF-8", "Date"=>"Wed, 15 Apr 2015 03:14:17 GMT", "Expires"=>"Wed, 15 Apr 2015 03:14:17 GMT", "Cache-Control"=>"private, max-age=0", "X-Content-Type-Options"=>"nosniff", "X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "Server"=>"GSE", "Alternate-Protocol"=>"443:quic,p=0.5", "Transfer-Encoding"=>"chunked"} => {"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"invalid", "message"=>"No rows present in the request.", "locationType"=>"other", "location"=>"rows"}], "code"=>400, "message"=>"No rows present in the request."}}

有没有人有相同的问题,知道如何解决它?

感谢。

1 个答案:

答案 0 :(得分:0)

确保为表格架构中的所有列标题提供适当的值。提供单独的“json”条目将使用您提供的列数据填充单个行。除非您已经为名为column_name和value的变量赋值,否则需要在json声明后面的语句中提供这些值。

tabledata.insert_all“rows”操作的示例Ruby语法如下所示:

body = {
   "rows" =>[ 
      {"json" => { "person_id" => 10, "person_name" => "test"}}, 
      {"json" => { "person_id" => 11, "person_name" => "test2"}} 
   ]
}