From 44df38c1a79546fdac2ae93c6f746239efd012c6 Mon Sep 17 00:00:00 2001 From: happyhuman Date: Wed, 28 Feb 2018 10:45:37 -0800 Subject: [PATCH 1/8] Added a snippet to show how to read a newline-delimited-json file from GCS and store it in a BQ Table. --- .../bigquery/snippets/BigQuerySnippets.java | 36 +++++++++++++++++++ .../bigquery/snippets/ITBigQuerySnippets.java | 25 +++++++++++++ 2 files changed, 61 insertions(+) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index d6701804a6f9..81d24b526afa 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -25,6 +25,7 @@ import com.google.api.client.util.Charsets; import com.google.api.gax.paging.Page; import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.LoadJobConfiguration; import com.google.cloud.bigquery.TableResult; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQuery.DatasetListOption; @@ -63,6 +64,7 @@ import java.nio.channels.Channels; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -378,6 +380,40 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath) // [END writeFileToTable] } + /** + * Example of writing a newline-delimited-json file with textual fields from GCS to a table. + */ + // [TARGET writer(WriteChannelConfiguration)] + // [VARIABLE "my_dataset_name"] + // [VARIABLE "my_table_name"] + // [VARIABLE "my_source_uri")] + // [VARIABLE "field_names")] + public Long writeRemoteFileToTable(String datasetName, String tableName, String sourceUri, List fieldNames) + throws InterruptedException { + // [START bigquery_load_table_gcs_json] + TableId tableId = TableId.of(datasetName, tableName); + LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri) + .setFormatOptions(FormatOptions.json()) + .build(); + // Table field definition + ArrayList fields = new ArrayList<>(); + for (String fieldName: fieldNames) { + fields.add(Field.of(fieldName, LegacySQLTypeName.STRING)); + } + // Table schema definition + Schema schema = Schema.of(fields.toArray(new Field[fields.size()])); + // Create the table + StandardTableDefinition tableDefinition = StandardTableDefinition.of(schema); + bigquery.create(TableInfo.of(tableId, tableDefinition)); + // Load the table + Job remoteLoadJob = bigquery.create(JobInfo.of(configuration)); + remoteLoadJob = remoteLoadJob.waitFor(); + // Check the table + System.out.println("State: " + remoteLoadJob.getStatus().getState()); + return ((StandardTableDefinition) bigquery.getTable(tableId).getDefinition()).getNumRows(); + // [END bigquery_load_table_gcs_json] + } + /** * Example of inserting rows into a table without running a load job. */ diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java index d5c081f8368f..bb2eda3dc1f8 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import com.google.api.gax.paging.Page; @@ -48,7 +49,10 @@ import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; +import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -197,6 +201,27 @@ public void testWriteAndListTableData() assertTrue(bigquerySnippets.deleteTable(DATASET, tableName)); } + @Test + public void testWriteRemoteJsonToTable() throws InterruptedException { + String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; + String datasetName = "test_dataset"; + String tableName = "us_states"; + List fieldNames = Arrays.asList("name", "post_abbr"); + Table table = bigquery.getTable(datasetName, tableName); + assertNull(table); + + Long result = bigquerySnippets.writeRemoteFileToTable(datasetName, tableName, sourceUri, fieldNames); + table = bigquery.getTable(datasetName, tableName); + assertNotNull(table); + ArrayList tableFieldNames = new ArrayList<>(); + for (Field field: table.getDefinition().getSchema().getFields()) { + tableFieldNames.add(field.getName()); + } + assertArrayEquals(fieldNames.toArray(), tableFieldNames.toArray()); + bigquery.delete(table.getTableId()); + assertEquals(Long.valueOf(50), result); + } + @Test public void testInsertAllAndListTableData() throws IOException, InterruptedException { String tableName = "test_insert_all_and_list_table_data"; From 5d3e09b810c807fb3f6f0dec78e77c4218c65cd0 Mon Sep 17 00:00:00 2001 From: happyhuman Date: Mon, 5 Mar 2018 11:22:36 -0800 Subject: [PATCH 2/8] Made some changes based on the PR comments. --- .../bigquery/snippets/BigQuerySnippets.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index 81d24b526afa..ea6bfe789b67 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -25,6 +25,7 @@ import com.google.api.client.util.Charsets; import com.google.api.gax.paging.Page; import com.google.cloud.bigquery.BigQuery; +import com.google.cloud.bigquery.JobInfo.CreateDisposition; import com.google.cloud.bigquery.LoadJobConfiguration; import com.google.cloud.bigquery.TableResult; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; @@ -392,19 +393,18 @@ public Long writeRemoteFileToTable(String datasetName, String tableName, String throws InterruptedException { // [START bigquery_load_table_gcs_json] TableId tableId = TableId.of(datasetName, tableName); - LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri) - .setFormatOptions(FormatOptions.json()) - .build(); // Table field definition ArrayList fields = new ArrayList<>(); - for (String fieldName: fieldNames) { + for (String fieldName : fieldNames) { fields.add(Field.of(fieldName, LegacySQLTypeName.STRING)); } // Table schema definition - Schema schema = Schema.of(fields.toArray(new Field[fields.size()])); - // Create the table - StandardTableDefinition tableDefinition = StandardTableDefinition.of(schema); - bigquery.create(TableInfo.of(tableId, tableDefinition)); + Schema schema = Schema.of(fields); + LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri) + .setFormatOptions(FormatOptions.json()) + .setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED) + .setSchema(schema) + .build(); // Load the table Job remoteLoadJob = bigquery.create(JobInfo.of(configuration)); remoteLoadJob = remoteLoadJob.waitFor(); From b3904d23221af2df9d0fcfa3321c1ed568e2a9b8 Mon Sep 17 00:00:00 2001 From: happyhuman Date: Mon, 5 Mar 2018 15:38:57 -0800 Subject: [PATCH 3/8] Made some changes based on the PR comments. --- .../bigquery/snippets/BigQuerySnippets.java | 13 ++++++------- .../bigquery/snippets/ITBigQuerySnippets.java | 5 +---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index ea6bfe789b67..f6cb33d3e919 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -387,17 +387,16 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath) // [TARGET writer(WriteChannelConfiguration)] // [VARIABLE "my_dataset_name"] // [VARIABLE "my_table_name"] - // [VARIABLE "my_source_uri")] - // [VARIABLE "field_names")] - public Long writeRemoteFileToTable(String datasetName, String tableName, String sourceUri, List fieldNames) + public Long writeRemoteFileToTable(String datasetName, String tableName) throws InterruptedException { // [START bigquery_load_table_gcs_json] + String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; TableId tableId = TableId.of(datasetName, tableName); // Table field definition - ArrayList fields = new ArrayList<>(); - for (String fieldName : fieldNames) { - fields.add(Field.of(fieldName, LegacySQLTypeName.STRING)); - } + Field[] fields = new Field[] { + Field.of("name", LegacySQLTypeName.STRING), + Field.of("post_abbr", LegacySQLTypeName.STRING) + }; // Table schema definition Schema schema = Schema.of(fields); LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri) diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java index bb2eda3dc1f8..59ee70fc3a3f 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java @@ -203,21 +203,18 @@ public void testWriteAndListTableData() @Test public void testWriteRemoteJsonToTable() throws InterruptedException { - String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json"; String datasetName = "test_dataset"; String tableName = "us_states"; - List fieldNames = Arrays.asList("name", "post_abbr"); Table table = bigquery.getTable(datasetName, tableName); assertNull(table); - Long result = bigquerySnippets.writeRemoteFileToTable(datasetName, tableName, sourceUri, fieldNames); + Long result = bigquerySnippets.writeRemoteFileToTable(datasetName, tableName); table = bigquery.getTable(datasetName, tableName); assertNotNull(table); ArrayList tableFieldNames = new ArrayList<>(); for (Field field: table.getDefinition().getSchema().getFields()) { tableFieldNames.add(field.getName()); } - assertArrayEquals(fieldNames.toArray(), tableFieldNames.toArray()); bigquery.delete(table.getTableId()); assertEquals(Long.valueOf(50), result); } From cd95a6bdb96579f1e9d852604b124a365bb7238b Mon Sep 17 00:00:00 2001 From: happyhuman Date: Mon, 5 Mar 2018 16:24:52 -0800 Subject: [PATCH 4/8] Removed the unused imports. --- .../cloud/examples/bigquery/snippets/BigQuerySnippets.java | 1 - .../cloud/examples/bigquery/snippets/ITBigQuerySnippets.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index f6cb33d3e919..f77c156842e1 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -65,7 +65,6 @@ import java.nio.channels.Channels; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java index 59ee70fc3a3f..2ef79ed95a83 100644 --- a/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java +++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java @@ -50,9 +50,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Arrays; import java.util.Iterator; -import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; From babab5a1efdb8b632a9cf56d026889c872e67cae Mon Sep 17 00:00:00 2001 From: happyhuman Date: Fri, 9 Mar 2018 10:13:03 -0800 Subject: [PATCH 5/8] Fixed a number of other comments and annotations in BigQuerySnippets --- .../com/google/cloud/bigquery/BigQuery.java | 98 +++++++++++-------- .../bigquery/snippets/BigQuerySnippets.java | 22 +++-- 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java index 9d69342f754a..c6a948c968a9 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java @@ -524,6 +524,19 @@ public int hashCode() { * } * } * + *

