Skip to content

Commit 4523eb1

Browse files
authored
---
yaml --- r: 8929 b: refs/heads/lesv-patch-1 c: d629d3e h: refs/heads/master i: 8927: 91e5c04
1 parent 858229b commit 4523eb1

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ refs/tags/v0.22.0: 18b298fe4bfe8ec2f20b0e0bf7ffdcce5cc3c5fe
6666
refs/heads/vam-google-patch-1: d0c8fee3a4074d0bf7360ce8c4f7f7223d0ee7b9
6767
refs/heads/vam-google-patch-CODEOWNERS: 2ac1616e25229e51d08a984708ef1918f91a35ee
6868
refs/heads/danoscarmike-patch-1: 7342a9916bce4ed00002c7202e2a16c5d46afaea
69-
refs/heads/lesv-patch-1: 344856459d28290b735f934e9c73b297a3a88ac5
69+
refs/heads/lesv-patch-1: d629d3e28582dbbcb2602e5aead26f7626265bf7
7070
refs/heads/ml-update-branch: 079dd6610017f5c51b9d1938c12d6d55b61513cf
7171
refs/heads/vkedia-patch-2: 7d8241388a9769a5c069334761b06c7012c878e7
7272
refs/heads/vkedia-patch-3: 4d128043acaa7db9160faf439d2ca6104e8a88cb

branches/lesv-patch-1/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ public TableResult query(QueryJobConfiguration configuration, JobOption... optio
596596
@Override
597597
public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption... options)
598598
throws InterruptedException, JobException {
599+
Job.checkNotDryRun(configuration, "query");
599600
return create(JobInfo.of(jobId, configuration), options).getQueryResults();
600601
}
601602

branches/lesv-patch-1/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Job.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public Job build() {
165165
* @throws BigQueryException upon failure
166166
*/
167167
public boolean exists() {
168+
checkNotDryRun("exists");
168169
return bigquery.getJob(getJobId(), JobOption.fields()) != null;
169170
}
170171

@@ -185,6 +186,7 @@ public boolean exists() {
185186
* @throws BigQueryException upon failure
186187
*/
187188
public boolean isDone() {
189+
checkNotDryRun("isDone");
188190
Job job = bigquery.getJob(getJobId(), JobOption.fields(BigQuery.JobField.STATUS));
189191
return job == null || job.getStatus().getState() == JobStatus.State.DONE;
190192
}
@@ -231,6 +233,7 @@ public boolean isDone() {
231233
* to complete
232234
*/
233235
public Job waitFor(RetryOption... waitOptions) throws InterruptedException {
236+
checkNotDryRun("waitFor");
234237
Object completedJobResponse;
235238
if (getConfiguration().getType() == Type.QUERY) {
236239
completedJobResponse =
@@ -268,6 +271,7 @@ public Job waitFor(RetryOption... waitOptions) throws InterruptedException {
268271
*/
269272
public TableResult getQueryResults(QueryResultsOption... options)
270273
throws InterruptedException, JobException {
274+
checkNotDryRun("getQueryResults");
271275
if (getConfiguration().getType() != Type.QUERY) {
272276
throw new UnsupportedOperationException(
273277
"Getting query results is supported only for " + Type.QUERY + " jobs");
@@ -389,6 +393,7 @@ public boolean shouldRetry(Throwable prevThrowable, Job prevResponse) {
389393
* @throws BigQueryException upon failure
390394
*/
391395
public Job reload(JobOption... options) {
396+
checkNotDryRun("reload");
392397
return bigquery.getJob(getJobId(), options);
393398
}
394399

@@ -410,9 +415,36 @@ public Job reload(JobOption... options) {
410415
* @throws BigQueryException upon failure
411416
*/
412417
public boolean cancel() {
418+
checkNotDryRun("cancel");
413419
return bigquery.cancel(getJobId());
414420
}
415421

422+
private void checkNotDryRun(String op) {
423+
checkNotDryRun(getConfiguration(), op);
424+
}
425+
426+
static void checkNotDryRun(JobConfiguration jobConfig, String op) {
427+
QueryJobConfiguration config;
428+
if (jobConfig instanceof QueryJobConfiguration) {
429+
config = (QueryJobConfiguration) jobConfig;
430+
} else {
431+
return;
432+
}
433+
434+
Boolean dryRun = config.dryRun();
435+
if (dryRun == null) {
436+
dryRun = false;
437+
}
438+
if (dryRun) {
439+
String msg =
440+
"Operation \"%s\" does not work for dryrun queries, "
441+
+ "since a dry run does not actually create a job. "
442+
+ "To validate a query and obtain some processing statistics, consider calling "
443+
+ "BigQuery.create(JobInfo).";
444+
throw new UnsupportedOperationException(String.format(msg, op));
445+
}
446+
}
447+
416448
/** Returns the job's {@code BigQuery} object used to issue requests. */
417449
public BigQuery getBigQuery() {
418450
return bigquery;

branches/lesv-patch-1/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryImplTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,4 +1400,17 @@ public void testRuntimeException() {
14001400
thrown.expectMessage(exceptionMessage);
14011401
bigquery.getDataset(DATASET);
14021402
}
1403+
1404+
@Test
1405+
public void testQueryDryRun() throws Exception {
1406+
// https://github.com/GoogleCloudPlatform/google-cloud-java/issues/2479
1407+
EasyMock.replay(bigqueryRpcMock);
1408+
thrown.expect(UnsupportedOperationException.class);
1409+
options
1410+
.toBuilder()
1411+
.setRetrySettings(ServiceOptions.getDefaultRetrySettings())
1412+
.build()
1413+
.getService()
1414+
.query(QueryJobConfiguration.newBuilder("foo").setDryRun(true).build());
1415+
}
14031416
}

0 commit comments

Comments
 (0)