Skip to content

Commit 793eeb7

Browse files
authored
---
yaml --- r: 28881 b: refs/heads/autosynth-dlp c: f482707 h: refs/heads/master i: 28879: 64fb085
1 parent a4ed2be commit 793eeb7

3 files changed

Lines changed: 9 additions & 71 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ refs/tags/v0.60.0: 4cd518d0612329f8a8e53484eef4cd1651e32855
103103
refs/tags/v0.61.0: e4b526656bb1bf5eefd0ee578b7405147821225e
104104
refs/tags/v0.62.0: bbede7385d48ba08f487bdd29ec10668ace96396
105105
refs/heads/0.60.0-alpha: 10939381ffe0b8da32db4fe3087c86e3aa7f3e55
106-
refs/heads/autosynth-dlp: fb9bdca25d73760cb73be7e4c00508ceafa04d1e
106+
refs/heads/autosynth-dlp: f482707df9e83f76941e24453f121b8973ceab30
107107
refs/heads/autosynth-logging: eca54b98c8cf82050bbdfc5c19139673dff9e5b8
108108
refs/heads/dupes: 3478c5d81fd242d0e985656645a679420a2060c2
109109
refs/tags/v0.63.0: 94f19b71d40f46b36120e7b9d78a1a3d41bfcbd6

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

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
package com.google.cloud.examples.bigquery.snippets;
2424

25-
import com.google.api.client.util.Charsets;
2625
import com.google.api.gax.paging.Page;
2726
import com.google.cloud.bigquery.BigQuery;
2827
import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption;
@@ -61,7 +60,6 @@
6160
import com.google.cloud.bigquery.WriteChannelConfiguration;
6261
import java.io.IOException;
6362
import java.io.OutputStream;
64-
import java.nio.ByteBuffer;
6563
import java.nio.channels.Channels;
6664
import java.nio.file.Files;
6765
import java.nio.file.Path;
@@ -310,62 +308,6 @@ public Table getTableFromId(String projectId, String datasetName, String tableNa
310308
return table;
311309
}
312310

313-
/** Example of creating a channel with which to write to a table. */
314-
// [TARGET writer(WriteChannelConfiguration)]
315-
// [VARIABLE "my_dataset_name"]
316-
// [VARIABLE "my_table_name"]
317-
// [VARIABLE "StringValue1\nStringValue2\n"]
318-
public long writeToTable(String datasetName, String tableName, String csvData)
319-
throws IOException, InterruptedException, TimeoutException {
320-
// [START ]
321-
TableId tableId = TableId.of(datasetName, tableName);
322-
WriteChannelConfiguration writeChannelConfiguration =
323-
WriteChannelConfiguration.newBuilder(tableId).setFormatOptions(FormatOptions.csv()).build();
324-
TableDataWriteChannel writer = bigquery.writer(writeChannelConfiguration);
325-
// Write data to writer
326-
try {
327-
writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
328-
} finally {
329-
writer.close();
330-
}
331-
// Get load job
332-
Job job = writer.getJob();
333-
job = job.waitFor();
334-
LoadStatistics stats = job.getStatistics();
335-
return stats.getOutputRows();
336-
// [END ]
337-
}
338-
339-
/** Example of creating a channel with which to write to a table. */
340-
// [TARGET writer(JobId, WriteChannelConfiguration)]
341-
// [VARIABLE "my_dataset_name"]
342-
// [VARIABLE "my_table_name"]
343-
// [VARIABLE "StringValue1\nStringValue2\n"]
344-
// [VARIABLE "us"]
345-
public long writeToTableLocation(
346-
String datasetName, String tableName, String csvData, String location)
347-
throws IOException, InterruptedException, TimeoutException {
348-
// [START ]
349-
TableId tableId = TableId.of(datasetName, tableName);
350-
WriteChannelConfiguration writeChannelConfiguration =
351-
WriteChannelConfiguration.newBuilder(tableId).setFormatOptions(FormatOptions.csv()).build();
352-
// The location must be specified; other fields can be auto-detected.
353-
JobId jobId = JobId.newBuilder().setLocation(location).build();
354-
TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
355-
// Write data to writer
356-
try {
357-
writer.write(ByteBuffer.wrap(csvData.getBytes(Charsets.UTF_8)));
358-
} finally {
359-
writer.close();
360-
}
361-
// Get load job
362-
Job job = writer.getJob();
363-
job = job.waitFor();
364-
LoadStatistics stats = job.getStatistics();
365-
return stats.getOutputRows();
366-
// [END ]
367-
}
368-
369311
/** Example of writing a local file to a table. */
370312
// [TARGET writer(WriteChannelConfiguration)]
371313
// [VARIABLE "my_dataset_name"]
@@ -378,7 +320,10 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath,
378320
TableId tableId = TableId.of(datasetName, tableName);
379321
WriteChannelConfiguration writeChannelConfiguration =
380322
WriteChannelConfiguration.newBuilder(tableId).setFormatOptions(FormatOptions.csv()).build();
381-
// The location must be specified; other fields can be auto-detected.
323+
// Generally, location can be inferred based on the location of the referenced dataset.
324+
// However,
325+
// it can also be set explicitly to force job execution to be routed to a specific processing
326+
// location. See https://cloud.google.com/bigquery/docs/locations for more info.
382327
JobId jobId = JobId.newBuilder().setLocation(location).build();
383328
TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration);
384329
// Write data to writer

