google-cloud-bigquery
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 e391c054d9..675e6c1e86 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
@@ -699,20 +699,17 @@ 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
- * }
+ * {@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
*/
@@ -723,22 +720,19 @@ public int hashCode() {
*
* Example of creating a table.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * String fieldName = "string_field";
- * TableId tableId = TableId.of(datasetName, tableName);
- * // Table field definition
- * Field field = Field.of(fieldName, LegacySQLTypeName.STRING);
- * // Table schema definition
- * Schema schema = Schema.of(field);
- * TableDefinition tableDefinition = StandardTableDefinition.of(schema);
- * TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
- * Table table = bigquery.create(tableInfo);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * String fieldName = "string_field";
+ * TableId tableId = TableId.of(datasetName, tableName);
+ * // Table field definition
+ * Field field = Field.of(fieldName, LegacySQLTypeName.STRING);
+ * // Table schema definition
+ * Schema schema = Schema.of(field);
+ * TableDefinition tableDefinition = StandardTableDefinition.of(schema);
+ * TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
+ * Table table = bigquery.create(tableInfo);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -756,46 +750,41 @@ public int hashCode() {
*
* 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";
- * 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 loadJob = bigquery.create(JobInfo.of(configuration));
- * loadJob = loadJob.waitFor();
- * // Check the table
- * System.out.println("State: " + loadJob.getStatus().getState());
- * return ((StandardTableDefinition) bigquery.getTable(tableId).getDefinition()).getNumRows();
- * }
- *
+ * {@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 loadJob = bigquery.create(JobInfo.of(configuration));
+ * loadJob = loadJob.waitFor();
+ * // Check the table
+ * System.out.println("State: " + loadJob.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";
- * Job job = null;
- * JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
- * JobInfo jobInfo = JobInfo.of(jobConfiguration);
- * try {
- * job = bigquery.create(jobInfo);
- * } catch (BigQueryException e) {
- * // the job was not created
- * }
+ * {@code
+ * String query = "SELECT field FROM my_dataset_name.my_table_name";
+ * Job job = null;
+ * JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
+ * JobInfo jobInfo = JobInfo.of(jobConfiguration);
+ * try {
+ * job = bigquery.create(jobInfo);
+ * } catch (BigQueryException e) {
+ * // the job was not created
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -808,18 +797,15 @@ public int hashCode() {
*
* Example of creating a query connection.
*
- *
- * {
- * @code
- * ConnectionSettings connectionSettings =
- * ConnectionSettings.newBuilder()
- * .setRequestTimeout(10L)
- * .setMaxResults(100L)
- * .setUseQueryCache(true)
- * .build();
- * Connection connection = bigquery.createConnection(connectionSettings);
- * }
- *
+ * {@code
+ * ConnectionSettings connectionSettings =
+ * ConnectionSettings.newBuilder()
+ * .setRequestTimeout(10L)
+ * .setMaxResults(100L)
+ * .setUseQueryCache(true)
+ * .build();
+ * Connection connection = bigquery.createConnection(connectionSettings);
+ * }
*
* @throws BigQueryException upon failure
* @param connectionSettings
@@ -836,12 +822,9 @@ public int hashCode() {
*
* Example of creating a query connection.
*
- *
- * {
- * @code
- * Connection connection = bigquery.createConnection();
- * }
- *
+ * {@code
+ * Connection connection = bigquery.createConnection();
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -853,13 +836,10 @@ public int hashCode() {
*
* Example of getting a dataset.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset";
- * Dataset dataset = bigquery.getDataset(datasetName);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset";
+ * Dataset dataset = bigquery.getDataset(datasetName);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -870,15 +850,12 @@ public int hashCode() {
*
* Example of getting a dataset.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * DatasetId datasetId = DatasetId.of(projectId, datasetName);
- * Dataset dataset = bigquery.getDataset(datasetId);
- * }
- *
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * DatasetId datasetId = DatasetId.of(projectId, datasetName);
+ * Dataset dataset = bigquery.getDataset(datasetId);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -892,16 +869,13 @@ public int hashCode() {
*
* Example of listing datasets, specifying the page size.
*
- *
- * {
- * @code
- * // List datasets in the default project
- * Page<Dataset> datasets = bigquery.listDatasets(DatasetListOption.pageSize(100));
- * for (Dataset dataset : datasets.iterateAll()) {
- * // do something with the dataset
- * }
+ * {@code
+ * // List datasets in the default project
+ * Page datasets = bigquery.listDatasets(DatasetListOption.pageSize(100));
+ * for (Dataset dataset : datasets.iterateAll()) {
+ * // do something with the dataset
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -915,17 +889,14 @@ public int hashCode() {
*
* Example of listing datasets in a project, specifying the page size.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * // List datasets in a specified project
- * Page<{@link Dataset}> datasets = bigquery.listDatasets(projectId, DatasetListOption.pageSize(100));
- * for (Dataset dataset : datasets.iterateAll()) {
- * // do something with the dataset
- * }
+ * {@code
+ * String projectId = "my_project_id";
+ * // List datasets in a specified project
+ * Page datasets = bigquery.listDatasets(projectId, DatasetListOption.pageSize(100));
+ * for (Dataset dataset : datasets.iterateAll()) {
+ * // do something with the dataset
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -936,18 +907,15 @@ public int hashCode() {
*
* Example of deleting a dataset from its id, even if non-empty.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * boolean deleted = bigquery.delete(datasetName, DatasetDeleteOption.deleteContents());
- * if (deleted) {
- * // the dataset was deleted
- * } else {
- * // the dataset was not found
- * }
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * boolean deleted = bigquery.delete(datasetName, DatasetDeleteOption.deleteContents());
+ * if (deleted) {
+ * // the dataset was deleted
+ * } else {
+ * // the dataset was not found
* }
- *
+ * }
*
* @return {@code true} if dataset was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
@@ -959,20 +927,17 @@ public int hashCode() {
*
* Example of deleting a dataset, even if non-empty.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * DatasetId datasetId = DatasetId.of(projectId, datasetName);
- * boolean deleted = bigquery.delete(datasetId, DatasetDeleteOption.deleteContents());
- * if (deleted) {
- * // the dataset was deleted
- * } else {
- * // the dataset was not found
- * }
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * DatasetId datasetId = DatasetId.of(projectId, datasetName);
+ * boolean deleted = bigquery.delete(datasetId, DatasetDeleteOption.deleteContents());
+ * if (deleted) {
+ * // the dataset was deleted
+ * } else {
+ * // the dataset was not found
* }
- *
+ * }
*
* @return {@code true} if dataset was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
@@ -996,21 +961,18 @@ public int hashCode() {
*
* Example of deleting a table.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * TableId tableId = TableId.of(projectId, datasetName, tableName);
- * boolean deleted = bigquery.delete(tableId);
- * if (deleted) {
- * // the table was deleted
- * } else {
- * // the table was not found
- * }
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * TableId tableId = TableId.of(projectId, datasetName, tableName);
+ * boolean deleted = bigquery.delete(tableId);
+ * if (deleted) {
+ * // the table was deleted
+ * } else {
+ * // the table was not found
* }
- *
+ * }
*
* @return {@code true} if table was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
@@ -1022,21 +984,18 @@ public int hashCode() {
*
* Example of deleting a model.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * String tableName = "my_model_name";
- * ModelId modelId = ModelId.of(projectId, datasetName, modelName);
- * boolean deleted = bigquery.delete(modelId);
- * if (deleted) {
- * // the model was deleted
- * } else {
- * // the model was not found
- * }
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_model_name";
+ * ModelId modelId = ModelId.of(projectId, datasetName, modelName);
+ * boolean deleted = bigquery.delete(modelId);
+ * if (deleted) {
+ * // the model was deleted
+ * } else {
+ * // the model was not found
* }
- *
+ * }
*
* @return {@code true} if model was deleted, {@code false} if it was not found
* @throws BigQueryException upon failure
@@ -1081,19 +1040,15 @@ public int hashCode() {
*
*
- *
- * {
- * @code
- * // String datasetName = "my_dataset_name";
- * // String tableName = "my_table_name";
- * // String newDescription = "new_description";
- *
- * Table beforeTable = bigquery.getTable(datasetName, tableName);
- * TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build();
- * Table afterTable = bigquery.update(tableInfo);
+ * {@code
+ * // String datasetName = "my_dataset_name";
+ * // String tableName = "my_table_name";
+ * // String newDescription = "new_description";
*
- * }
- *
+ * Table beforeTable = bigquery.getTable(datasetName, tableName);
+ * TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build();
+ * Table afterTable = bigquery.update(tableInfo);
+ * }
*
*
*
@@ -1106,33 +1061,27 @@ public int hashCode() {
*
* Example of updating a table by changing its description.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * String newDescription = "new_description";
- * Table beforeTable = bigquery.getTable(datasetName, tableName);
- * TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build();
- * Table afterTable = bigquery.update(tableInfo);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * String newDescription = "new_description";
+ * Table beforeTable = bigquery.getTable(datasetName, tableName);
+ * TableInfo tableInfo = beforeTable.toBuilder().setDescription(newDescription).build();
+ * Table afterTable = bigquery.update(tableInfo);
+ * }
*
* Example of updating a table by changing its expiration.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * Table beforeTable = bigquery.getTable(datasetName, tableName);
- *
- * // Set table to expire 5 days from now.
- * long expirationMillis = DateTime.now().plusDays(5).getMillis();
- * TableInfo tableInfo = beforeTable.toBuilder().setExpirationTime(expirationMillis).build();
- * Table afterTable = bigquery.update(tableInfo);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * Table beforeTable = bigquery.getTable(datasetName, tableName);
+ *
+ * // Set table to expire 5 days from now.
+ * long expirationMillis = DateTime.now().plusDays(5).getMillis();
+ * TableInfo tableInfo = beforeTable.toBuilder().setExpirationTime(expirationMillis).build();
+ * Table afterTable = bigquery.update(tableInfo);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1143,33 +1092,27 @@ public int hashCode() {
*
* Example of updating a model by changing its description.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String modelName = "my_model_name";
- * String newDescription = "new_description";
- * Model beforeModel = bigquery.getModel(datasetName, modelName);
- * ModelInfo modelInfo = beforeModel.toBuilder().setDescription(newDescription).build();
- * Model afterModel = bigquery.update(modelInfo);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String modelName = "my_model_name";
+ * String newDescription = "new_description";
+ * Model beforeModel = bigquery.getModel(datasetName, modelName);
+ * ModelInfo modelInfo = beforeModel.toBuilder().setDescription(newDescription).build();
+ * Model afterModel = bigquery.update(modelInfo);
+ * }
*
* Example of updating a model by changing its expiration.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String modelName = "my_model_name";
- * Model beforeModel = bigquery.getModel(datasetName, modelName);
- *
- * // Set model to expire 5 days from now.
- * long expirationMillis = DateTime.now().plusDays(5).getMillis();
- * ModelInfo modelInfo = beforeModel.toBuilder().setExpirationTime(expirationMillis).build();
- * Model afterModel = bigquery.update(modelInfo);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String modelName = "my_model_name";
+ * Model beforeModel = bigquery.getModel(datasetName, modelName);
+ *
+ * // Set model to expire 5 days from now.
+ * long expirationMillis = DateTime.now().plusDays(5).getMillis();
+ * ModelInfo modelInfo = beforeModel.toBuilder().setExpirationTime(expirationMillis).build();
+ * Model afterModel = bigquery.update(modelInfo);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1187,14 +1130,11 @@ public int hashCode() {
*
* Example of getting a table.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * Table table = bigquery.getTable(datasetName, tableName);
- * }
- *
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * Table table = bigquery.getTable(datasetName, tableName);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1205,16 +1145,13 @@ public int hashCode() {
*
* Example of getting a table.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * TableId tableId = TableId.of(projectId, datasetName, tableName);
- * Table table = bigquery.getTable(tableId);
- * }
- *
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * TableId tableId = TableId.of(projectId, datasetName, tableName);
+ * Table table = bigquery.getTable(tableId);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1232,16 +1169,13 @@ public int hashCode() {
*
* Example of getting a model.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * String modelName = "my_model_name";
- * ModelId modelId = ModelId.of(projectId, datasetName, tableName);
- * Model model = bigquery.getModel(modelId);
- * }
- *
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * String modelName = "my_model_name";
+ * ModelId modelId = ModelId.of(projectId, datasetName, tableName);
+ * Model model = bigquery.getModel(modelId);
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1275,16 +1209,13 @@ public int hashCode() {
*
* Example of listing the tables in a dataset, specifying the page size.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * Page<Table> tables = bigquery.listTables(datasetName, TableListOption.pageSize(100));
- * for (Table table : tables.iterateAll()) {
- * // do something with the table
- * }
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * Page tables = bigquery.listTables(datasetName, TableListOption.pageSize(100));
+ * for (Table table : tables.iterateAll()) {
+ * // do something with the table
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1298,18 +1229,15 @@ public int hashCode() {
*
* Example of listing the tables in a dataset.
*
- *
- * {
- * @code
- * String projectId = "my_project_id";
- * String datasetName = "my_dataset_name";
- * DatasetId datasetId = DatasetId.of(projectId, datasetName);
- * Page<Table> tables = bigquery.listTables(datasetId, TableListOption.pageSize(100));
- * for (Table table : tables.iterateAll()) {
- * // do something with the table
- * }
+ * {@code
+ * String projectId = "my_project_id";
+ * String datasetName = "my_dataset_name";
+ * DatasetId datasetId = DatasetId.of(projectId, datasetName);
+ * Page tables = bigquery.listTables(datasetId, TableListOption.pageSize(100));
+ * for (Table table : tables.iterateAll()) {
+ * // do something with the table
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1332,33 +1260,30 @@ public int hashCode() {
*
* Example of inserting rows into a table without running a load job.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * TableId tableId = TableId.of(datasetName, tableName);
- * // Values of the row to insert
- * Map<String, Object> rowContent = new HashMap<>();
- * rowContent.put("booleanField", true);
- * // Bytes are passed in base64
- * rowContent.put("bytesField", "Cg0NDg0="); // 0xA, 0xD, 0xD, 0xE, 0xD in base64
- * // Records are passed as a map
- * Map<String, Object> recordsContent = new HashMap<>();
- * recordsContent.put("stringField", "Hello, World!");
- * rowContent.put("recordField", recordsContent);
- * InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId).addRow("rowId", rowContent)
- * // More rows can be added in the same RPC by invoking .addRow() on the
- * // builder
- * .build());
- * if (response.hasErrors()) {
- * // If any of the insertions failed, this lets you inspect the errors
- * for (Entry<Long, List<BigQueryError>> entry : response.getInsertErrors().entrySet()) {
- * // inspect row error
- * }
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * TableId tableId = TableId.of(datasetName, tableName);
+ * // Values of the row to insert
+ * Map rowContent = new HashMap<>();
+ * rowContent.put("booleanField", true);
+ * // Bytes are passed in base64
+ * rowContent.put("bytesField", "Cg0NDg0="); // 0xA, 0xD, 0xD, 0xE, 0xD in base64
+ * // Records are passed as a map
+ * Map recordsContent = new HashMap<>();
+ * recordsContent.put("stringField", "Hello, World!");
+ * rowContent.put("recordField", recordsContent);
+ * InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId).addRow("rowId", rowContent)
+ * // More rows can be added in the same RPC by invoking .addRow() on the
+ * // builder
+ * .build());
+ * if (response.hasErrors()) {
+ * // If any of the insertions failed, this lets you inspect the errors
+ * for (Entry> entry : response.getInsertErrors().entrySet()) {
+ * // inspect row error
* }
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1369,20 +1294,17 @@ public int hashCode() {
*
* Example of listing table rows, specifying the page size.
*
- *
- * {
- * @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,
- * // simply omit the option.
- * TableResult tableData = bigquery.listTableData(datasetName, tableName, TableDataListOption.pageSize(100));
- * for (FieldValueList row : tableData.iterateAll()) {
- * // do something with the row
- * }
+ * {@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,
+ * // simply omit the option.
+ * TableResult tableData = bigquery.listTableData(datasetName, tableName, TableDataListOption.pageSize(100));
+ * for (FieldValueList row : tableData.iterateAll()) {
+ * // do something with the row
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1393,21 +1315,18 @@ public int hashCode() {
*
* Example of listing table rows, specifying the page size.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * TableId tableIdObject = TableId.of(datasetName, tableName);
- * // This example reads the result 100 rows per RPC call. If there's no need
- * // to limit the number,
- * // simply omit the option.
- * TableResult tableData = bigquery.listTableData(tableIdObject, TableDataListOption.pageSize(100));
- * for (FieldValueList row : tableData.iterateAll()) {
- * // do something with the row
- * }
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * TableId tableIdObject = TableId.of(datasetName, tableName);
+ * // This example reads the result 100 rows per RPC call. If there's no need
+ * // to limit the number,
+ * // simply omit the option.
+ * TableResult tableData = bigquery.listTableData(tableIdObject, TableDataListOption.pageSize(100));
+ * for (FieldValueList row : tableData.iterateAll()) {
+ * // do something with the row
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1441,18 +1360,15 @@ TableResult listTableData(
*
* Example of listing table rows with schema.
*
- *
- * {
- * @code
- * Schema schema = Schema.of(Field.of("word", LegacySQLTypeName.STRING),
- * Field.of("word_count", LegacySQLTypeName.STRING), Field.of("corpus", LegacySQLTypeName.STRING),
- * Field.of("corpus_date", LegacySQLTypeName.STRING));
- * TableResult tableData = bigquery.listTableData(TableId.of("bigquery-public-data", "samples", "shakespeare"),
- * schema);
- * FieldValueList row = tableData.getValues().iterator().next();
- * System.out.println(row.get("word").getStringValue());
- * }
- *
+ * {@code
+ * Schema schema = Schema.of(Field.of("word", LegacySQLTypeName.STRING),
+ * Field.of("word_count", LegacySQLTypeName.STRING), Field.of("corpus", LegacySQLTypeName.STRING),
+ * Field.of("corpus_date", LegacySQLTypeName.STRING));
+ * TableResult tableData = bigquery.listTableData(TableId.of("bigquery-public-data", "samples", "shakespeare"),
+ * schema);
+ * FieldValueList row = tableData.getValues().iterator().next();
+ * System.out.println(row.get("word").getStringValue());
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1464,16 +1380,13 @@ TableResult listTableData(
*
* Example of getting a job.
*
- *
- * {
- * @code
- * String jobName = "my_job_name";
- * Job job = bigquery.getJob(jobName);
- * if (job == null) {
- * // job was not found
- * }
+ * {@code
+ * String jobName = "my_job_name";
+ * Job job = bigquery.getJob(jobName);
+ * if (job == null) {
+ * // job was not found
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1485,17 +1398,14 @@ TableResult listTableData(
*
* Example of getting a job.
*
- *
- * {
- * @code
- * String jobName = "my_job_name";
- * JobId jobIdObject = JobId.of(jobName);
- * Job job = bigquery.getJob(jobIdObject);
- * if (job == null) {
- * // job was not found
- * }
+ * {@code
+ * String jobName = "my_job_name";
+ * JobId jobIdObject = JobId.of(jobName);
+ * Job job = bigquery.getJob(jobIdObject);
+ * if (job == null) {
+ * // job was not found
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1506,15 +1416,12 @@ TableResult listTableData(
*
* Example of listing jobs, specifying the page size.
*
- *
- * {
- * @code
- * Page<Job> jobs = bigquery.listJobs(JobListOption.pageSize(100));
- * for (Job job : jobs.iterateAll()) {
- * // do something with the job
- * }
+ * {@code
+ * Page jobs = bigquery.listJobs(JobListOption.pageSize(100));
+ * for (Job job : jobs.iterateAll()) {
+ * // do something with the job
* }
- *
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1529,18 +1436,15 @@ TableResult listTableData(
*
* Example of cancelling a job.
*
- *
- * {
- * @code
- * String jobName = "my_job_name";
- * boolean success = bigquery.cancel(jobName);
- * if (success) {
- * // job was cancelled
- * } else {
- * // job was not found
- * }
+ * {@code
+ * String jobName = "my_job_name";
+ * boolean success = bigquery.cancel(jobName);
+ * if (success) {
+ * // job was cancelled
+ * } else {
+ * // job was not found
* }
- *
+ * }
*
* @return {@code true} if cancel was requested successfully, {@code false} if the job was not
* found
@@ -1558,19 +1462,16 @@ TableResult listTableData(
*
* Example of cancelling a job.
*
- *
- * {
- * @code
- * String jobName = "my_job_name";
- * JobId jobId = JobId.of(jobName);
- * boolean success = bigquery.cancel(jobId);
- * if (success) {
- * // job was cancelled
- * } else {
- * // job was not found
- * }
+ * {@code
+ * String jobName = "my_job_name";
+ * JobId jobId = JobId.of(jobName);
+ * boolean success = bigquery.cancel(jobId);
+ * if (success) {
+ * // job was cancelled
+ * } else {
+ * // job was not found
* }
- *
+ * }
*
* @return {@code true} if cancel was requested successfully, {@code false} if the job was not
* found
@@ -1589,22 +1490,19 @@ TableResult listTableData(
*
* Example of running a query.
*
- *
- * {
- * @code
- * // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
- * String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
- * QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();
- *
- * // Print the results.
- * for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
- * for (FieldValue val : row) {
- * System.out.printf("%s,", val.toString());
- * }
- * System.out.printf("\n");
+ * {@code
+ * // BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
+ * String query = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
+ * QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();
+ *
+ * // Print the results.
+ * for (FieldValueList row : bigquery.query(queryConfig).iterateAll()) {
+ * for (FieldValue val : row) {
+ * System.out.printf("%s,", val.toString());
* }
+ * System.out.printf("\n");
* }
- *
+ * }
*
* This method supports query-related preview features via environmental variables (enabled by
* setting the {@code QUERY_PREVIEW_ENABLED} environment variable to "TRUE"). Specifically, this
@@ -1630,7 +1528,7 @@ TableResult query(QueryJobConfiguration configuration, JobOption... options)
* If the location of the job is not "US" or "EU", the {@code jobId} must specify the job
* location.
*
- *
This method cannot be used in conjuction with {@link QueryJobConfiguration#dryRun()}
+ *
This method cannot be used in conjunction with {@link QueryJobConfiguration#dryRun()}
* queries. Since dry-run queries are not actually executed, there's no way to retrieve results.
*
*
See {@link #query(QueryJobConfiguration, JobOption...)} for examples on populating a {@link
@@ -1659,56 +1557,50 @@ TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption...
*
*
Example of creating a channel with which to write to a table.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * String csvData = "StringValue1\nStringValue2\n";
- * TableId tableId = TableId.of(datasetName, tableName);
- * WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.newBuilder(tableId)
- * .setFormatOptions(FormatOptions.csv()).build();
- * TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
- * // Write data to writer
- * try {
- * writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
- * } finally {
- * writer.close();
- * }
- * // Get load job
- * Job job = writer.getJob();
- * job = job.waitFor();
- * LoadStatistics stats = job.getStatistics();
- * return stats.getOutputRows();
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * String csvData = "StringValue1\nStringValue2\n";
+ * TableId tableId = TableId.of(datasetName, tableName);
+ * WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.newBuilder(tableId)
+ * .setFormatOptions(FormatOptions.csv()).build();
+ * TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
+ * // Write data to writer
+ * try {
+ * writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
+ * } finally {
+ * writer.close();
* }
- *
+ * // Get load job
+ * Job job = writer.getJob();
+ * job = job.waitFor();
+ * LoadStatistics stats = job.getStatistics();
+ * return stats.getOutputRows();
+ * }
*
* Example of writing a local file to a table.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * Path csvPath = FileSystems.getDefault().getPath(".", "my-data.csv");
- * String location = "us";
- * TableId tableId = TableId.of(datasetName, tableName);
- * WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.newBuilder(tableId)
- * .setFormatOptions(FormatOptions.csv()).build();
- * // The location must be specified; other fields can be auto-detected.
- * JobId jobId = JobId.newBuilder().setLocation(location).build();
- * TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
- * // Write data to writer
- * try (OutputStream stream = Channels.newOutputStream(writer)) {
- * Files.copy(csvPath, stream);
- * }
- * // Get load job
- * Job job = writer.getJob();
- * job = job.waitFor();
- * LoadStatistics stats = job.getStatistics();
- * return stats.getOutputRows();
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * Path csvPath = FileSystems.getDefault().getPath(".", "my-data.csv");
+ * String location = "us";
+ * TableId tableId = TableId.of(datasetName, tableName);
+ * WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.newBuilder(tableId)
+ * .setFormatOptions(FormatOptions.csv()).build();
+ * // The location must be specified; other fields can be auto-detected.
+ * JobId jobId = JobId.newBuilder().setLocation(location).build();
+ * TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
+ * // Write data to writer
+ * try (OutputStream stream = Channels.newOutputStream(writer)) {
+ * Files.copy(csvPath, stream);
* }
- *
+ * // Get load job
+ * Job job = writer.getJob();
+ * job = job.waitFor();
+ * LoadStatistics stats = job.getStatistics();
+ * return stats.getOutputRows();
+ * }
*
* @throws BigQueryException upon failure
*/
@@ -1721,32 +1613,29 @@ TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption...
*
* Example of creating a channel with which to write to a table.
*
- *
- * {
- * @code
- * String datasetName = "my_dataset_name";
- * String tableName = "my_table_name";
- * String csvData = "StringValue1\nStringValue2\n";
- * String location = "us";
- * TableId tableId = TableId.of(datasetName, tableName);
- * WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.newBuilder(tableId)
- * .setFormatOptions(FormatOptions.csv()).build();
- * // The location must be specified; other fields can be auto-detected.
- * JobId jobId = JobId.newBuilder().setLocation(location).build();
- * TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
- * // Write data to writer
- * try {
- * writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
- * } finally {
- * writer.close();
- * }
- * // Get load job
- * Job job = writer.getJob();
- * job = job.waitFor();
- * LoadStatistics stats = job.getStatistics();
- * return stats.getOutputRows();
+ * {@code
+ * String datasetName = "my_dataset_name";
+ * String tableName = "my_table_name";
+ * String csvData = "StringValue1\nStringValue2\n";
+ * String location = "us";
+ * TableId tableId = TableId.of(datasetName, tableName);
+ * WriteChannelConfiguration writeChannelConfiguration = WriteChannelConfiguration.newBuilder(tableId)
+ * .setFormatOptions(FormatOptions.csv()).build();
+ * // The location must be specified; other fields can be auto-detected.
+ * JobId jobId = JobId.newBuilder().setLocation(location).build();
+ * TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
+ * // Write data to writer
+ * try {
+ * writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
+ * } finally {
+ * writer.close();
* }
- *
+ * // Get load job
+ * Job job = writer.getJob();
+ * job = job.waitFor();
+ * LoadStatistics stats = job.getStatistics();
+ * return stats.getOutputRows();
+ * }
*/
TableDataWriteChannel writer(JobId jobId, WriteChannelConfiguration writeChannelConfiguration);
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java
index 363f9507e1..5af3085e20 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ExternalTableDefinition.java
@@ -200,6 +200,20 @@ public Builder setMetadataCacheMode(String metadataCacheMode) {
abstract Builder setMetadataCacheModeInner(String metadataCacheMode);
+ /**
+ * [Optional] Metadata Cache Mode for the table. Set this to enable caching of metadata from
+ * external data source.
+ *
+ * @see
+ * MaxStaleness
+ */
+ public Builder setMaxStaleness(String maxStaleness) {
+ return setMaxStalenessInner(maxStaleness);
+ }
+
+ abstract Builder setMaxStalenessInner(String maxStaleness);
+
/** Creates an {@code ExternalTableDefinition} object. */
@Override
public abstract ExternalTableDefinition build();
@@ -305,6 +319,22 @@ public String getMetadataCacheMode() {
@Nullable
abstract String getMetadataCacheModeInner();
+ /**
+ * Returns the maximum staleness of data that could be returned when the table is queried.
+ * Staleness encoded as a string encoding of sql IntervalValue type.
+ *
+ * @see
+ * MaxStaleness
+ */
+ @Nullable
+ public String getMaxStaleness() {
+ return getMaxStalenessInner();
+ }
+
+ @Nullable
+ abstract String getMaxStalenessInner();
+
/**
* Returns the source format, and possibly some parsing options, of the external data. Supported
* formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}.
@@ -351,6 +381,9 @@ public HivePartitioningOptions getHivePartitioningOptions() {
com.google.api.services.bigquery.model.Table toPb() {
Table tablePb = super.toPb();
tablePb.setExternalDataConfiguration(toExternalDataConfigurationPb());
+ if (getMaxStaleness() != null) {
+ tablePb.setMaxStaleness(getMaxStaleness());
+ }
return tablePb;
}
@@ -616,6 +649,9 @@ static ExternalTableDefinition fromPb(Table tablePb) {
if (externalDataConfiguration.getMetadataCacheMode() != null) {
builder.setMetadataCacheMode(externalDataConfiguration.getMetadataCacheMode());
}
+ if (tablePb.getMaxStaleness() != null) {
+ builder.setMaxStaleness(tablePb.getMaxStaleness());
+ }
}
return builder.build();
}
diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExternalTableDefinitionTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExternalTableDefinitionTest.java
index 2562e1763c..e6e7e0fcc6 100644
--- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExternalTableDefinitionTest.java
+++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/ExternalTableDefinitionTest.java
@@ -59,8 +59,8 @@ public class ExternalTableDefinitionTest {
.setSourceUriPrefix(SOURCE_URIS.get(0))
.build();
private static final String OBJECT_METADATA = "SIMPLE";
-
private static final String METADATA_CACHE_MODE = "AUTOMATIC";
+ private static final String MAX_STALENESS = "INTERVAL 15 MINUTE";
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION =
ExternalTableDefinition.newBuilder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS)
.setFileSetSpecType("FILE_SET_SPEC_TYPE_FILE_SYSTEM_MATCH")
@@ -73,6 +73,7 @@ public class ExternalTableDefinitionTest {
.setHivePartitioningOptions(HIVE_PARTITIONING_OPTIONS)
.setObjectMetadata(OBJECT_METADATA)
.setMetadataCacheMode(METADATA_CACHE_MODE)
+ .setMaxStaleness(MAX_STALENESS)
.build();
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION_AVRO =
@@ -174,5 +175,6 @@ private void compareExternalTableDefinition(
assertEquals(expected.getHivePartitioningOptions(), value.getHivePartitioningOptions());
assertEquals(expected.getObjectMetadata(), value.getObjectMetadata());
assertEquals(expected.getMetadataCacheMode(), value.getMetadataCacheMode());
+ assertEquals(expected.getMaxStaleness(), value.getMaxStaleness());
}
}
diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java
index 15fe5eb8cf..b1cb8d8451 100644
--- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java
+++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java
@@ -2111,9 +2111,13 @@ public void testCreateAndGetTableWithSelectedField() {
public void testCreateExternalTable() throws InterruptedException {
String tableName = "test_create_external_table";
TableId tableId = TableId.of(DATASET, tableName);
+
ExternalTableDefinition externalTableDefinition =
ExternalTableDefinition.of(
- "gs://" + BUCKET + "/" + JSON_LOAD_FILE, TABLE_SCHEMA, FormatOptions.json());
+ "gs://" + BUCKET + "/" + JSON_LOAD_FILE, TABLE_SCHEMA, FormatOptions.json())
+ .toBuilder()
+ .setMaxStaleness("INTERVAL 15 MINUTE")
+ .build();
TableInfo tableInfo = TableInfo.of(tableId, externalTableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
diff --git a/pom.xml b/pom.xml
index 53e4b5b9a3..31168bf894 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.google.cloud
google-cloud-bigquery-parent
pom
- 2.42.4
+ 2.43.3
BigQuery Parent
https://github.com/googleapis/java-bigquery
@@ -14,7 +14,7 @@
com.google.cloud
sdk-platform-java-config
- 3.36.1
+ 3.39.0
@@ -54,7 +54,7 @@
UTF-8
github
google-cloud-bigquery-parent
- v2-rev20240905-2.0.0
+ v2-rev20241013-2.0.0
@@ -71,7 +71,7 @@
com.google.cloud
google-cloud-bigquerystorage-bom
- 3.9.2
+ 3.10.2
pom
import
@@ -79,7 +79,7 @@
com.google.cloud
google-cloud-datacatalog-bom
- 1.57.0
+ 1.58.0
pom
import
@@ -93,7 +93,7 @@
com.google.cloud
google-cloud-bigquery
- 2.42.4
+ 2.43.3
@@ -137,19 +137,19 @@
com.google.cloud
google-cloud-storage
- 2.43.1
+ 2.44.1
test
com.google.cloud
google-cloud-bigqueryconnection
- 2.53.0
+ 2.54.0
test
com.google.api.grpc
proto-google-cloud-bigqueryconnection-v1
- 2.53.0
+ 2.54.0
test
@@ -180,7 +180,7 @@
org.apache.maven.plugins
maven-project-info-reports-plugin
- 3.7.0
+ 3.8.0
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 8d3d0e4d5d..667606a0a4 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -30,7 +30,7 @@
com.google.cloud.samples
shared-configuration
- 1.2.0
+ 1.2.2
@@ -45,7 +45,7 @@
com.google.cloud
google-cloud-bigquery
- 2.42.3
+ 2.43.1
@@ -63,13 +63,13 @@
com.google.cloud
google-cloud-bigtable
- 2.44.1
+ 2.45.1
test
com.google.cloud
google-cloud-bigqueryconnection
- 2.53.0
+ 2.54.0
test
diff --git a/samples/pom.xml b/samples/pom.xml
index b0ed2cf7ba..d493a5953d 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -34,7 +34,7 @@
com.google.cloud.samples
shared-configuration
- 1.2.0
+ 1.2.2
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index be36735e93..358fb3bb4e 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -30,7 +30,7 @@
com.google.cloud.samples
shared-configuration
- 1.2.0
+ 1.2.2
@@ -44,7 +44,7 @@
com.google.cloud
google-cloud-bigquery
- 2.42.4
+ 2.43.3
@@ -61,13 +61,13 @@
com.google.cloud
google-cloud-bigtable
- 2.44.1
+ 2.45.1
test
com.google.cloud
google-cloud-bigqueryconnection
- 2.53.0
+ 2.54.0
test
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index a0ea893ac5..68190cb051 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -29,7 +29,7 @@
com.google.cloud.samples
shared-configuration
- 1.2.0
+ 1.2.2
@@ -79,13 +79,13 @@
com.google.cloud
google-cloud-bigtable
- 2.44.1
+ 2.45.1
test
com.google.cloud
google-cloud-bigqueryconnection
- 2.53.0
+ 2.54.0
test
diff --git a/samples/snippets/src/main/java/com/example/bigquery/SimpleApp.java b/samples/snippets/src/main/java/com/example/bigquery/SimpleApp.java
index 65ebbc241d..49975a9cc0 100644
--- a/samples/snippets/src/main/java/com/example/bigquery/SimpleApp.java
+++ b/samples/snippets/src/main/java/com/example/bigquery/SimpleApp.java
@@ -20,6 +20,7 @@
// [START bigquery_simple_app_deps]
import com.google.cloud.bigquery.BigQuery;
+import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.FieldValueList;
import com.google.cloud.bigquery.Job;
@@ -27,56 +28,65 @@
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.QueryJobConfiguration;
import com.google.cloud.bigquery.TableResult;
-import java.util.UUID;
// [END bigquery_simple_app_deps]
public class SimpleApp {
+
public static void main(String... args) throws Exception {
- // [START bigquery_simple_app_client]
- BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
- // [END bigquery_simple_app_client]
- // [START bigquery_simple_app_query]
- QueryJobConfiguration queryConfig =
- QueryJobConfiguration.newBuilder(
- "SELECT CONCAT('https://stackoverflow.com/questions/', "
- + "CAST(id as STRING)) as url, view_count "
- + "FROM `bigquery-public-data.stackoverflow.posts_questions` "
- + "WHERE tags like '%google-bigquery%' "
- + "ORDER BY view_count DESC "
- + "LIMIT 10")
- // Use standard SQL syntax for queries.
- // See: https://cloud.google.com/bigquery/sql-reference/
- .setUseLegacySql(false)
- .build();
+ // TODO(developer): Replace these variables before running the app.
+ String projectId = "MY_PROJECT_ID";
+ simpleApp(projectId);
+ }
- // Create a job ID so that we can safely retry.
- JobId jobId = JobId.of(UUID.randomUUID().toString());
- Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
+ public static void simpleApp(String projectId) {
+ try {
+ // [START bigquery_simple_app_client]
+ BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
+ // [END bigquery_simple_app_client]
+ // [START bigquery_simple_app_query]
+ QueryJobConfiguration queryConfig =
+ QueryJobConfiguration.newBuilder(
+ "SELECT CONCAT('https://stackoverflow.com/questions/', "
+ + "CAST(id as STRING)) as url, view_count "
+ + "FROM `bigquery-public-data.stackoverflow.posts_questions` "
+ + "WHERE tags like '%google-bigquery%' "
+ + "ORDER BY view_count DESC "
+ + "LIMIT 10")
+ // Use standard SQL syntax for queries.
+ // See: https://cloud.google.com/bigquery/sql-reference/
+ .setUseLegacySql(false)
+ .build();
- // Wait for the query to complete.
- queryJob = queryJob.waitFor();
+ JobId jobId = JobId.newBuilder().setProject(projectId).build();
+ Job queryJob = bigquery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
- // Check for errors
- if (queryJob == null) {
- throw new RuntimeException("Job no longer exists");
- } else if (queryJob.getStatus().getError() != null) {
- // You can also look at queryJob.getStatus().getExecutionErrors() for all
- // errors, not just the latest one.
- throw new RuntimeException(queryJob.getStatus().getError().toString());
- }
- // [END bigquery_simple_app_query]
+ // Wait for the query to complete.
+ queryJob = queryJob.waitFor();
+
+ // Check for errors
+ if (queryJob == null) {
+ throw new RuntimeException("Job no longer exists");
+ } else if (queryJob.getStatus().getError() != null) {
+ // You can also look at queryJob.getStatus().getExecutionErrors() for all
+ // errors, not just the latest one.
+ throw new RuntimeException(queryJob.getStatus().getError().toString());
+ }
+ // [END bigquery_simple_app_query]
- // [START bigquery_simple_app_print]
- // Get the results.
- TableResult result = queryJob.getQueryResults();
+ // [START bigquery_simple_app_print]
+ // Get the results.
+ TableResult result = queryJob.getQueryResults();
- // Print all pages of the results.
- for (FieldValueList row : result.iterateAll()) {
- // String type
- String url = row.get("url").getStringValue();
- String viewCount = row.get("view_count").getStringValue();
- System.out.printf("%s : %s views\n", url, viewCount);
+ // Print all pages of the results.
+ for (FieldValueList row : result.iterateAll()) {
+ // String type
+ String url = row.get("url").getStringValue();
+ String viewCount = row.get("view_count").getStringValue();
+ System.out.printf("%s : %s views\n", url, viewCount);
+ }
+ } catch (BigQueryException | InterruptedException e) {
+ System.out.println("Simple App failed due to error: \n" + e.toString());
}
// [END bigquery_simple_app_print]
}
diff --git a/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java b/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java
index cfb77f1079..4c4030c7dc 100644
--- a/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java
+++ b/samples/snippets/src/test/java/com/example/bigquery/SimpleAppIT.java
@@ -17,6 +17,7 @@
package com.example.bigquery;
import static com.google.common.truth.Truth.assertThat;
+import static junit.framework.TestCase.assertNotNull;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
@@ -24,6 +25,7 @@
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -37,6 +39,20 @@ public class SimpleAppIT {
private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;
+ private static final String PROJECT_ID = requireEnvVar("GOOGLE_CLOUD_PROJECT");
+
+ private static String requireEnvVar(String varName) {
+ String value = System.getenv(varName);
+ assertNotNull(
+ "Environment variable " + varName + " is required to perform these tests.",
+ System.getenv(varName));
+ return value;
+ }
+
+ @BeforeClass
+ public static void checkRequirements() {
+ requireEnvVar("GOOGLE_CLOUD_PROJECT");
+ }
@Before
public void setUp() {
@@ -56,7 +72,7 @@ public void tearDown() {
@Test
public void testQuickstart() throws Exception {
- SimpleApp.main();
+ SimpleApp.simpleApp(PROJECT_ID);
String got = bout.toString();
assertThat(got).contains("https://stackoverflow.com/questions/");
}
diff --git a/versions.txt b/versions.txt
index 5ab44bc138..aa33dddd58 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,4 +1,4 @@
# Format:
# module:released-version:current-version
-google-cloud-bigquery:2.42.4:2.42.4
\ No newline at end of file
+google-cloud-bigquery:2.43.3:2.43.3
\ No newline at end of file