Programmer
Programmer

Reputation: 325

How to instantiate com.google.cloud.bigquery.Table

I want to process csv file present in cloud bucket and insert its data in a BQ table. I found following piece of code but I am not sure how I can instantiate com.google.cloud.bigquery.Table for a given table name

    com.google.cloud.bigquery.Table table = null;
    com.google.cloud.bigquery.Job job = table.load(FormatOptions.csv(), sourceUri);
        com.google.cloud.bigquery.Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
          WaitForOption.timeout(3, TimeUnit.MINUTES));
      if (!(completedJob != null && completedJob.getStatus().getError() == null)) {
          throw new InterruptedException("Unable to load file from bucket into BQ");
      } 
    return job;

Upvotes: 0

Views: 127

Answers (1)

Graham Polley
Graham Polley

Reputation: 14781

Snippet taken from here.

[imports]

BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
TableId tableId = TableId.of("dataset", "table");
Table table = bigquery.getTable(tableId);

[..]

Side note - that is an Alpha client library you are using. Just so you know.

Upvotes: 1

Related Questions