我在链接BigQuery [PHP] InsertAll Error: No records present in table data append request上遇到了同样的问题。我按照解决方案,错误被删除但结果不会影响BigQuery表我的代码是:
$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();
}
答案 0 :(得分:2)
您正在向大查询发送错误的对象。将$data
更改为对象,并确保您没有rows
和json
级别,同时确保变量type
正确,因为BigQuery非常严格,如果有string
,string
,integer
或float
,则可以使用此作品。
$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;
}