Reputation: 2281
I suffering the same problem on the link BigQuery [PHP] InsertAll Error: No records present in table data append request. I followed the solution, error was removed but result is not affected on the BigQuery table my code is:
$data = '{"rows":[{"json":{"userId":"GR-003","state":"Pune","sales":"350"}}]}';
$data1 = json_decode($data);
try{
$rows = array();
$row = new Google_Service_Bigquery_TableDataInsertAllRequestRows;
$row->setJson($data1);
$row->setInsertId('9');
$rows[0] = $row;
$request = new Google_Service_Bigquery_TableDataInsertAllRequest;
$request->setKind('bigquery#tableDataInsertAllRequest');
$request->setRows($rows);
$service->tabledata->insertAll(PROJECT_ID, DATASET_ID , 'sample_table', $request);
} catch (Exception $e)
{
echo $e->getMessage();
}
Upvotes: 2
Views: 1057
Reputation: 207982
You are sending the wrong object to big query. Change the $data
to an object, and make sure you don't have rows
and json
level, also make sure variable type
is correct as BigQuery is very strict, like string
, string
, integer
or float
if you have it.
$rows = array();
foreach() {
$obj = new StdClass();
$obj->userId='GR-003';
$obj->state='Pune';
$obj->sales=350;
$row = new Google_Service_Bigquery_TableDataInsertAllRequestRows;
$row->setJson($obj);
$row->setInsertId('9');
$rows[] = $row;
}
Upvotes: 2