Skip to content

Commit fbe1aeb

Browse files
committed
Update BigQuery snippets to use renamed getters/setters/builders
1 parent 127d11e commit fbe1aeb

15 files changed

Lines changed: 158 additions & 146 deletions

File tree

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
443443
* <pre> {@code
444444
* String datasetName = "my_dataset_name";
445445
* Dataset dataset = null;
446-
* DatasetInfo datasetInfo = DatasetInfo.builder(datasetName).build();
446+
* DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
447447
* try {
448448
* // the dataset was created
449449
* dataset = bigquery.create(datasetInfo);
@@ -470,7 +470,7 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
470470
* // Table schema definition
471471
* Schema schema = Schema.of(field);
472472
* TableDefinition tableDefinition = StandardTableDefinition.of(schema);
473-
* TableInfo tableInfo = TableInfo.builder(tableId, tableDefinition).build();
473+
* TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
474474
* Table table = bigquery.create(tableInfo);
475475
* }</pre>
476476
*
@@ -659,7 +659,7 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
659659
* String datasetName = "my_dataset_name";
660660
* String newFriendlyName = "some_new_friendly_name";
661661
* Dataset oldDataset = bigquery.getDataset(datasetName);
662-
* DatasetInfo datasetInfo = oldDataset.toBuilder().friendlyName(newFriendlyName).build();
662+
* DatasetInfo datasetInfo = oldDataset.toBuilder().setFriendlyName(newFriendlyName).build();
663663
* Dataset newDataset = bigquery.update(datasetInfo);
664664
* }</pre>
665665
*
@@ -676,7 +676,7 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
676676
* String tableName = "my_table_name";
677677
* String newFriendlyName = "new_friendly_name";
678678
* Table oldTable = bigquery.getTable(datasetName, tableName);
679-
* TableInfo tableInfo = oldTable.toBuilder().friendlyName(newFriendlyName).build();
679+
* TableInfo tableInfo = oldTable.toBuilder().setFriendlyName(newFriendlyName).build();
680680
* Table newTable = bigquery.update(tableInfo);
681681
* }</pre>
682682
*
@@ -773,13 +773,13 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
773773
* rowContent.put("booleanField", true);
774774
* // Bytes are passed in base64
775775
* rowContent.put("bytesField", "DQ4KDQ==");
776-
* InsertAllResponse response = bigquery.insertAll(InsertAllRequest.builder(tableId)
776+
* InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId)
777777
* .addRow("rowId", rowContent)
778778
* // More rows can be added in the same RPC by invoking .addRow() on the builder
779779
* .build());
780780
* if (response.hasErrors()) {
781781
* // If any of the insertions failed, this lets you inspect the errors
782-
* for (Entry<Long, List<BigQueryError>> entry : response.insertErrors().entrySet()) {
782+
* for (Entry<Long, List<BigQueryError>> entry : response.getInsertErrors().entrySet()) {
783783
* // inspect row error
784784
* }
785785
* }
@@ -937,12 +937,12 @@ Page<List<FieldValue>> listTableData(String datasetId, String tableId,
937937
* // Wait for things to finish
938938
* while (!response.jobCompleted()) {
939939
* Thread.sleep(1000);
940-
* response = bigquery.getQueryResults(response.jobId());
940+
* response = bigquery.getQueryResults(response.getJobId());
941941
* }
942942
* if (response.hasErrors()) {
943943
* // handle errors
944944
* }
945-
* QueryResult result = response.result();
945+
* QueryResult result = response.getResult();
946946
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
947947
* while (rowIterator.hasNext()) {
948948
* List<FieldValue> row = rowIterator.next();
@@ -965,12 +965,12 @@ Page<List<FieldValue>> listTableData(String datasetId, String tableId,
965965
* // Wait for things to finish
966966
* while (!response.jobCompleted()) {
967967
* Thread.sleep(1000);
968-
* response = bigquery.getQueryResults(response.jobId());
968+
* response = bigquery.getQueryResults(response.getJobId());
969969
* }
970970
* if (response.hasErrors()) {
971971
* // handle errors
972972
* }
973-
* QueryResult result = response.result();
973+
* QueryResult result = response.getResult();
974974
* Iterator<List<FieldValue>> rowIterator = result.iterateAll();
975975
* while (rowIterator.hasNext()) {
976976
* List<FieldValue> row = rowIterator.next();
@@ -993,7 +993,9 @@ Page<List<FieldValue>> listTableData(String datasetId, String tableId,
993993
* String csvData = "StringValue1\nStringValue2\n";
994994
* TableId tableId = TableId.of(datasetName, tableName);
995995
* WriteChannelConfiguration writeChannelConfiguration =
996-
* WriteChannelConfiguration.builder(tableId).formatOptions(FormatOptions.csv()).build();
996+
* WriteChannelConfiguration.newBuilder(tableId)
997+
* .setFormatOptions(FormatOptions.csv())
998+
* .build();
997999
* BaseWriteChannel<BigQueryOptions, WriteChannelConfiguration> writer =
9981000
* bigquery.writer(writeChannelConfiguration);
9991001
* // Write data to writer

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Dataset.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public Dataset reload(DatasetOption... options) {
232232
* <pre> {@code
233233
* String friendlyName = "my_friendly_name";
234234
* Builder builder = dataset.toBuilder();
235-
* builder.friendlyName(friendlyName);
235+
* builder.setFriendlyName(friendlyName);
236236
* Dataset updatedDataset = builder.build().update();
237237
* }</pre>
238238
*
@@ -309,9 +309,9 @@ public Table get(String tableId, TableOption... options) {
309309
* String tableName = “my_table”;
310310
* String fieldName = “my_field”;
311311
* Schema schema = Schema.of(Field.of(fieldName, Type.string()));
312-
* StandardTableDefinition definition = StandardTableDefinition.builder()
313-
* .schema(schema)
314-
* .timePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY))
312+
* StandardTableDefinition definition = StandardTableDefinition.newBuilder()
313+
* .setSchema(schema)
314+
* .setTimePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY))
315315
* .build();
316316
* Table table = dataset.create(tableName, definition);
317317
* }</pre>

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public boolean isDone() {
187187
* Job completedJob = job.waitFor();
188188
* if (completedJob == null) {
189189
* // job no longer exists
190-
* } else if (completedJob.status().error() != null) {
190+
* } else if (completedJob.getStatus().getError() != null) {
191191
* // job failed, handle error
192192
* } else {
193193
* // job completed successfully
@@ -202,7 +202,7 @@ public boolean isDone() {
202202
* WaitForOption.timeout(60, TimeUnit.SECONDS));
203203
* if (completedJob == null) {
204204
* // job no longer exists
205-
* } else if (completedJob.status().error() != null) {
205+
* } else if (completedJob.getStatus().getError() != null) {
206206
* // job failed, handle error
207207
* } else {
208208
* // job completed successfully
@@ -237,15 +237,15 @@ public Job waitFor(WaitForOption... waitOptions) throws InterruptedException, Ti
237237
*
238238
* <p>Example of reloading all fields until job status is DONE.
239239
* <pre> {@code
240-
* while (job.status().state() != JobStatus.State.DONE) {
240+
* while (job.getStatus().getState() != JobStatus.State.DONE) {
241241
* Thread.sleep(1000L);
242242
* job = job.reload();
243243
* }
244244
* }</pre>
245245
*
246246
* <p>Example of reloading status field until job status is DONE.
247247
* <pre> {@code
248-
* while (job.status().state() != JobStatus.State.DONE) {
248+
* while (job.getStatus().getState() != JobStatus.State.DONE) {
249249
* Thread.sleep(1000L);
250250
* job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS));
251251
* }

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Table.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public Table reload(TableOption... options) {
219219
*
220220
* <p>Example of updating the table's information.
221221
* <pre> {@code
222-
* Table updatedTable = table.toBuilder().description("new description").build().update();
222+
* Table updatedTable = table.toBuilder().setDescription("new description").build().update();
223223
* }</pre>
224224
*
225225
* @param options dataset options
@@ -349,7 +349,7 @@ public Page<List<FieldValue>> list(TableDataListOption... options)
349349
* try {
350350
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
351351
* WaitForOption.timeout(3, TimeUnit.MINUTES));
352-
* if (completedJob != null && completedJob.status().error() == null) {
352+
* if (completedJob != null && completedJob.getStatus().getError() == null) {
353353
* // Job completed successfully
354354
* } else {
355355
* // Handle error case
@@ -384,7 +384,7 @@ public Job copy(String destinationDataset, String destinationTable, JobOption...
384384
* try {
385385
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
386386
* WaitForOption.timeout(3, TimeUnit.MINUTES));
387-
* if (completedJob != null && completedJob.status().error() == null) {
387+
* if (completedJob != null && completedJob.getStatus().getError() == null) {
388388
* // Job completed successfully.
389389
* } else {
390390
* // Handle error case.
@@ -417,7 +417,7 @@ public Job copy(TableId destinationTable, JobOption... options)
417417
* try {
418418
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
419419
* WaitForOption.timeout(3, TimeUnit.MINUTES));
420-
* if (completedJob != null && completedJob.status().error() == null) {
420+
* if (completedJob != null && completedJob.getStatus().getError() == null) {
421421
* // Job completed successfully
422422
* } else {
423423
* // Handle error case
@@ -455,7 +455,7 @@ public Job extract(String format, String destinationUri, JobOption... options)
455455
* try {
456456
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
457457
* WaitForOption.timeout(3, TimeUnit.MINUTES));
458-
* if (completedJob != null && completedJob.status().error() == null) {
458+
* if (completedJob != null && completedJob.getStatus().getError() == null) {
459459
* // Job completed successfully
460460
* } else {
461461
* // Handle error case
@@ -490,7 +490,7 @@ public Job extract(String format, List<String> destinationUris, JobOption... opt
490490
* try {
491491
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
492492
* WaitForOption.timeout(3, TimeUnit.MINUTES));
493-
* if (completedJob != null && completedJob.status().error() == null) {
493+
* if (completedJob != null && completedJob.getStatus().getError() == null) {
494494
* // Job completed successfully
495495
* } else {
496496
* // Handle error case
@@ -527,7 +527,7 @@ public Job load(FormatOptions format, String sourceUri, JobOption... options)
527527
* try {
528528
* Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS),
529529
* WaitForOption.timeout(3, TimeUnit.MINUTES));
530-
* if (completedJob != null && completedJob.status().error() == null) {
530+
* if (completedJob != null && completedJob.getStatus().getError() == null) {
531531
* // Job completed successfully
532532
* } else {
533533
* // Handle error case

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/BigQueryExample.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public void run(BigQuery bigquery, DatasetId datasetId) {
237237
private static class CreateDatasetAction extends DatasetAction {
238238
@Override
239239
public void run(BigQuery bigquery, DatasetId datasetId) {
240-
bigquery.create(DatasetInfo.builder(datasetId).build());
240+
bigquery.create(DatasetInfo.newBuilder(datasetId).build());
241241
System.out.println("Created dataset " + datasetId);
242242
}
243243
}
@@ -396,7 +396,7 @@ void run(BigQuery bigquery, TableInfo table) throws Exception {
396396
}
397397

398398
static Schema parseSchema(String[] args, int start, int end) {
399-
Schema.Builder builder = Schema.builder();
399+
Schema.Builder builder = Schema.newBuilder();
400400
for (int i = start; i < end; i++) {
401401
String[] fieldsArray = args[i].split(":");
402402
if (fieldsArray.length != 2) {
@@ -523,15 +523,15 @@ void run(BigQuery bigquery, JobInfo job) throws Exception {
523523
System.out.println("Creating job");
524524
Job startedJob = bigquery.create(job);
525525
while (!startedJob.isDone()) {
526-
System.out.println("Waiting for job " + startedJob.jobId().job() + " to complete");
526+
System.out.println("Waiting for job " + startedJob.getJobId().getJob() + " to complete");
527527
Thread.sleep(1000L);
528528
}
529529
startedJob = startedJob.reload();
530-
if (startedJob.status().error() == null) {
531-
System.out.println("Job " + startedJob.jobId().job() + " succeeded");
530+
if (startedJob.getStatus().getError() == null) {
531+
System.out.println("Job " + startedJob.getJobId().getJob() + " succeeded");
532532
} else {
533-
System.out.println("Job " + startedJob.jobId().job() + " failed");
534-
System.out.println("Error: " + startedJob.status().error());
533+
System.out.println("Job " + startedJob.getJobId().getJob() + " failed");
534+
System.out.println("Error: " + startedJob.getStatus().getError());
535535
}
536536
}
537537
}
@@ -627,19 +627,19 @@ void run(BigQuery bigquery, QueryRequest queryRequest) throws Exception {
627627
System.out.println("Running query");
628628
QueryResponse queryResponse = bigquery.query(queryRequest);
629629
while (!queryResponse.jobCompleted()) {
630-
System.out.println("Waiting for query job " + queryResponse.jobId() + " to complete");
630+
System.out.println("Waiting for query job " + queryResponse.getJobId() + " to complete");
631631
Thread.sleep(1000L);
632-
queryResponse = bigquery.getQueryResults(queryResponse.jobId());
632+
queryResponse = bigquery.getQueryResults(queryResponse.getJobId());
633633
}
634634
if (!queryResponse.hasErrors()) {
635635
System.out.println("Query succeeded. Results:");
636-
Iterator<List<FieldValue>> iterator = queryResponse.result().iterateAll();
636+
Iterator<List<FieldValue>> iterator = queryResponse.getResult().iterateAll();
637637
while (iterator.hasNext()) {
638638
System.out.println(iterator.next());
639639
}
640640
} else {
641641
System.out.println("Query completed with errors. Errors:");
642-
for (BigQueryError err : queryResponse.executionErrors()) {
642+
for (BigQueryError err : queryResponse.getExecutionErrors()) {
643643
System.out.println(err);
644644
}
645645
}

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/BigQuerySnippets.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public BigQuerySnippets(BigQuery bigquery) {
8585
public Dataset createDataset(String datasetName) {
8686
// [START createDataset]
8787
Dataset dataset = null;
88-
DatasetInfo datasetInfo = DatasetInfo.builder(datasetName).build();
88+
DatasetInfo datasetInfo = DatasetInfo.newBuilder(datasetName).build();
8989
try {
9090
// the dataset was created
9191
dataset = bigquery.create(datasetInfo);
@@ -105,7 +105,7 @@ public Dataset createDataset(String datasetName) {
105105
public Dataset updateDataset(String datasetName, String newFriendlyName) {
106106
// [START updateDataset]
107107
Dataset oldDataset = bigquery.getDataset(datasetName);
108-
DatasetInfo datasetInfo = oldDataset.toBuilder().friendlyName(newFriendlyName).build();
108+
DatasetInfo datasetInfo = oldDataset.toBuilder().setFriendlyName(newFriendlyName).build();
109109
Dataset newDataset = bigquery.update(datasetInfo);
110110
// [END updateDataset]
111111
return newDataset;
@@ -121,7 +121,7 @@ public Dataset updateDataset(String datasetName, String newFriendlyName) {
121121
public Table updateTable(String datasetName, String tableName, String newFriendlyName) {
122122
// [START updateTable]
123123
Table oldTable = bigquery.getTable(datasetName, tableName);
124-
TableInfo tableInfo = oldTable.toBuilder().friendlyName(newFriendlyName).build();
124+
TableInfo tableInfo = oldTable.toBuilder().setFriendlyName(newFriendlyName).build();
125125
Table newTable = bigquery.update(tableInfo);
126126
// [END updateTable]
127127
return newTable;
@@ -337,7 +337,9 @@ public BaseWriteChannel<BigQueryOptions, WriteChannelConfiguration> writeToTable
337337
// [START writeToTable]
338338
TableId tableId = TableId.of(datasetName, tableName);
339339
WriteChannelConfiguration writeChannelConfiguration =
340-
WriteChannelConfiguration.builder(tableId).formatOptions(FormatOptions.csv()).build();
340+
WriteChannelConfiguration.newBuilder(tableId)
341+
.setFormatOptions(FormatOptions.csv())
342+
.build();
341343
BaseWriteChannel<BigQueryOptions, WriteChannelConfiguration> writer =
342344
bigquery.writer(writeChannelConfiguration);
343345
// Write data to writer
@@ -365,13 +367,13 @@ public InsertAllResponse insertAll(String datasetName, String tableName) {
365367
rowContent.put("booleanField", true);
366368
// Bytes are passed in base64
367369
rowContent.put("bytesField", "DQ4KDQ==");
368-
InsertAllResponse response = bigquery.insertAll(InsertAllRequest.builder(tableId)
370+
InsertAllResponse response = bigquery.insertAll(InsertAllRequest.newBuilder(tableId)
369371
.addRow("rowId", rowContent)
370372
// More rows can be added in the same RPC by invoking .addRow() on the builder
371373
.build());
372374
if (response.hasErrors()) {
373375
// If any of the insertions failed, this lets you inspect the errors
374-
for (Entry<Long, List<BigQueryError>> entry : response.insertErrors().entrySet()) {
376+
for (Entry<Long, List<BigQueryError>> entry : response.getInsertErrors().entrySet()) {
375377
// inspect row error
376378
}
377379
}
@@ -394,7 +396,7 @@ public Table createTable(String datasetName, String tableName, String fieldName)
394396
// Table schema definition
395397
Schema schema = Schema.of(field);
396398
TableDefinition tableDefinition = StandardTableDefinition.of(schema);
397-
TableInfo tableInfo = TableInfo.builder(tableId, tableDefinition).build();
399+
TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build();
398400
Table table = bigquery.create(tableInfo);
399401
// [END createTable]
400402
return table;
@@ -553,12 +555,12 @@ public QueryResponse runQuery(String query) throws InterruptedException {
553555
// Wait for things to finish
554556
while (!response.jobCompleted()) {
555557
Thread.sleep(1000);
556-
response = bigquery.getQueryResults(response.jobId());
558+
response = bigquery.getQueryResults(response.getJobId());
557559
}
558560
if (response.hasErrors()) {
559561
// handle errors
560562
}
561-
QueryResult result = response.result();
563+
QueryResult result = response.getResult();
562564
Iterator<List<FieldValue>> rowIterator = result.iterateAll();
563565
while (rowIterator.hasNext()) {
564566
List<FieldValue> row = rowIterator.next();
@@ -580,12 +582,12 @@ public QueryResponse queryResults(final String query) throws InterruptedExceptio
580582
// Wait for things to finish
581583
while (!response.jobCompleted()) {
582584
Thread.sleep(1000);
583-
response = bigquery.getQueryResults(response.jobId());
585+
response = bigquery.getQueryResults(response.getJobId());
584586
}
585587
if (response.hasErrors()) {
586588
// handle errors
587589
}
588-
QueryResult result = response.result();
590+
QueryResult result = response.getResult();
589591
Iterator<List<FieldValue>> rowIterator = result.iterateAll();
590592
while (rowIterator.hasNext()) {
591593
List<FieldValue> row = rowIterator.next();

google-cloud-examples/src/main/java/com/google/cloud/examples/bigquery/snippets/CreateTableAndLoadData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void main(String... args) throws InterruptedException, TimeoutExce
5555
System.out.println("Loading data into table " + tableId);
5656
Job loadJob = table.load(FormatOptions.csv(), "gs://bucket/path");
5757
loadJob = loadJob.waitFor();
58-
if (loadJob.status().error() != null) {
58+
if (loadJob.getStatus().getError() != null) {
5959
System.out.println("Job completed with errors");
6060
} else {
6161
System.out.println("Job succeeded");

0 commit comments

Comments
 (0)