0
votes

I just have some trouble with the example for creating a table using the BigQuery API: https://developers.google.com/bigquery/docs/developers_guide#creatingatable

Everything before worked just fine but here I always receive a parsing exception... Below the body sent in the request (I actually modified the example to the data and schema of the next example in the tutorial, but had the same issue with the original schema + self generated dataset) and the error response.

When I upload the same dataset using the webinterface and same schema it works like a charm.....

Thanks for any helpful clue!

Joerg



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

    {
       "configuration": {
         "load": {
         "schema": { 
         "fields": [ 
                    { 
                    "name": "Name", 
                    "type": "STRING",
                   "mode": "REQUIRED",
                    },
                    {
                    "name": "Age",
                    "type": "INTEGER",
                    "mode": "REQUIRED",
                    },
                    {
                    "name": "Weight",
                    "type": "FLOAT",
                    "mode": "REQUIRED",
                    },
                    {
                    "name": "IsMagic",
                    "type": "BOOLEAN",
                    "mode": "REQUIRED",
                    }
                    ]
         },
          "destinationTable": {
            "projectId": "536201353583",
            "datasetId": "Benchmark",
            "tableId": "syntest2"
          }
    "writeDisposition": "WRITE_APPEND"    }
      }
    }
    --xxx
    Content-Type: application/octet-stream

    "Shooting Star",15,325.5,true
    "Magic Muffin",12,411.5,true
    "Blaze",16,312.2,false
    "Old Red",22,388.2,false
    --xxx--



    {'status': '400', 'content-length': '171', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'server': 'HTTP Upload Server Built on Apr 30 2012 12:11:36 (1335813096)', 'pragma': 'no-cache', 'cache-control': 'no-cache, no-store, must-revalidate', 'date': 'Thu, 03 May 2012 19:40:00 GMT', 'content-type': 'application/json'}

    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "parseError",
        "message": "Parse Error"
       }
      ],
      "code": 400,
      "message": "Parse Error"
     }
    }

2
I suggest you use the BigQuery Client API provided by Google instead of parsing raw HTTP request/response, this is the one for python (others in the link other below): developers.google.com/resources/api-libraries/documentation/… According to Google, it has improved security and better language integration: developers.google.com/bigquery/client-librariesiBrAaAa

2 Answers

2
votes

The parse error you're seeing refers to your JSON request, not the CSV data.

In addition to the parse error noted by Jordan (missing comma after destinationTable), you also have trailing commas in the objects defining the table schema, which is invalid JSON. Try removing them and see if that helps!

1
votes

It looks like you're missing a comma between the end brace of destinationTable and the writeDisposition specifier.