Skip to content

Commit 47bebc3

Browse files
authored
[BigQuery] Handle 409 Conflict in BigqueryClient testing client for dataset and table creation
[BigQuery] Handle 409 Conflict in BigqueryClient testing client for dataset and table creation
2 parents bb43833 + f348cd0 commit 47bebc3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/testing

sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/testing/BigqueryClient.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkArgument;
2121
import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkState;
2222

23+
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
2324
import com.google.api.client.http.HttpTransport;
2425
import com.google.api.client.json.JsonFactory;
2526
import com.google.api.client.util.BackOff;
@@ -451,6 +452,12 @@ public void createNewDataset(
451452
new IOException(
452453
"Expected valid response from insert dataset job, but received null.");
453454
}
455+
} catch (GoogleJsonResponseException e) {
456+
if (e.getStatusCode() == 409) {
457+
LOG.info("Dataset {} already exists, treating as success.", datasetId);
458+
return;
459+
}
460+
lastException = e;
454461
} catch (IOException e) {
455462
// ignore and retry
456463
lastException = e;
@@ -509,6 +516,16 @@ public void createNewTable(String projectId, String datasetId, Table newTable)
509516
lastException =
510517
new IOException("Expected valid response from create table job, but received null.");
511518
}
519+
} catch (GoogleJsonResponseException e) {
520+
if (e.getStatusCode() == 409) {
521+
LOG.info(
522+
"Table {}:{}.{} already exists, treating as success.",
523+
projectId,
524+
datasetId,
525+
newTable.getTableReference().getTableId());
526+
return;
527+
}
528+
lastException = e;
512529
} catch (IOException e) {
513530
// ignore and retry
514531
lastException = e;

0 commit comments

Comments
 (0)