1
votes

I'm trying to insert a row using this example code:

https://developers.google.com/bigquery/streaming-data-into-bigquery#streaminginsertexamples

I'm receiving an error:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid table ID \"projectid:datasetid.tableid\".",
    "reason" : "invalid"
  } ],
  "message" : "Invalid table ID \"projectid:datasetid.tableid\"."
}

The project, dataset and table all exist. When I copy the actual projectid:datasetid.tableid from the error report and paste it into the BigQuery web UI, it works. The projectid has a '-' in it, the rest is alphanumeric. Why would the API complain about an id that the web UI accepts?


Update to answer Jordan's question. This is my call:

TableDataInsertAllResponse response =
    bigquery
    .tabledata()
    .insertAll(projectId, datasetId, table.getId(), content)
    .execute();

Before I call this, I ensure the project, dataset and table all exist by getting them. I then use the table's actual id.


New information: turns out (as you suspected) the table.getId() returns the fully qualified id, including project and dataset. When I hardcode the shortened id to exclude them, it worked.

1
It sounds like you're sending a single name as the table name rather than splitting it up into components. If that isn't the case, can you send the actual code you are calling?Jordan Tigani
Hi Jordan. Updated. (Btw, thanks for the effort you guys put into SO.)Richard Watson

1 Answers

6
votes

Aha... ok this is expected. The table.getId() call is going to return the fully-qualified name of the table (i.e. project:dataset.table). (see https://developers.google.com/bigquery/docs/reference/v2/tables).

Try table.getTableReference().getTableId() instead. (see https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/java/latest/com/google/api/services/bigquery/model/Table.html#getTableReference())

Why, you may ask? Every REST resource is supposed to have a unique id. The table's fully-qualified unique ID is the project:dataset.table name. However, when you are passing the components of the id, the table component is just the last part of that name.