Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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')`
like image 504
ipramusinto Avatar asked Sep 17 '25 05:09

ipramusinto


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.

like image 90
Tlaquetzal Avatar answered Sep 19 '25 17:09

Tlaquetzal