sijocherian / google-bigquery

Automatically exported from code.google.com/p/google-bigquery
0 stars 0 forks source link

404 thrown when trying to do tabledata().insertAll() to existing table #241

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This can be reproduced using both BQ java library and also API explorer 
(https://developers.google.com/apis-explorer/#p/bigquery/v2)

What steps will reproduce the problem?
1. Try to insert some data (with tabledata().insertAll()) into non-existing 
table. You'll get 404 as expected.
2. Create a table using tables().insert(). You'll get 200 response as expected. 
The table exists - you can see it in BQ UI for example.
3. Try to insert some data to the table you've just created. You'll get 404 
response.

Here's code in java to reproduce the issue:
        // the situation is like this:
        // * dataset exists
        // * table does not exist

        // prepare insert all request
        Map<String, Object> jsonData = new HashMap<>();
        jsonData.put("a", "b");

        TableDataInsertAllRequest.Rows r = new TableDataInsertAllRequest.Rows();
        r.setInsertId("123");
        r.setJson(jsonData);
        TableDataInsertAllRequest content =
                new TableDataInsertAllRequest().setRows(Arrays.asList(r));
        Bigquery.Tabledata.InsertAll insertAllRequest = bigquery.tabledata().insertAll(projectId, datasetId, tableId, content);

        // now, try to do the load to the non-existing table
        try {
            insertAllRequest.execute();
        } catch (Exception e) {
            // this gives 404 as expected
        }

        // prepare table insert request
        List<TableFieldSchema> tableFieldSchema = newArrayList();
        tableFieldSchema.add(new TableFieldSchema().setName("a").setType("STRING"));
        Table table = new Table().setTableReference(new TableReference().setTableId(tableId).setDatasetId(datasetId)
                .setProjectId(projectId)).
                setSchema(new TableSchema().setFields(tableFieldSchema));

        Bigquery.Tables.Insert tableInsertRequest = bigquery.tables().insert(projectId, datasetId, table);

        //create table
        tableInsertRequest.execute();

        // try to load to the table now - gives 404!
        insertAllRequest.execute();

This problem occurs only when you try to insert data immediately after you've 
created it. If you wait for a while (around minute or so) then you will be able 
to do insert normally.

Original issue reported on code.google.com by p.pastus...@ocado.com on 24 Apr 2015 at 12:27

GoogleCodeExporter commented 9 years ago
I should probably add, that when you do just:
* create new table
* insert data into table

(so without first step with trying to load data to non-existing table), then 
everything works fine.

Original comment by p.pastus...@ocado.com on 28 Apr 2015 at 7:30

GoogleCodeExporter commented 9 years ago
This is a similar problem to the schema update problem. See suggestions and 
workarounds there.

Original comment by jcon...@google.com on 23 Jun 2015 at 11:47