public void exportBigQueryToGcs ( String projectId , TableReference tableRef , List < String > gcsPaths , boolean awaitCompletion ) throws IOException , InterruptedException { logger . atFine ( ) . log ( "exportBigQueryToGcs(bigquery, '%s', '%s', '%s', '%s')" , projectId , BigQueryStrings . toString ( tableRef ) , gcsPaths , awaitCompletion ) ; logger . atInfo ( ) . log ( "Exporting table '%s' to %s paths; path[0] is '%s'; awaitCompletion: %s" , BigQueryStrings . toString ( tableRef ) , gcsPaths . size ( ) , gcsPaths . isEmpty ( ) ? "(empty)" : gcsPaths . get ( 0 ) , awaitCompletion ) ; // Create job and configuration. JobConfigurationExtract extractConfig = new JobConfigurationExtract ( ) ; // Set source. extractConfig . setSourceTable ( tableRef ) ; // Set destination. extractConfig . setDestinationUris ( gcsPaths ) ; extractConfig . set ( "destinationFormat" , "NEWLINE_DELIMITED_JSON" ) ; JobConfiguration config = new JobConfiguration ( ) ; config . setExtract ( extractConfig ) ; // Get the table to determine the location Table table = getTable ( tableRef ) ; JobReference jobReference = createJobReference ( projectId , "direct-bigqueryhelper-export" , table . getLocation ( ) ) ; Job job = new Job ( ) ; job . setConfiguration ( config ) ; job . setJobReference ( jobReference ) ; // Insert and run job. insertJobOrFetchDuplicate ( projectId , job ) ; if ( awaitCompletion ) { // Poll until job is complete. BigQueryUtils . waitForJobCompletion ( service , projectId , jobReference , NOP_PROGRESSABLE ) ; } }
Exports BigQuery results into GCS polls for completion before returning .