From 9a6e0007a2ea7ba3f152d2e7b765745e7a714648 Mon Sep 17 00:00:00 2001 From: abhinav Date: Mon, 8 Apr 2019 16:50:53 +0530 Subject: [PATCH 1/4] close write channel --- .../cloud/examples/bigquery/snippets/BigQuerySnippets.java | 2 ++ 1 file changed, 2 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 f0c91d62344c..0569b3ef82cf 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,6 +383,8 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath, // Write data to writer try (OutputStream stream = Channels.newOutputStream(writer)) { Files.copy(csvPath, stream); + } finally { + writer.close(); } // Get load job Job job = writer.getJob(); From 2ea74d53351ce1bc40c9f60a991450a4249d140f Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Mon, 8 Apr 2019 08:46:32 -0400 Subject: [PATCH 2/4] Update BigQuerySnippets.java --- .../cloud/examples/bigquery/snippets/BigQuerySnippets.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 0569b3ef82cf..73aa811e7801 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 @@ -379,12 +379,11 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath, 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)) { + try (TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration); + OutputStream stream = Channels.newOutputStream(writer)) { Files.copy(csvPath, stream); - } finally { - writer.close(); } // Get load job Job job = writer.getJob(); From b1684a3c127fa620e259c1b6ade0447bb126f754 Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Mon, 8 Apr 2019 09:26:32 -0400 Subject: [PATCH 3/4] Update BigQuerySnippets.java --- .../cloud/examples/bigquery/snippets/BigQuerySnippets.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 73aa811e7801..7b01b59ef4f5 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 @@ -379,12 +379,15 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath, 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 (TableDataWriteChannel writer = bigquery.writer(jobId, writeChannelConfiguration); - OutputStream stream = Channels.newOutputStream(writer)) { + try (OutputStream stream = Channels.newOutputStream(writer)) { Files.copy(csvPath, stream); + } finally { + writer.close(); } + // Get load job Job job = writer.getJob(); job = job.waitFor(); From ddc4bd10a52a8ce25a98ff763e428b2497ebe765 Mon Sep 17 00:00:00 2001 From: Solomon Duskis Date: Mon, 8 Apr 2019 10:56:24 -0400 Subject: [PATCH 4/4] Update BigQuerySnippets.java --- .../cloud/examples/bigquery/snippets/BigQuerySnippets.java | 2 -- 1 file changed, 2 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 7b01b59ef4f5..0569b3ef82cf 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 @@ -380,14 +380,12 @@ public long writeFileToTable(String datasetName, String tableName, Path csvPath, // 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); } finally { writer.close(); } - // Get load job Job job = writer.getJob(); job = job.waitFor();