Skip to content
Prev Previous commit
Next Next commit
update exception handling
  • Loading branch information
stephaniewang526 committed Jan 22, 2020
commit c3dc47cb2c7c331401c39cdbe59e00d0978746eb
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@

public class AddColumnLoadAppend {

public static void runAddColumnLoadAppend() {
public static void runAddColumnLoadAppend() throws Exception {
// TODO(developer): Replace these variables before running the sample.
String datasetName = "MY_DATASET_NAME";
String tableName = "MY_TABLE_NAME";
String sourceUri = "/path/to/file.csv";
addColumnLoadAppend(datasetName, tableName, sourceUri);
}

public static void addColumnLoadAppend(String datasetName, String tableName, String sourceUri) {
public static void addColumnLoadAppend(String datasetName, String tableName, String sourceUri)
throws Exception {
try {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests.
Expand Down Expand Up @@ -91,10 +92,9 @@ public static void addColumnLoadAppend(String datasetName, String tableName, Str
} else if (completedJob.getStatus().getError() != null) {
// You can also look at queryJob.getStatus().getExecutionErrors() for all
// errors, not just the latest one.
System.out.println(
throw new Exception(
"BigQuery was unable to load into the table due to an error: \n"
+ loadJob.getStatus().getError());
return;
}

System.out.println("Column successfully added during load append job");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void tearDown() {
}

@Test
public void testAddColumnLoadAppend() {
public void testAddColumnLoadAppend() throws Exception {
String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv";

String tableName = "ADD_COLUMN_LOAD_APPEND_TEST";
Expand Down