Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery Invalid dataset ID


I used to query in UI
This time, I'm in cloud shell, and try to access my dataset and table through python

from google.cloud import bigquery

client = bigquery.Client()
dataset_id = 'mytest-0001:reports_test'
table_id = 'test_data'
dataset_ref = client.dataset(dataset_id)
dataset = client.get_dataset(dataset_ref)
table_ref = dataset_ref.table(table_id)
table = client.get_table(table_ref)
print('Dataset ID: '.format(dataset_id))
print('Description: '.format(dataset.description))
print(table.schema)
print(table.description)
print(table.num_rows)

I got some the error below...

google.api_core.exceptions.BadRequest: 400 GET https://www.googleapis.com/bigquery/v2/projects/gcd-my-reporting/datasets/mytest-0001:reports_test: Invalid dataset ID "mytest-0001:reports_test". Dataset IDs must be al phanumeric (plus underscores, dashes, and colons) and must be at most 1024 characters long.

With some reason I can't modified the dataset id, Any idea to fixed this?

like image 252
Edwin Lai Avatar asked Sep 03 '26 05:09

Edwin Lai


1 Answers

You don't have to modify dataset id, just specify the dataset id without project id. If you want to specify project for any reason, you must to do it when define client as explained in this document.

The code will be:

from google.cloud import bigquery

client = bigquery.Client(project='mytest-0001')
dataset_id = 'reports_test'
like image 179
enle lin Avatar answered Sep 04 '26 18:09

enle lin