Skip to content

Commit 689ae5a

Browse files
committed
[BigQuery] Handle 409 Conflict in BigqueryClient dataset and table creation
1 parent cf3d6ed commit 689ae5a

1 file changed

Lines changed: 13 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: 13 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,12 @@ 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("Table {} already exists, treating as success.", newTable.getId());
522+
return;
523+
}
524+
lastException = e;
512525
} catch (IOException e) {
513526
// ignore and retry
514527
lastException = e;

0 commit comments

Comments
 (0)