BigQuery Invalid Dataset ID in Cloud Shell
While querying from the google cloud shell, and try to access the dataset and table through python
\n\nfrom google.cloud import bigquery\n\nclient = bigquery.Client()\ndataset_id = 'mytest-0001:reports_test'\ntable_id = 'test_data'\ndataset_ref = client.dataset(dataset_id)\ndataset = client.get_dataset(dataset_ref)\ntable_ref = dataset_ref.table(table_id)\ntable = client.get_table(table_ref)\nprint('Dataset ID: '.format(dataset_id))\nprint('Description: '.format(dataset.description))\nprint(table.schema)\nprint(table.description)\nprint(table.num_rows)\n
It throws the below error:
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\n 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?
Solution:
Make sure you pass,
- The Project name while initializing the client
- And specify the dataset id without the project prefix
The code will be:
from google.cloud import bigquery\n\nclient = bigquery.Client(project='mytest-0001')\ndataset_id = 'reports_test'\n
Atori
posted onEnjoy great content like this and a lot more !
Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds
Post Comment