Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -608,18 +608,20 @@ public com.google.api.services.bigquery.model.Job call() throws IOException {
// If the Job ALREADY EXISTS, retrieve it.
Job job = this.getJob(jobInfo.getJobId(), JobOption.fields(JobField.STATISTICS));

long jobCreationTime = job.getStatistics().getCreationTime();
long jobMinStaleTime = System.currentTimeMillis();
long jobMaxStaleTime =
java.time.Instant.ofEpochMilli(jobMinStaleTime)
.minus(1, java.time.temporal.ChronoUnit.DAYS)
.toEpochMilli();

// Only return the job if it has been created in the past 24 hours.
// This is assuming any job older than 24 hours is a valid duplicate JobID
// and not a false positive like b/290419183
if (jobCreationTime >= jobMaxStaleTime && jobCreationTime <= jobMinStaleTime) {
return job;
if (job != null) {
long jobCreationTime = job.getStatistics().getCreationTime();
long jobMinStaleTime = System.currentTimeMillis();
long jobMaxStaleTime =
java.time.Instant.ofEpochMilli(jobMinStaleTime)
.minus(1, java.time.temporal.ChronoUnit.DAYS)
.toEpochMilli();

// Only return the job if it has been created in the past 24 hours.
// This is assuming any job older than 24 hours is a valid duplicate JobID
// and not a false positive like b/290419183
if (jobCreationTime >= jobMaxStaleTime && jobCreationTime <= jobMinStaleTime) {
return job;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,37 @@ void testCreateJobTryGetNotRandom() throws IOException {
any(String.class), eq(id), eq((String) null), eq(withStatisticOption));
}

@Test
void testCreateJobTryGetNotRandomJobNotFound() throws IOException {
Map<BigQueryRpc.Option, ?> withStatisticOption = optionMap(JobOption.fields(STATISTICS));
final String id = "testCreateJobTryGet-id";
String query = "SELECT * in FOO";

when(bigqueryRpcMock.createSkipExceptionTranslation(
jobCapture.capture(), eq(EMPTY_RPC_OPTIONS)))
.thenThrow(
new BigQueryException(
409,
"already exists, for some reason",
new RuntimeException("Already Exists: Job")));
when(bigqueryRpcMock.getJobSkipExceptionTranslation(
any(String.class), eq(id), eq((String) null), eq(withStatisticOption)))
.thenThrow(new BigQueryException(404, "Job not found"));

bigquery = options.getService();
BigQueryException exception =
Assertions.assertThrows(
BigQueryException.class,
() ->
((BigQueryImpl) bigquery)
.create(JobInfo.of(JobId.of(id), QueryJobConfiguration.of(query))));
assertEquals(409, exception.getCode());
assertEquals("already exists, for some reason", exception.getMessage());
verify(bigqueryRpcMock)
.getJobSkipExceptionTranslation(
any(String.class), eq(id), eq((String) null), eq(withStatisticOption));
}

@Test
void testCreateJobWithProjectId() throws IOException {
JobInfo jobInfo =
Expand Down
Loading