0

实例化 HttpWebRequest 并设置属性值:-

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://www.googleapis.com/upload/bigquery/v2/projects/776934660156/jobs");
    request.Method = "POST";
    request.ContentType = "multipart/related; boundary=xxx";
    request.Headers.Add("Authorization: Bearer " + strAccessToken);//Service Account Access token

下面是 HttpWebRequest 对象的内容。当我通过此请求时,我收到错误 400 错误请求:-

--xxx
Content-Type: application/json; charset=UTF-8
{
"kind" : "bigquery#job" ,
"Id" : "testJob" ,
"configuration": {
"load": {
"destinationTable": {
"projectId": "776934660156",
"datasetId": "BMSTestDataset",
"tableId": "tblEvents"
},
"fieldDelimiter":"|", 
}
}
}
--xxx
Content-Type: application/octet-stream
ET00000102|MT|50|Hindi|Halla Bol|2008-01-11 00:00:00|0|2007-08-07 15:51:38.240000000|<Genre><code>DRAMA</code></Genre>|<Legends><Actor>83</Actor><Actor>2457</Actor><Actor>1639</Actor><Actor>1151</Actor><Actor>1717</Actor><Actor>1526</Actor><Director>1801</Director><Music>820</Music></Legends>
ET00000103|MT|50|Hindi|Kisse Pyaar Karoon|2009-02-27 00:00:00|0|2007-08-07 17:16:36.443000000|<Genre><code>DRAMA</code></Genre>|<Legends><Actor>228</Actor><Actor>46</Actor><Actor>2539</Actor><Actor>2415</Actor><Actor>44</Actor><Actor>2161</Actor><Actor>2100</Actor><Director>82</Director><Music>2624</Music></Legends>
--xxx--

我没有指定架构,因为该表已经存在于 BQ 数据集中。请帮帮我,我做了很多研究,但没有得到任何解决方案。

谢谢

4

1 回答 1

1

一些东西:

首先,BigQuery 加载配置应如下所示(注意 Content-type 标头后的换行符:

--xxx
Content-Type: application/json; charset=UTF-8

{
  'configuration': {
    'load': {
      // Schema, only if necessary
      'schema': {
        'fields': [
          {'name':'f1', 'type':'STRING'},
          {'name':'f2', 'type':'INTEGER'}
        ]
      },
      'destinationTable': {
        'projectId': 'projectId',
        'datasetId': 'datasetId',
        'tableId': 'tableId'
      }
    }
  }
}
--xxx

此外,如果您想设置作业 ID,请使用 jobReference.jobId 参数(请参阅 BigQuery API加载配置文档)。例子:

"jobReference": {
    "jobId": 'SOMESTRINGHERE'
}

PS我认为使用随机边界字符串是一种很好的做法,例如:

var boundary = "------------------------" + DateTime.Now.Ticks;
于 2012-11-20T19:56:52.587 回答