return extract(format, ImmutableList.of(destinationUri), options);
/** Example of partitioning data to a list of Google Cloud Storage files. */ // [TARGET extract(String, List, JobOption...)] // [VARIABLE "CSV"] // [VARIABLE "gs://my_bucket/PartitionA_*.csv"] // [VARIABLE "gs://my_bucket/PartitionB_*.csv"] public Job extractList(String format, String gcsUrl1, String gcsUrl2) { // [START ] List<String> destinationUris = new ArrayList<>(); destinationUris.add(gcsUrl1); destinationUris.add(gcsUrl2); Job job = table.extract(format, destinationUris); // Wait for the job to complete try { Job completedJob = job.waitFor( RetryOption.initialRetryDelay(Duration.ofSeconds(1)), RetryOption.totalTimeout(Duration.ofMinutes(3))); if (completedJob != null && completedJob.getStatus().getError() == null) { // Job completed successfully } else { // Handle error case } } catch (InterruptedException e) { // Handle interrupted wait } // [END ] return job; }
@Test public void testExtractDataUris() throws Exception { initializeExpectedTable(2); expect(bigquery.getOptions()).andReturn(mockOptions); Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); expect(bigquery.create(EXTRACT_JOB_INFO)).andReturn(expectedJob); replay(bigquery); initializeTable(); Job job = table.extract("CSV", ImmutableList.of("URI")); assertSame(expectedJob, job); }
@Test public void testExtractDataUri() throws Exception { initializeExpectedTable(2); expect(bigquery.getOptions()).andReturn(mockOptions); Job expectedJob = new Job(serviceMockReturnsOptions, new JobInfo.BuilderImpl(EXTRACT_JOB_INFO)); expect(bigquery.create(EXTRACT_JOB_INFO)).andReturn(expectedJob); replay(bigquery); initializeTable(); Job job = table.extract("CSV", "URI"); assertSame(expectedJob, job); }
/** Example extracting data to single Google Cloud Storage file. */ // [TARGET extract(String, String, JobOption...)] // [VARIABLE "CSV"] // [VARIABLE "gs://my_bucket/filename.csv"] public Job extractSingle(String format, String gcsUrl) { // [START bigquery_extract_table] Job job = table.extract(format, gcsUrl); // Wait for the job to complete try { Job completedJob = job.waitFor( RetryOption.initialRetryDelay(Duration.ofSeconds(1)), RetryOption.totalTimeout(Duration.ofMinutes(3))); if (completedJob != null && completedJob.getStatus().getError() == null) { // Job completed successfully } else { // Handle error case } } catch (InterruptedException e) { // Handle interrupted wait } // [END bigquery_extract_table] return job; }
/** * Starts a BigQuery Job to extract the current table to the provided destination URI. Returns the * started {@link Job} object. * * @param format the format of the extracted data * @param destinationUri the fully-qualified Google Cloud Storage URI (e.g. gs://bucket/path) * where the extracted table should be written * @param options job options * @throws BigQueryException upon failure */ public Job extract(String format, String destinationUri, BigQuery.JobOption... options) throws BigQueryException { return extract(format, ImmutableList.of(destinationUri), options); }
return extract(format, ImmutableList.of(destinationUri), options);