branches/autosynth-dlp/google-cloud-examples/src/test/java/com/google/cloud/examples/bigquery/snippets/ITBigQuerySnippets.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,34 +212,27 @@ public void testWriteAndListTableData()
212212
String tableName = "test_write_and_list_table_data";
213213
String fieldName = "string_field";
214214
assertNotNull(bigquerySnippets.createTable(DATASET, tableName, fieldName));
215-
// Add rows from string
216-
long outputRows =
217-
bigquerySnippets.writeToTable(DATASET, tableName, "StringValue1\nStringValue2\n");
218-
assertEquals(2L, outputRows);
219215
// Add rows from file
220216
Path csvPath =
221217
Paths.get(Resources.getResource("bigquery/test_write_and_list_table_data.csv").toURI());
222-
outputRows = bigquerySnippets.writeFileToTable(DATASET, tableName, csvPath, "us");
218+
long outputRows = bigquerySnippets.writeFileToTable(DATASET, tableName, csvPath, "us");
223219
assertEquals(2L, outputRows);
224220
// List all rows
225221
TableResult tableData = bigquerySnippets.listTableData(DATASET, tableName);
226222
String tableDataString = tableData.toString();
227-
assertTrue(tableDataString.contains("StringValue1"));
228-
assertTrue(tableDataString.contains("StringValue2"));
229223
assertTrue(tableDataString.contains("StringValue3"));
230224
assertTrue(tableDataString.contains("StringValue4"));
231225
assertTrue(bigquerySnippets.deleteTable(DATASET, tableName));
232226
}
233227

234228
@Test
235229
public void testWriteRemoteJsonToTable() throws InterruptedException {
236-
String datasetName = "test_dataset";
237230
String tableName = "us_states";
238-
Table table = bigquery.getTable(datasetName, tableName);
231+
Table table = bigquery.getTable(DATASET, tableName);
239232
assertNull(table);
240233

241-
Long result = bigquerySnippets.writeRemoteFileToTable(datasetName, tableName);
242-
table = bigquery.getTable(datasetName, tableName);
234+
Long result = bigquerySnippets.writeRemoteFileToTable(DATASET, tableName);
235+
table = bigquery.getTable(DATASET, tableName);
243236
assertNotNull(table);
244237
ArrayList<String> tableFieldNames = new ArrayList<>();
245238
for (Field field : table.getDefinition().getSchema().getFields()) {

0 commit comments

Comments
 (0)