Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery: Table name missing dataset while no default dataset is set in the request

Here is the issue with a BigQuery query. I know this query is missing a dataset name, so the error "Table name "my_table" missing dataset while no default dataset is set in the request."

select * from my_table;

Changing 'my_tabale' to 'my_dataset.my_table' will fix the issue. But can somebody help me with setting a default dataset. The error message clearly giving an indication that BigQuery has such an option.

like image 997
Prince Avatar asked Jan 04 '21 04:01

Prince


People also ask

Can we rename dataset in BigQuery?

Renaming datasets Currently, you cannot change the name of an existing dataset, but you can copy a dataset.

Is table name case sensitive in BigQuery?

Google BigQuery is not case sensitive, so all names default to lowercase.

What are the limitations of BigQuery datasets?

BigQuery datasets are subject to the following limitations: You can set the geographic location at creation time only. All tables referenced in a query must be stored in datasets in the same location. When copying a table, the datasets containing the source table and destination table must reside in the same location.

How to fix my_table missing dataset while no default dataset is set?

Here is the issue with a BigQuery query. I know this query is missing a dataset name, so the error "Table name "my_table" missing dataset while no default dataset is set in the request." Changing 'my_tabale' to 'my_dataset.my_table' will fix the issue.

How do I change the default table expiration in BigQuery?

Note: If your project is not associated with a billing account, BigQuery automatically sets the default table expiration for datasets that you create in the project. You can specify a shorter default table expiration for a dataset, but you can't specify a longer default table expiration. Click Create dataset.

Can I change the location of my BigQuery dataset?

After a dataset is created, the location can't be changed. Note: If you choose EU or an EU-based region for the dataset location, your Core BigQuery Customer Data resides in the EU. Core BigQuery Customer Data is defined in the Service Specific Terms.


2 Answers

Depending on which API you are using, you can specify the defaultDataset parameter when running your BigQuery job. More information for the jobs.query api can be found here https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query.

For example, using the NodeJS API for createQueryJob https://googleapis.dev/nodejs/bigquery/latest/BigQuery.html#createQueryJob, you can do something similar to this:

const options = {
  keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
  projectId: process.env.GOOGLE_APPLICATION_PROJECT_ID,
  defaultDataset: {
    datasetId: process.env.BIGQUERY_DATASET_ID,
    projectId: process.env.GOOGLE_APPLICATION_PROJECT_ID
  },
  query: `select * from my_table;`
}

const [job] = await bigquery.createQueryJob(options);
let [rows] = await job.getQueryResults();

like image 90
bitnahian Avatar answered Oct 21 '22 06:10

bitnahian


The short answer is: SET @@dataset_id = 'whatever';

But, this is a scripting command, so you will have to enclose your SQL query in a BEGIN ... END block. Note the semicolon. Scripting gives you some added flexibility. On the other hand, it prevents the console from doing that fun thing where it estimates the processing cost.

like image 40
Mark Avatar answered Oct 21 '22 08:10

Mark