1

I was trying to stream import data into big query using 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
)

But I always get the following error message

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."}}

Does anyone have the same the issue and know how to fix it?

Thanks.

4

1 回答 1

0

Make sure you are providing appropriate values for all of the column headers present in your table’s schema. Providing separate “json” entries will populate individual rows with the column data you provide. Unless you have already assigned values to the variables named column_name and value, you need to provide those values in the statement following the json declaration.

A sample Ruby syntax for a tabledata.insert_all “rows” operation would look as follows:

body = {
   "rows" =>[ 
      {"json" => { "person_id" => 10, "person_name" => "test"}}, 
      {"json" => { "person_id" => 11, "person_name" => "test2"}} 
   ]
}
于 2015-04-24T19:05:25.507 回答