Why do we need to construct a dataset reference in bigquery?

Viewed 405

I am learning bigquery with python notebook, and I found out the very first lines of code as follows:

from google.cloud import bigquery
client = bigquery.Client()
hn_dataset_ref = client.dataset('hacker_news', project='bigquery-public-data')
hn_dset = client.get_dataset(hn_dataset_ref)

My question is why do we need to construct a dataset reference?

Can we do in a shorter way like below?

from google.cloud import bigquery
client = bigquery.Client()
hn_dset = client.get_dataset('bigquery-public-data.hacker_news')`
1 Answers

Yes, you can do it in the shorter way. When you use a string, the method will actually create a DatasetReference.

The long method was the old way to do it, and it is actually deprecated, so it is no longer recommended its use.

Related