A simple usage example showing how to create a table if it does not exist and load data into - * it. For the complete source code see - * CreateTableAndLoadData.java. + *
A simple usage example showing how to create a table in Bigquery. For the complete source code see + * CreateTable.java. * *
{@code - * BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); - * TableId tableId = TableId.of("dataset", "table"); - * Table table = bigquery.getTable(tableId); - * if (table == null) { - * System.out.println("Creating table " + tableId); - * Field integerField = Field.of("fieldName", Field.Type.integer()); - * Schema schema = Schema.of(integerField); - * table = bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema))); - * } - * System.out.println("Loading data into table " + tableId); - * Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path"); - * loadJob = loadJob.waitFor(); - * if (loadJob.getStatus().getError() != null) { - * System.out.println("Job completed with errors"); - * } else { - * System.out.println("Job succeeded"); - * } - * }+ * try { + * // Initialize client that will be used to send requests. This client only needs to be created + * // once, and can be reused for multiple requests. + * BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); + * + * TableId tableId = TableId.of(datasetName, tableName); + * TableDefinition tableDefinition = StandardTableDefinition.of(schema); + * TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build(); + * + * bigquery.create(tableInfo); + * System.out.println("Table created successfully"); + * } catch (BigQueryException e) { + * System.out.println("Table was not created. \n" + e.toString()); + * } + * * * @see Google Cloud BigQuery */ diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java index 6e5b32419..c2e6c03f5 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/testing/package-info.java @@ -17,7 +17,14 @@ /** * A testing helper for Google BigQuery. * - *
A simple usage example: + *
A simple usage example: 1. Create a test Google Cloud project. + * + *
2. Download a JSON service account credentials file from the Google Developer's Console. + * + *
3. Create a RemoteBigQueryHelper object using your project ID and JSON key. Here is an example + * that uses the RemoteBigQueryHelper to create a dataset. + * + *
4. Run tests. * *
Before the test: * @@ -33,9 +40,5 @@ *
{@code * RemoteBigQueryHelper.forceDelete(bigquery, DATASET); * }- * - * @see - * Google Cloud Java tools for testing */ package com.google.cloud.bigquery.testing; From 93e358afe38c90b7bbe20d2756aec204fdeb28eb Mon Sep 17 00:00:00 2001 From: Mend Renovate