bigquery-emulator icon indicating copy to clipboard operation
bigquery-emulator copied to clipboard

Deleting a dataset dont seem to remove tables

Open sbv-csis opened this issue 2 years ago • 1 comments

It seems like deleting a dataset doesnt "cascade" to a tables:

$ bq --api http://127.0.0.1:9050 --project_id=test-project-bla mk test-dataset-bla                   
Dataset 'test-project-bla:test-dataset-bla' successfully created.
$ bq --api http://127.0.0.1:9050 --project_id=test-project-bla mk test-dataset-bla.t1                  
Table 'test-project-bla:test-dataset-bla.t1' successfully created.
$ bq --api http://127.0.0.1:9050 --project_id=test-project-bla rm test-dataset-bla
rm: remove dataset 'test-project-bla:test-dataset-bla'? (y/N) y
$ bq --api http://127.0.0.1:9050 --project_id=test-project-bla mk test-dataset-bla                   
Dataset 'test-project-bla:test-dataset-bla' successfully created.
$ bq --api http://127.0.0.1:9050 --project_id=test-project-bla mk test-dataset-bla.t1
BigQuery error in mk operation: failed to exec INSERT INTO `tables` (`id`,`projectID`,`datasetID`,`metadata`) VALUES
(@id,@projectid,@datasetid,@metadata): UNIQUE constraint failed: tables.projectID, tables.datasetID, tables.id
If the error provided does not help solve your issue, please run the command again with the `--apilog=stderr flag`.

I briefly mentioned this in a comment on #160

sbv-csis avatar Mar 07 '23 21:03 sbv-csis

The bug here is actually that the dataset is removed when it still contains tables. As noted in datasets.delete a dataset cannot be deleted until it does not contain any tables.

If you were to run the following, then the tables in the dataset would also be deleted.

 bq --api http://127.0.0.1:9050 --project_id=test-project-bla rm  -r test-dataset-bla

ohaibbq avatar Apr 14 '24 17:04 ohaibbq