Example of creating a dataset. + *

 {@code
+   * String datasetName = "my_dataset_name";
+   * Dataset dataset = null;
+   * DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
+   * try {
+   *   // the dataset was created
+   *   dataset = bigquery.create(datasetInfo);
+   * } catch (BigQueryException e) {
+   *   // the dataset was not created
+   * }
+   * }
+ * * @throws BigQueryException upon failure */ Dataset create(DatasetInfo datasetInfo, DatasetOption... options); @@ -538,7 +551,7 @@ public int hashCode() { * String fieldName = "string_field"; * TableId tableId = TableId.of(datasetName, tableName); * // Table field definition - * Field field = Field.of(fieldName, Field.Type.string()); + * Field field = Field.of(fieldName, LegacySQLTypeName.STRING); * // Table schema definition * Schema schema = Schema.of(field); * TableDefinition tableDefinition = StandardTableDefinition.of(schema); @@ -553,6 +566,32 @@ public int hashCode() { /** * Creates a new job. * + *

Example of writing a newline-delimited-json file with textual fields from GCS to a table. + *

 {@code
+   * String datasetName = "my_dataset_name";
+   * String tableName = "my_table_name";
+   * String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.json";
+   * TableId tableId = TableId.of(datasetName, tableName);
+   * // Table field definition
+   * Field[] fields = new Field[] {
+   *     Field.of("name", LegacySQLTypeName.STRING),
+   *     Field.of("post_abbr", LegacySQLTypeName.STRING)
+   * };
+   * // Table schema definition
+   * Schema schema = Schema.of(fields);
+   * LoadJobConfiguration configuration = LoadJobConfiguration.builder(tableId, sourceUri)
+   *     .setFormatOptions(FormatOptions.json())
+   *     .setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
+   *     .setSchema(schema)
+   *     .build();
+   * // Load the table
+   * Job remoteLoadJob = bigquery.create(JobInfo.of(configuration));
+   * remoteLoadJob = remoteLoadJob.waitFor();
+   * // Check the table
+   * System.out.println("State: " + remoteLoadJob.getStatus().getState());
+   * return ((StandardTableDefinition) bigquery.getTable(tableId).getDefinition()).getNumRows();
+   * }
+ * *

Example of creating a query job. *

 {@code
    * String query = "SELECT field FROM my_dataset_name.my_table_name";
@@ -861,8 +900,7 @@ public int hashCode() {
    * Lists the table's rows.
    *
    * 

Example of listing table rows, specifying the page size. - * - *

{@code
+   * 
 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";
    * // This example reads the result 100 rows per RPC call. If there's no need to limit the number,
@@ -882,8 +920,7 @@ public int hashCode() {
    * Lists the table's rows.
    *
    * 

Example of listing table rows, specifying the page size. - * - *

{@code
+   * 
 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";
    * TableId tableIdObject = TableId.of(datasetName, tableName);
@@ -891,7 +928,7 @@ public int hashCode() {
    * // simply omit the option.
    * TableResult tableData =
    *     bigquery.listTableData(tableIdObject, TableDataListOption.pageSize(100));
-   * for (FieldValueList row : rowIterator.hasNext()) {
+   * for (FieldValueList row : tableData.iterateAll()) {
    *   // do something with the row
    * }
    * }
@@ -904,17 +941,16 @@ public int hashCode() { * Lists the table's rows. If the {@code schema} is not {@code null}, it is available to the * {@link FieldValueList} iterated over. * - *

Example of listing table rows. - * - *

{@code
+   * 

Example of listing table rows with schema. + *

 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";
    * Schema schema = ...;
-   * String field = "my_field";
+   * String field = "field";
    * TableResult tableData =
    *     bigquery.listTableData(datasetName, tableName, schema);
    * for (FieldValueList row : tableData.iterateAll()) {
-   *   row.get(field)
+   *   row.get(field);
    * }
    * }
* @@ -927,9 +963,8 @@ TableResult listTableData( * Lists the table's rows. If the {@code schema} is not {@code null}, it is available to the * {@link FieldValueList} iterated over. * - *

Example of listing table rows. - * - *

{@code
+   * 

Example of listing table rows with schema. + *

 {@code
    * Schema schema =
    *     Schema.of(
    *         Field.of("word", LegacySQLTypeName.STRING),
@@ -1047,28 +1082,21 @@ TableResult listTableData(
    * queries. Since dry-run queries are not actually executed, there's no way to retrieve results.
    *
    * 

Example of running a query. - * - *

{@code
-   * String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare`";
-   * QueryJobConfiguration queryConfig = QueryJobConfiguration.of(query);
-   *
-   * // To run the legacy syntax queries use the following code instead:
-   * //   String query = "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]"
-   * //   QueryJobConfiguration queryConfig =
-   * //       QueryJobConfiguration.newBuilder(query).setUseLegacySql(true).build();
-   *
+   * 
 {@code
+   * String query = "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]";
+   * QueryJobConfiguration queryConfig =
+   *     QueryJobConfiguration.newBuilder(query).setUseLegacySql(true).build();
    * for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
    *   // do something with the data
    * }
    * }
* *

Example of running a query with query parameters. - * - *

{@code
-   * String query =
-   *     "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > ?";
+   * 
 {@code
+   * String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where;
+   * // Note, standard SQL is required to use query parameters. Legacy SQL will not work.
    * QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query)
-   *     .addPositionalParameter(QueryParameterValue.int64(5))
+   *     .addNamedParameter("wordCount", QueryParameterValue.int64(5))
    *     .build();
    * for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
    *   // do something with the data
@@ -1092,18 +1120,6 @@ TableResult query(QueryJobConfiguration configuration, JobOption... options)
    * 

See {@link #query(QueryJobConfiguration, JobOption...)} for examples on populating a {@link * QueryJobConfiguration}. * - *

The recommended way to create a randomly generated JobId is the following: - * - *

{@code
-   * JobId jobId = JobId.of();
-   * }
- * - * For a user specified job id with an optional prefix use the following: - * - *
{@code
-   * JobId jobId = JobId.of("my_prefix-my_unique_job_id");
-   * }
- * * @throws BigQueryException upon failure * @throws InterruptedException if the current thread gets interrupted while waiting for the query * to complete diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index f77c156842e1..86d9e583ede6 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -383,7 +383,7 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath) /** * Example of writing a newline-delimited-json file with textual fields from GCS to a table. */ - // [TARGET writer(WriteChannelConfiguration)] + // [TARGET create(JobInfo, JobOption...)] // [VARIABLE "my_dataset_name"] // [VARIABLE "my_table_name"] public Long writeRemoteFileToTable(String datasetName, String tableName) @@ -504,7 +504,9 @@ public TableResult listTableDataFromId(String datasetName, String tableName) { return tableData; } - /** Example of listing table rows with schema. */ + /** + * Example of listing table rows with schema. + */ // [TARGET listTableData(String, String, Schema, TableDataListOption...)] // [VARIABLE "my_dataset_name"] // [VARIABLE "my_table_name"] @@ -522,7 +524,9 @@ public TableResult listTableDataSchema( return tableData; } - /** Example of listing table rows with schema. */ + /** + * Example of listing table rows with schema. + */ // [TARGET listTableData(TableId, Schema, TableDataListOption...)] public FieldValueList listTableDataSchemaId() { // [START listTableDataSchemaId] @@ -641,8 +645,10 @@ public boolean cancelJobFromId(String jobName) { return success; } - /** Example of running a query. */ - // [TARGET query(QueryJobConfiguration, QueryOption...)] + /** + * Example of running a query. + */ + // [TARGET query(QueryJobConfiguration, JobOption...)] // [VARIABLE "SELECT unique(corpus) FROM [bigquery-public-data:samples.shakespeare]"] public void runQuery(String query) throws InterruptedException { // [START runQuery] @@ -654,8 +660,10 @@ public void runQuery(String query) throws InterruptedException { // [END runQuery] } - /** Example of running a query with query parameters. */ - // [TARGET query(QueryJobConfiguration, QueryOption...)] + /** + * Example of running a query with query parameters. + */ + // [TARGET query(QueryJobConfiguration, JobOption...)] // [VARIABLE "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where // word_count > @wordCount"] public void runQueryWithParameters(String query) throws InterruptedException { From 5930f77b22f6a4f948f1d836c576026f90fbe229 Mon Sep 17 00:00:00 2001 From: happyhuman Date: Fri, 9 Mar 2018 10:53:25 -0800 Subject: [PATCH 6/8] Minor changes in the snippet description --- .../cloud/examples/bigquery/snippets/BigQuerySnippets.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java index 86d9e583ede6..ef0394e8d875 100644 --- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java +++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java @@ -381,7 +381,7 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath) } /** - * Example of writing a newline-delimited-json file with textual fields from GCS to a table. + * Example of loading a newline-delimited-json file with textual fields from GCS to a table. */ // [TARGET create(JobInfo, JobOption...)] // [VARIABLE "my_dataset_name"] From 17d39a0511e5502adb5efe4f8fab5b0cd0d2876a Mon Sep 17 00:00:00 2001 From: happyhuman Date: Fri, 9 Mar 2018 11:19:02 -0800 Subject: [PATCH 7/8] Minor changes in the snippet description --- .../src/main/java/com/google/cloud/bigquery/BigQuery.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java index c6a948c968a9..08eb60d14458 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java @@ -566,7 +566,7 @@ public int hashCode() { /** * Creates a new job. * - *

Example of writing a newline-delimited-json file with textual fields from GCS to a table. + *

Example of loading a newline-delimited-json file with textual fields from GCS to a table. *

 {@code
    * String datasetName = "my_dataset_name";
    * String tableName = "my_table_name";

From f7938bda1cb35ccf263f6be36de02a3f24128c8c Mon Sep 17 00:00:00 2001
From: happyhuman 
Date: Fri, 9 Mar 2018 15:38:07 -0800
Subject: [PATCH 8/8] Cleaned up some of the auto generated java docs manually.

---
 .../java/com/google/cloud/bigquery/BigQuery.java  | 15 +--------------
 .../bigquery/snippets/BigQuerySnippets.java       |  3 +--
 2 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java
index 08eb60d14458..7f216910f8d9 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java
@@ -522,19 +522,6 @@ public int hashCode() {
    * } catch (BigQueryException e) {
    *   // the dataset was not created
    * }
-   * } 
- * - *

Example of creating a dataset. - *

 {@code
-   * String datasetName = "my_dataset_name";
-   * Dataset dataset = null;
-   * DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
-   * try {
-   *   // the dataset was created
-   *   dataset = bigquery.create(datasetInfo);
-   * } catch (BigQueryException e) {
-   *   // the dataset was not created
-   * }
    * }
* * @throws BigQueryException upon failure @@ -1093,7 +1080,7 @@ TableResult listTableData( * *

Example of running a query with query parameters. *

 {@code
-   * String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where;
+   * String query = "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > @wordCount";
    * // Note, standard SQL is required to use query parameters. Legacy SQL will not work.
    * QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query)
    *     .addNamedParameter("wordCount", QueryParameterValue.int64(5))
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java
index ef0394e8d875..ea95c59bbcf9 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java
@@ -664,8 +664,7 @@ public void runQuery(String query) throws InterruptedException {
    * Example of running a query with query parameters.
    */
   // [TARGET query(QueryJobConfiguration, JobOption...)]
-  // [VARIABLE "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where
-  // word_count > @wordCount"]
+  // [VARIABLE "SELECT distinct(corpus) FROM `bigquery-public-data.samples.shakespeare` where word_count > @wordCount"]
   public void runQueryWithParameters(String query) throws InterruptedException {
     // [START runQueryWithParameters]
     // Note, standard SQL is required to use query parameters. Legacy SQL will not work.