Skip to content

BigQuery listTables(DatasetId) does not use project overrided in DatasetId #1123

@tswast

Description

@tswast

My Google Application Default Credentials are set to the swast-scratch project, but I wish to list the tables in the publicdata project's samples dataset. This is a public dataset.

$ bq ls publicdata:samples
      tableId       Type
 ----------------- -------
  github_nested     TABLE
  github_timeline   TABLE
  gsod              TABLE
  natality          TABLE
  shakespeare       TABLE
  trigrams          TABLE
  wikipedia         TABLE

Example code that displays this issue:

import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.DatasetId;
import com.google.cloud.bigquery.Table;
import java.io.PrintWriter;
import java.util.Iterator;

public class TableLister {
  public static void listTables(PrintWriter out) {
    BigQuery bigquery = BigQueryOptions.defaultInstance().service();
    Iterator<Table> tables = bigquery.listTables(DatasetId.of("publicdata", "samples")).iterateAll();
    while (tables.hasNext()) {
      out.println(tables.next());
    }
  }

  public static void main(String[] args) {
    listTables(new PrintWriter(System.out));
  }
}

It fails with the error: "message" : "Not found: Dataset swast-scratch:samples", so it appears that it is not using the project that I set in the DatasetId.

http://googlecloudplatform.github.io/gcloud-java/0.2.5/apidocs/com/google/cloud/bigquery/DatasetId.html#of-java.lang.String-java.lang.String-

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions