|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -package com.google.cloud.examples.bigquery.cloudsnippets; |
| 17 | +package com.google.cloud.examples.bigquery.snippets; |
18 | 18 |
|
19 | 19 | import com.google.cloud.bigquery.BigQuery; |
20 | 20 | import com.google.cloud.bigquery.FieldValue; |
21 | 21 | import com.google.cloud.bigquery.FieldValueList; |
| 22 | +import com.google.cloud.bigquery.FormatOptions; |
| 23 | +import com.google.cloud.bigquery.Job; |
| 24 | +import com.google.cloud.bigquery.JobInfo; |
| 25 | +import com.google.cloud.bigquery.LoadJobConfiguration; |
22 | 26 | import com.google.cloud.bigquery.QueryJobConfiguration; |
23 | 27 | import com.google.cloud.bigquery.QueryParameterValue; |
| 28 | +import com.google.cloud.bigquery.StandardTableDefinition; |
24 | 29 | import com.google.cloud.bigquery.TableId; |
25 | 30 | import java.util.concurrent.TimeoutException; |
26 | 31 | import org.joda.time.DateTime; |
@@ -283,4 +288,25 @@ public void runQueryWithTimestampParameters() throws InterruptedException { |
283 | 288 | } |
284 | 289 | // [END bigquery_query_params_timestamps] |
285 | 290 | } |
| 291 | + |
| 292 | + /** |
| 293 | + * Example of loading a parquet file from GCS to a table. |
| 294 | + */ |
| 295 | + public void loadTableGcsParquet(String datasetName) throws InterruptedException { |
| 296 | + // [START bigquery_load_table_gcs_parquet] |
| 297 | + String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.parquet"; |
| 298 | + TableId tableId = TableId.of(datasetName, "us_states"); |
| 299 | + LoadJobConfiguration configuration = |
| 300 | + LoadJobConfiguration.builder(tableId, sourceUri) |
| 301 | + .setFormatOptions(FormatOptions.parquet()) |
| 302 | + .build(); |
| 303 | + // Load the table |
| 304 | + Job loadJob = bigquery.create(JobInfo.of(configuration)); |
| 305 | + loadJob = loadJob.waitFor(); |
| 306 | + // Check the table |
| 307 | + StandardTableDefinition destinationTable = bigquery.getTable(tableId).getDefinition(); |
| 308 | + System.out.println("State: " + loadJob.getStatus().getState()); |
| 309 | + System.out.printf("Loaded %d rows.\n", destinationTable.getNumRows()); |
| 310 | + // [END bigquery_load_table_gcs_parquet] |
| 311 | + } |
286 | 312 | } |
0 commit comments