解决错误:返回“输出字段用作输入”

时间:2015-06-21 18:47:58

标签: google-bigquery

我正在尝试使用Python创建一个BigQuery表。其他操作(查询,检索表体等)工作正常,但在尝试创建表时我遇到了错误:

  

apiclient.errors.HttpError:https://www.googleapis.com/bigquery/v2/projects/marechal-consolidation/datasets/marechal_results/tables ?alt = json   返回“输出字段用作输入”>

这是我正在执行的命令:

projectId = 'xxxx'
dataSet = 'marechal_results'
with open(filePath+'tableStructure.json') as data_file:
    structure = json.load(data_file)
table_result = tables.insert(projectId=projectId, datasetId=dataSet, body=structure).execute()

JSON表:

{
  "kind": "bigquery#table",

  "tableReference": {
    "projectId": "xxxx",
    "tableId": "xxxx",
    "datasetId": "xxxx"
  },

  "type": "table",
  "schema": {
    "fields": [
      {
        "mode": "REQUIRED",
        "type": "STRING",
        "description": "Company",
        "name": "COMPANY"
      },
      {
        "mode": "REQUIRED",
        "type": "STRING",
        "description": "Currency",
        "name": "CURRENCY"
      }
// bunch of other fields follow...
    ]
  }
}

为什么我收到此错误?

编辑:这是我作为参数传递的JSON对象:

{
  "kind": "bigquery#table",
  "type": "TABLE",
  "tableReference": {
    "projectId": "xxxx",
    "tableId": "xxxx",
    "datasetId": "xxxx"
  },    
  "schema": {
    "fields": [
      {
        "type": "STRING",
        "name": "COMPANY"
      },
      {
        "type": "STRING",
        "name": "YEAR"
  },
  {
    "type": "STRING",
    "name": "COUNTRY_ISO"
  },
  {
    "type": "STRING",
    "name": "COUNTRY"
  },
  {
    "type": "STRING",
    "name": "COUNTRY_GROUP"
  },
  {
    "type": "STRING",
    "name": "REGION"
  },
  {
    "type": "STRING",
    "name": "AREA"
  },
  {
    "type": "STRING",
    "name": "BU"
  },
  {
    "type": "STRING",
    "name": "REFERENCE"
  },
  {
    "type": "FLOAT",
    "name": "QUANTITY"
  },
  {
    "type": "FLOAT",
    "name": "NET_SALES"
  },
  {
    "type": "FLOAT",
    "name": "GROSS_SALES"
  },
  {
    "type": "STRING",
    "name": "FAM_GRP"
  },
  {
    "type": "STRING",
    "name": "FAMILY"
  },
  {
    "type": "STRING",
    "name": "PRESENTATION"
  },
  {
    "type": "STRING",
    "name": "ORIG_FAMILY"
      },
      {
        "type": "FLOAT",
        "name": "REF_PRICE"
      },
      {
        "type": "STRING",
        "name": "CODE1"
      },
      {
        "type": "STRING",
        "name": "CODE4"
      }
    ]
  }
}

1 个答案:

答案 0 :(得分:2)

这可能为时已晚,无法帮助您,但希望它可以帮助下一个像我这样的可怜的灵魂。我花了一段时间才弄清楚“输出字段用作输入”的含义。

尽管API为请求(输入)和响应(输出)指定了相同的对象,但是某些字段仅允许在响应中使用。在文档中,您将看到其描述以“仅输出”为前缀。通过查看表定义,我看到您具有"type": "TABLE",并且“类型”被列为“仅输出”属性。因此,我想知道,如果删除它,该错误将消失。这是文档的链接:https://cloud.google.com/bigquery/docs/reference/rest/v2/tables

如果他们告诉您违规行为在哪个领域,将会有所帮助。