From 8b579c13ef6da3e8e0bdc988701e75778185cae9 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Wed, 12 Oct 2022 18:43:32 -0400 Subject: [PATCH 01/15] feat: add fast query path support with job location --- .../java/com/google/cloud/bigquery/BigQueryImpl.java | 10 +++++++++- .../com/google/cloud/bigquery/QueryRequestInfo.java | 6 ++++-- .../google/cloud/bigquery/QueryRequestInfoTest.java | 8 ++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 3cfbfd652..5d4a877ce 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1294,7 +1294,7 @@ public TableResult query(QueryJobConfiguration configuration, JobOption... optio // If all parameters passed in configuration are supported by the query() method on the backend, // put on fast path QueryRequestInfo requestInfo = new QueryRequestInfo(configuration); - if (requestInfo.isFastQuerySupported()) { + if (requestInfo.isFastQuerySupported(null)) { String projectId = getOptions().getProjectId(); QueryRequest content = requestInfo.toPb(); return queryRpc(projectId, content, options); @@ -1379,6 +1379,14 @@ public com.google.api.services.bigquery.model.QueryResponse call() { public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOption... options) throws InterruptedException, JobException { Job.checkNotDryRun(configuration, "query"); + // If all parameters passed in configuration are supported by the query() method on the backend, + // put on fast path + QueryRequestInfo requestInfo = new QueryRequestInfo(configuration); + if (requestInfo.isFastQuerySupported(jobId)) { + String projectId = getOptions().getProjectId(); + QueryRequest content = requestInfo.toPb(); + return queryRpc(projectId, content, options); + } return create(JobInfo.of(jobId, configuration), options).getQueryResults(); } diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index ccde465af..d0bca424a 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -57,7 +57,7 @@ final class QueryRequestInfo { this.useQueryCache = config.useQueryCache(); } - boolean isFastQuerySupported() { + boolean isFastQuerySupported(JobId jobId) { return config.getClustering() == null && config.getCreateDisposition() == null && config.getDestinationEncryptionConfiguration() == null @@ -70,7 +70,9 @@ boolean isFastQuerySupported() { && config.getTableDefinitions() == null && config.getTimePartitioning() == null && config.getUserDefinedFunctions() == null - && config.getWriteDisposition() == null; + && config.getWriteDisposition() == null + && jobId.getJob() == null + && jobId.getLocation() !=null ; } QueryRequest toPb() { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java index a62e3c0a0..95f4587cb 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java @@ -150,8 +150,12 @@ public class QueryRequestInfoTest { @Test public void testIsFastQuerySupported() { - assertEquals(false, REQUEST_INFO.isFastQuerySupported()); - assertEquals(true, REQUEST_INFO_SUPPORTED.isFastQuerySupported()); + JobId jobIdSupported = JobId.newBuilder().setLocation("US").build(); + JobId jobIdNotSupported = JobId.newBuilder().setJob("random-job-id").build(); + assertEquals(false, REQUEST_INFO.isFastQuerySupported(jobIdSupported)); + assertEquals(true, REQUEST_INFO_SUPPORTED.isFastQuerySupported(jobIdSupported)); + assertEquals(false, REQUEST_INFO.isFastQuerySupported(jobIdNotSupported)); + assertEquals(false, REQUEST_INFO_SUPPORTED.isFastQuerySupported(jobIdNotSupported)); } @Test From 29231ec1051c3db0250d91eba926f4773c1448e9 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 12 Oct 2022 22:45:49 +0000 Subject: [PATCH 02/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../main/java/com/google/cloud/bigquery/QueryRequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index d0bca424a..027293ec8 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -72,7 +72,7 @@ boolean isFastQuerySupported(JobId jobId) { && config.getUserDefinedFunctions() == null && config.getWriteDisposition() == null && jobId.getJob() == null - && jobId.getLocation() !=null ; + && jobId.getLocation() != null; } QueryRequest toPb() { From e32bd91b81c4023b26df8ca83b0967955913e17a Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Wed, 12 Oct 2022 21:14:37 -0400 Subject: [PATCH 03/15] chore: fix NPE --- .../com/google/cloud/bigquery/QueryRequestInfo.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index 027293ec8..fe1b4df34 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -58,6 +58,13 @@ final class QueryRequestInfo { } boolean isFastQuerySupported(JobId jobId) { + boolean isJobId; + // Fast query path is not possible if jobId is specified + if( jobId != null) { + isJobId = jobId.getJob() == null; + } else { + isJobId = true; + } return config.getClustering() == null && config.getCreateDisposition() == null && config.getDestinationEncryptionConfiguration() == null @@ -71,8 +78,7 @@ boolean isFastQuerySupported(JobId jobId) { && config.getTimePartitioning() == null && config.getUserDefinedFunctions() == null && config.getWriteDisposition() == null - && jobId.getJob() == null - && jobId.getLocation() != null; + && isJobId; } QueryRequest toPb() { From 0909c943d61b021d4dc024e5ea928088738bc0ac Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 13 Oct 2022 01:17:05 +0000 Subject: [PATCH 04/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../main/java/com/google/cloud/bigquery/QueryRequestInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index fe1b4df34..9c1e94f4d 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -60,7 +60,7 @@ final class QueryRequestInfo { boolean isFastQuerySupported(JobId jobId) { boolean isJobId; // Fast query path is not possible if jobId is specified - if( jobId != null) { + if (jobId != null) { isJobId = jobId.getJob() == null; } else { isJobId = true; From 31b1db292007fde1d74a66325a28873036008bc4 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Wed, 12 Oct 2022 22:01:25 -0400 Subject: [PATCH 05/15] chore: respect user specified location --- .../java/com/google/cloud/bigquery/QueryRequestInfo.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index 9c1e94f4d..8169209cf 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -60,8 +60,11 @@ final class QueryRequestInfo { boolean isFastQuerySupported(JobId jobId) { boolean isJobId; // Fast query path is not possible if jobId is specified - if (jobId != null) { - isJobId = jobId.getJob() == null; + // Respect both JobId and Location specified by user. + // Specifying either will force the query to take the slower path. + if( jobId != null) { + isJobId = jobId.getJob() == null + && jobId.getLocation() == null; } else { isJobId = true; } From 669dc21dfe8c79d04de8ac2f657511d94ce6de78 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 13 Oct 2022 02:03:52 +0000 Subject: [PATCH 06/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/bigquery/QueryRequestInfo.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index 8169209cf..adad1542c 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -62,9 +62,8 @@ boolean isFastQuerySupported(JobId jobId) { // Fast query path is not possible if jobId is specified // Respect both JobId and Location specified by user. // Specifying either will force the query to take the slower path. - if( jobId != null) { - isJobId = jobId.getJob() == null - && jobId.getLocation() == null; + if (jobId != null) { + isJobId = jobId.getJob() == null && jobId.getLocation() == null; } else { isJobId = true; } From 1c3aa8d36c882506cb3e6df6cde5170aa6881e11 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Wed, 12 Oct 2022 22:04:51 -0400 Subject: [PATCH 07/15] chore: fix test --- .../java/com/google/cloud/bigquery/QueryRequestInfoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java index 95f4587cb..456475597 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/QueryRequestInfoTest.java @@ -150,7 +150,7 @@ public class QueryRequestInfoTest { @Test public void testIsFastQuerySupported() { - JobId jobIdSupported = JobId.newBuilder().setLocation("US").build(); + JobId jobIdSupported = JobId.newBuilder().build(); JobId jobIdNotSupported = JobId.newBuilder().setJob("random-job-id").build(); assertEquals(false, REQUEST_INFO.isFastQuerySupported(jobIdSupported)); assertEquals(true, REQUEST_INFO_SUPPORTED.isFastQuerySupported(jobIdSupported)); From 9f2deaf4447d67185ce8197ee95fdfe2bd9628ec Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 13 Oct 2022 02:05:22 +0000 Subject: [PATCH 08/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../java/com/google/cloud/bigquery/QueryRequestInfo.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index 8169209cf..adad1542c 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -62,9 +62,8 @@ boolean isFastQuerySupported(JobId jobId) { // Fast query path is not possible if jobId is specified // Respect both JobId and Location specified by user. // Specifying either will force the query to take the slower path. - if( jobId != null) { - isJobId = jobId.getJob() == null - && jobId.getLocation() == null; + if (jobId != null) { + isJobId = jobId.getJob() == null && jobId.getLocation() == null; } else { isJobId = true; } From 59f1774ef576d5fd7a84dbdc3466b922ded857b5 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Fri, 4 Nov 2022 16:32:28 -0400 Subject: [PATCH 09/15] chore add IT tests --- .../google/cloud/bigquery/BigQueryImpl.java | 7 +++ .../cloud/bigquery/QueryRequestInfo.java | 14 ++--- .../cloud/bigquery/it/ITBigQueryTest.java | 59 +++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 5d4a877ce..d0aba0767 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1385,6 +1385,13 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp if (requestInfo.isFastQuerySupported(jobId)) { String projectId = getOptions().getProjectId(); QueryRequest content = requestInfo.toPb(); + // Be careful when setting the location in JobId, if a location is specified in the JobId, + // the job created by the query method will be in that location, even if the table to be + // queried is in a different location. This may + // cause the query to fail with "BigQueryException: Not found" + if(jobId.getLocation() != null) { + content.setLocation(jobId.getLocation()); + } return queryRpc(projectId, content, options); } return create(JobInfo.of(jobId, configuration), options).getQueryResults(); diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index adad1542c..eb41f1565 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -58,14 +58,14 @@ final class QueryRequestInfo { } boolean isFastQuerySupported(JobId jobId) { - boolean isJobId; - // Fast query path is not possible if jobId is specified - // Respect both JobId and Location specified by user. - // Specifying either will force the query to take the slower path. + boolean isJobIdFastQuerySupported; + // Fast query path is not possible if job is specified in the JobID object + // Respect Job field value in JobId specified by user. + // Specifying it will force the query to take the slower path. if (jobId != null) { - isJobId = jobId.getJob() == null && jobId.getLocation() == null; + isJobIdFastQuerySupported = jobId.getJob() == null; } else { - isJobId = true; + isJobIdFastQuerySupported = true; } return config.getClustering() == null && config.getCreateDisposition() == null @@ -80,7 +80,7 @@ boolean isFastQuerySupported(JobId jobId) { && config.getTimePartitioning() == null && config.getUserDefinedFunctions() == null && config.getWriteDisposition() == null - && isJobId; + && isJobIdFastQuerySupported; } QueryRequest toPb() { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 8e8f4cc0c..92331f6bd 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -180,6 +180,7 @@ public class ITBigQueryTest { private static final Long EXPIRATION_MS = 86400000L; private static final Logger LOG = Logger.getLogger(ITBigQueryTest.class.getName()); private static final String DATASET = RemoteBigQueryHelper.generateDatasetName(); + private static final String UK_DATASET = RemoteBigQueryHelper.generateDatasetName(); private static final String DESCRIPTION = "Test dataset"; private static final String OTHER_DATASET = RemoteBigQueryHelper.generateDatasetName(); private static final String MODEL_DATASET = RemoteBigQueryHelper.generateDatasetName(); @@ -533,6 +534,7 @@ public class ITBigQueryTest { private static final TableId TABLE_ID = TableId.of(DATASET, "testing_table"); private static final TableId TABLE_ID_DDL = TableId.of(DATASET, "ddl_testing_table"); private static final TableId TABLE_ID_FASTQUERY = TableId.of(DATASET, "fastquery_testing_table"); + private static final TableId TABLE_ID_FASTQUERY_UK = TableId.of(UK_DATASET, "fastquery_testing_table"); private static final TableId TABLE_ID_LARGE = TableId.of(DATASET, "large_data_testing_table"); private static final TableId TABLE_ID_FASTQUERY_BQ_RESULTSET = TableId.of(DATASET, "fastquery_testing_bq_resultset"); @@ -675,6 +677,7 @@ public class ITBigQueryTest { private static final String PUBLIC_PROJECT = "bigquery-public-data"; private static final String PUBLIC_DATASET = "census_bureau_international"; + private static BigQuery bigquery; private static Storage storage; @@ -717,6 +720,7 @@ public static void beforeClass() throws InterruptedException, IOException { DatasetInfo info3 = DatasetInfo.newBuilder(ROUTINE_DATASET).setDescription("java routine lifecycle").build(); bigquery.create(info3); + LoadJobConfiguration configuration = LoadJobConfiguration.newBuilder( TABLE_ID, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()) @@ -730,6 +734,7 @@ public static void beforeClass() throws InterruptedException, IOException { LoadJobConfiguration loadJobConfiguration = job.getConfiguration(); assertEquals(labels, loadJobConfiguration.getLabels()); + LoadJobConfiguration configurationFastQuery = LoadJobConfiguration.newBuilder( TABLE_ID_FASTQUERY, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()) @@ -781,6 +786,7 @@ public static void beforeClass() throws InterruptedException, IOException { public static void afterClass() throws ExecutionException, InterruptedException { if (bigquery != null) { RemoteBigQueryHelper.forceDelete(bigquery, DATASET); + RemoteBigQueryHelper.forceDelete(bigquery, UK_DATASET); RemoteBigQueryHelper.forceDelete(bigquery, MODEL_DATASET); RemoteBigQueryHelper.forceDelete(bigquery, ROUTINE_DATASET); } @@ -3267,6 +3273,59 @@ public void testFastSQLQuery() throws InterruptedException { } } + @Test + public void testFastSQLQueryWithJobId() throws InterruptedException { + DatasetInfo infoUK = + DatasetInfo.newBuilder(UK_DATASET).setDescription(DESCRIPTION).setLocation("europe-west1").setLabels(LABELS).build(); + bigquery.create(infoUK); + + TableDefinition tableDefinition = StandardTableDefinition.of(SIMPLE_SCHEMA); + TableInfo tableInfo = TableInfo.newBuilder(TABLE_ID_FASTQUERY_UK, tableDefinition).build(); + bigquery.create(tableInfo); + + String insert = "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK.getTable() + " VALUES('Anna');"; + + QueryJobConfiguration config = + QueryJobConfiguration.newBuilder(insert).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); + TableResult result = bigquery.query(config); + assertEquals(SIMPLE_SCHEMA, result.getSchema()); + assertEquals(1, result.getTotalRows()); + assertNull(result.getNextPage()); + assertNull(result.getNextPageToken()); + assertFalse(result.hasNextPage()); + // Verify correctness of table content + for (FieldValueList row : result.getValues()) { + FieldValue stringCell = row.get(0); + assertEquals(stringCell, row.get("StringField")); + assertEquals("Anna", stringCell.getStringValue()); + } + // With incorrect location in jobid + // The job will be created with the specified(incorrect) location + String query = + "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); + JobId jobIdWithLocation = JobId.newBuilder().setLocation("us-west1").build(); + QueryJobConfiguration configSelect = + QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); + try { + bigquery.query(configSelect, jobIdWithLocation); + } catch (BigQueryException exception){ + assertTrue(exception.getMessage().contains("Not found")); + assertEquals(BigQueryException.class, exception.getClass()); + + } + + //WithoutJobId in location, the query job defaults to the location of the dataset + JobId jobIdNoLocation = JobId.newBuilder().build(); + QueryJobConfiguration configNoLocation = + QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); + TableResult resultNoLocation = bigquery.query(configNoLocation, jobIdNoLocation); + for (FieldValueList row : resultNoLocation.getValues()) { + FieldValue stringCell = row.get(0); + assertEquals(stringCell, row.get("StringField")); + assertEquals("Anna", stringCell.getStringValue()); + } + } + /* TODO(prasmish): replicate the entire test case for executeSelect */ @Test public void testFastSQLQueryMultiPage() throws InterruptedException { From 248a7717d7b6ba6cb47d2d666ab5b525e689741d Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 4 Nov 2022 20:38:32 +0000 Subject: [PATCH 10/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 ++--- .../google/cloud/bigquery/BigQueryImpl.java | 2 +- .../cloud/bigquery/it/ITBigQueryTest.java | 26 +++++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5d4d46fe7..1590b4f60 100644 --- a/README.md +++ b/README.md @@ -52,20 +52,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.1.3') +implementation platform('com.google.cloud:libraries-bom:26.1.4') implementation 'com.google.cloud:google-cloud-bigquery' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.17.1' +implementation 'com.google.cloud:google-cloud-bigquery:2.18.2' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.17.1" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.18.2" ``` ## Authentication diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index d0aba0767..176a57a14 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1389,7 +1389,7 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp // the job created by the query method will be in that location, even if the table to be // queried is in a different location. This may // cause the query to fail with "BigQueryException: Not found" - if(jobId.getLocation() != null) { + if (jobId.getLocation() != null) { content.setLocation(jobId.getLocation()); } return queryRpc(projectId, content, options); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 92331f6bd..9d8071fc1 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -534,7 +534,8 @@ public class ITBigQueryTest { private static final TableId TABLE_ID = TableId.of(DATASET, "testing_table"); private static final TableId TABLE_ID_DDL = TableId.of(DATASET, "ddl_testing_table"); private static final TableId TABLE_ID_FASTQUERY = TableId.of(DATASET, "fastquery_testing_table"); - private static final TableId TABLE_ID_FASTQUERY_UK = TableId.of(UK_DATASET, "fastquery_testing_table"); + private static final TableId TABLE_ID_FASTQUERY_UK = + TableId.of(UK_DATASET, "fastquery_testing_table"); private static final TableId TABLE_ID_LARGE = TableId.of(DATASET, "large_data_testing_table"); private static final TableId TABLE_ID_FASTQUERY_BQ_RESULTSET = TableId.of(DATASET, "fastquery_testing_bq_resultset"); @@ -677,7 +678,6 @@ public class ITBigQueryTest { private static final String PUBLIC_PROJECT = "bigquery-public-data"; private static final String PUBLIC_DATASET = "census_bureau_international"; - private static BigQuery bigquery; private static Storage storage; @@ -734,7 +734,6 @@ public static void beforeClass() throws InterruptedException, IOException { LoadJobConfiguration loadJobConfiguration = job.getConfiguration(); assertEquals(labels, loadJobConfiguration.getLabels()); - LoadJobConfiguration configurationFastQuery = LoadJobConfiguration.newBuilder( TABLE_ID_FASTQUERY, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()) @@ -3276,17 +3275,24 @@ public void testFastSQLQuery() throws InterruptedException { @Test public void testFastSQLQueryWithJobId() throws InterruptedException { DatasetInfo infoUK = - DatasetInfo.newBuilder(UK_DATASET).setDescription(DESCRIPTION).setLocation("europe-west1").setLabels(LABELS).build(); + DatasetInfo.newBuilder(UK_DATASET) + .setDescription(DESCRIPTION) + .setLocation("europe-west1") + .setLabels(LABELS) + .build(); bigquery.create(infoUK); TableDefinition tableDefinition = StandardTableDefinition.of(SIMPLE_SCHEMA); TableInfo tableInfo = TableInfo.newBuilder(TABLE_ID_FASTQUERY_UK, tableDefinition).build(); bigquery.create(tableInfo); - String insert = "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK.getTable() + " VALUES('Anna');"; + String insert = + "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK.getTable() + " VALUES('Anna');"; QueryJobConfiguration config = - QueryJobConfiguration.newBuilder(insert).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); + QueryJobConfiguration.newBuilder(insert) + .setDefaultDataset(DatasetId.of(UK_DATASET)) + .build(); TableResult result = bigquery.query(config); assertEquals(SIMPLE_SCHEMA, result.getSchema()); assertEquals(1, result.getTotalRows()); @@ -3301,20 +3307,18 @@ public void testFastSQLQueryWithJobId() throws InterruptedException { } // With incorrect location in jobid // The job will be created with the specified(incorrect) location - String query = - "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); + String query = "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); JobId jobIdWithLocation = JobId.newBuilder().setLocation("us-west1").build(); QueryJobConfiguration configSelect = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); try { bigquery.query(configSelect, jobIdWithLocation); - } catch (BigQueryException exception){ + } catch (BigQueryException exception) { assertTrue(exception.getMessage().contains("Not found")); assertEquals(BigQueryException.class, exception.getClass()); - } - //WithoutJobId in location, the query job defaults to the location of the dataset + // WithoutJobId in location, the query job defaults to the location of the dataset JobId jobIdNoLocation = JobId.newBuilder().build(); QueryJobConfiguration configNoLocation = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); From 5d81b6c39be2263750eea24f04e44525ce584460 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 4 Nov 2022 20:40:09 +0000 Subject: [PATCH 11/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 6 ++--- .../google/cloud/bigquery/BigQueryImpl.java | 2 +- .../cloud/bigquery/it/ITBigQueryTest.java | 26 +++++++++++-------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5d4d46fe7..1590b4f60 100644 --- a/README.md +++ b/README.md @@ -52,20 +52,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.1.3') +implementation platform('com.google.cloud:libraries-bom:26.1.4') implementation 'com.google.cloud:google-cloud-bigquery' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.17.1' +implementation 'com.google.cloud:google-cloud-bigquery:2.18.2' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.17.1" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.18.2" ``` ## Authentication diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index d0aba0767..176a57a14 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1389,7 +1389,7 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp // the job created by the query method will be in that location, even if the table to be // queried is in a different location. This may // cause the query to fail with "BigQueryException: Not found" - if(jobId.getLocation() != null) { + if (jobId.getLocation() != null) { content.setLocation(jobId.getLocation()); } return queryRpc(projectId, content, options); diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 92331f6bd..9d8071fc1 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -534,7 +534,8 @@ public class ITBigQueryTest { private static final TableId TABLE_ID = TableId.of(DATASET, "testing_table"); private static final TableId TABLE_ID_DDL = TableId.of(DATASET, "ddl_testing_table"); private static final TableId TABLE_ID_FASTQUERY = TableId.of(DATASET, "fastquery_testing_table"); - private static final TableId TABLE_ID_FASTQUERY_UK = TableId.of(UK_DATASET, "fastquery_testing_table"); + private static final TableId TABLE_ID_FASTQUERY_UK = + TableId.of(UK_DATASET, "fastquery_testing_table"); private static final TableId TABLE_ID_LARGE = TableId.of(DATASET, "large_data_testing_table"); private static final TableId TABLE_ID_FASTQUERY_BQ_RESULTSET = TableId.of(DATASET, "fastquery_testing_bq_resultset"); @@ -677,7 +678,6 @@ public class ITBigQueryTest { private static final String PUBLIC_PROJECT = "bigquery-public-data"; private static final String PUBLIC_DATASET = "census_bureau_international"; - private static BigQuery bigquery; private static Storage storage; @@ -734,7 +734,6 @@ public static void beforeClass() throws InterruptedException, IOException { LoadJobConfiguration loadJobConfiguration = job.getConfiguration(); assertEquals(labels, loadJobConfiguration.getLabels()); - LoadJobConfiguration configurationFastQuery = LoadJobConfiguration.newBuilder( TABLE_ID_FASTQUERY, "gs://" + BUCKET + "/" + JSON_LOAD_FILE, FormatOptions.json()) @@ -3276,17 +3275,24 @@ public void testFastSQLQuery() throws InterruptedException { @Test public void testFastSQLQueryWithJobId() throws InterruptedException { DatasetInfo infoUK = - DatasetInfo.newBuilder(UK_DATASET).setDescription(DESCRIPTION).setLocation("europe-west1").setLabels(LABELS).build(); + DatasetInfo.newBuilder(UK_DATASET) + .setDescription(DESCRIPTION) + .setLocation("europe-west1") + .setLabels(LABELS) + .build(); bigquery.create(infoUK); TableDefinition tableDefinition = StandardTableDefinition.of(SIMPLE_SCHEMA); TableInfo tableInfo = TableInfo.newBuilder(TABLE_ID_FASTQUERY_UK, tableDefinition).build(); bigquery.create(tableInfo); - String insert = "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK.getTable() + " VALUES('Anna');"; + String insert = + "INSERT " + UK_DATASET + "." + TABLE_ID_FASTQUERY_UK.getTable() + " VALUES('Anna');"; QueryJobConfiguration config = - QueryJobConfiguration.newBuilder(insert).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); + QueryJobConfiguration.newBuilder(insert) + .setDefaultDataset(DatasetId.of(UK_DATASET)) + .build(); TableResult result = bigquery.query(config); assertEquals(SIMPLE_SCHEMA, result.getSchema()); assertEquals(1, result.getTotalRows()); @@ -3301,20 +3307,18 @@ public void testFastSQLQueryWithJobId() throws InterruptedException { } // With incorrect location in jobid // The job will be created with the specified(incorrect) location - String query = - "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); + String query = "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); JobId jobIdWithLocation = JobId.newBuilder().setLocation("us-west1").build(); QueryJobConfiguration configSelect = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); try { bigquery.query(configSelect, jobIdWithLocation); - } catch (BigQueryException exception){ + } catch (BigQueryException exception) { assertTrue(exception.getMessage().contains("Not found")); assertEquals(BigQueryException.class, exception.getClass()); - } - //WithoutJobId in location, the query job defaults to the location of the dataset + // WithoutJobId in location, the query job defaults to the location of the dataset JobId jobIdNoLocation = JobId.newBuilder().build(); QueryJobConfiguration configNoLocation = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); From 3d0df91049e8b3d489088f54bf129bbec6ad6e75 Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Tue, 8 Nov 2022 15:46:00 -0500 Subject: [PATCH 12/15] chore: allow users to specify project ID with JobID --- .../google/cloud/bigquery/BigQueryImpl.java | 7 +++++ .../cloud/bigquery/QueryRequestInfo.java | 10 +++---- .../cloud/bigquery/it/ITBigQueryTest.java | 26 +++++++++++++++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 176a57a14..ff07fdcad 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1384,6 +1384,12 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp QueryRequestInfo requestInfo = new QueryRequestInfo(configuration); if (requestInfo.isFastQuerySupported(jobId)) { String projectId = getOptions().getProjectId(); + // Be careful when setting the projectID in JobId, if a projectID is specified in the JobId, + // the job created by the query method will use that project. This may + // cause the query to fail with "BigQueryException: Not found" + if(jobId.getProject() != null){ + projectId = jobId.getProject(); + } QueryRequest content = requestInfo.toPb(); // Be careful when setting the location in JobId, if a location is specified in the JobId, // the job created by the query method will be in that location, even if the table to be @@ -1392,6 +1398,7 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp if (jobId.getLocation() != null) { content.setLocation(jobId.getLocation()); } + return queryRpc(projectId, content, options); } return create(JobInfo.of(jobId, configuration), options).getQueryResults(); diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index eb41f1565..6c19616fb 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -58,14 +58,11 @@ final class QueryRequestInfo { } boolean isFastQuerySupported(JobId jobId) { - boolean isJobIdFastQuerySupported; // Fast query path is not possible if job is specified in the JobID object // Respect Job field value in JobId specified by user. // Specifying it will force the query to take the slower path. - if (jobId != null) { - isJobIdFastQuerySupported = jobId.getJob() == null; - } else { - isJobIdFastQuerySupported = true; + if (jobId == null || jobId.getJob() != null) { + return false; } return config.getClustering() == null && config.getCreateDisposition() == null @@ -79,8 +76,7 @@ boolean isFastQuerySupported(JobId jobId) { && config.getTableDefinitions() == null && config.getTimePartitioning() == null && config.getUserDefinedFunctions() == null - && config.getWriteDisposition() == null - && isJobIdFastQuerySupported; + && config.getWriteDisposition() == null; } QueryRequest toPb() { diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java index 9d8071fc1..746a50cdb 100644 --- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java +++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java @@ -3273,7 +3273,28 @@ public void testFastSQLQuery() throws InterruptedException { } @Test - public void testFastSQLQueryWithJobId() throws InterruptedException { + public void testProjectIDFastSQLQueryWithJobId() throws InterruptedException { + String random_project_id = "RANDOM_PROJECT_" + UUID.randomUUID().toString().replace('-', '_'); + System.out.println(random_project_id); + String query = + "SELECT TimestampField, StringField, BooleanField FROM " + TABLE_ID_FASTQUERY.getTable(); + // With incorrect projectID in jobid + // The job will be created with the specified(incorrect) projectID + // hence failing the operation + JobId jobIdWithProjectId = JobId.newBuilder().setProject(random_project_id).build(); + QueryJobConfiguration configSelect = + QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(DATASET)).build(); + try { + bigquery.query(configSelect, jobIdWithProjectId); + } catch (Exception exception) { + // error message for non-existent project + assertTrue(exception.getMessage().contains("Cannot parse as CloudRegion")); + assertEquals(BigQueryException.class, exception.getClass()); + } + } + + @Test + public void testLocationFastSQLQueryWithJobId() throws InterruptedException { DatasetInfo infoUK = DatasetInfo.newBuilder(UK_DATASET) .setDescription(DESCRIPTION) @@ -3307,6 +3328,7 @@ public void testFastSQLQueryWithJobId() throws InterruptedException { } // With incorrect location in jobid // The job will be created with the specified(incorrect) location + // hence failing the operation String query = "SELECT StringField FROM " + TABLE_ID_FASTQUERY_UK.getTable(); JobId jobIdWithLocation = JobId.newBuilder().setLocation("us-west1").build(); QueryJobConfiguration configSelect = @@ -3318,7 +3340,7 @@ public void testFastSQLQueryWithJobId() throws InterruptedException { assertEquals(BigQueryException.class, exception.getClass()); } - // WithoutJobId in location, the query job defaults to the location of the dataset + // Without location in jobID, the query job defaults to the location of the dataset JobId jobIdNoLocation = JobId.newBuilder().build(); QueryJobConfiguration configNoLocation = QueryJobConfiguration.newBuilder(query).setDefaultDataset(DatasetId.of(UK_DATASET)).build(); From b92df7706ce3120a17fb9a08a165b731267eee26 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 8 Nov 2022 20:48:30 +0000 Subject: [PATCH 13/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 4 ++-- .../src/main/java/com/google/cloud/bigquery/BigQueryImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1590b4f60..b24e5db20 100644 --- a/README.md +++ b/README.md @@ -59,13 +59,13 @@ implementation 'com.google.cloud:google-cloud-bigquery' If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-bigquery:2.18.2' +implementation 'com.google.cloud:google-cloud-bigquery:2.19.1' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.18.2" +libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.19.1" ``` ## Authentication diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index ff07fdcad..5729388b2 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1387,7 +1387,7 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp // Be careful when setting the projectID in JobId, if a projectID is specified in the JobId, // the job created by the query method will use that project. This may // cause the query to fail with "BigQueryException: Not found" - if(jobId.getProject() != null){ + if (jobId.getProject() != null) { projectId = jobId.getProject(); } QueryRequest content = requestInfo.toPb(); From d30ee236cd4023a61f1605c351a12e4c85dd3afc Mon Sep 17 00:00:00 2001 From: Neenu1995 Date: Wed, 9 Nov 2022 10:43:15 -0500 Subject: [PATCH 14/15] chore: fix conditions --- .../com/google/cloud/bigquery/BigQueryImpl.java | 14 ++++++-------- .../google/cloud/bigquery/QueryRequestInfo.java | 6 ++++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index 5729388b2..a4688f166 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1383,18 +1383,16 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp // put on fast path QueryRequestInfo requestInfo = new QueryRequestInfo(configuration); if (requestInfo.isFastQuerySupported(jobId)) { - String projectId = getOptions().getProjectId(); // Be careful when setting the projectID in JobId, if a projectID is specified in the JobId, - // the job created by the query method will use that project. This may - // cause the query to fail with "BigQueryException: Not found" - if (jobId.getProject() != null) { - projectId = jobId.getProject(); - } + // the job created by the query method will use that project. This may cause the query to + // fail with "Access denied" if the project do not have enough permissions to run the job. + + String projectId = jobId.getProject() != null ? jobId.getProject() : getOptions().getProjectId(); QueryRequest content = requestInfo.toPb(); // Be careful when setting the location in JobId, if a location is specified in the JobId, // the job created by the query method will be in that location, even if the table to be - // queried is in a different location. This may - // cause the query to fail with "BigQueryException: Not found" + // queried is in a different location. This may cause the query to fail with + // "BigQueryException: Not found" if (jobId.getLocation() != null) { content.setLocation(jobId.getLocation()); } diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index 6c19616fb..5a2ceb402 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -61,8 +61,10 @@ boolean isFastQuerySupported(JobId jobId) { // Fast query path is not possible if job is specified in the JobID object // Respect Job field value in JobId specified by user. // Specifying it will force the query to take the slower path. - if (jobId == null || jobId.getJob() != null) { - return false; + if (jobId != null) { + if(jobId.getJob() != null){ + return false; + } } return config.getClustering() == null && config.getCreateDisposition() == null From 2c4c8f7b797fb635083bf247dfb2b484b445b491 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 9 Nov 2022 15:48:27 +0000 Subject: [PATCH 15/15] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- .../src/main/java/com/google/cloud/bigquery/BigQueryImpl.java | 3 ++- .../main/java/com/google/cloud/bigquery/QueryRequestInfo.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java index a4688f166..a0f5b7139 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java @@ -1387,7 +1387,8 @@ public TableResult query(QueryJobConfiguration configuration, JobId jobId, JobOp // the job created by the query method will use that project. This may cause the query to // fail with "Access denied" if the project do not have enough permissions to run the job. - String projectId = jobId.getProject() != null ? jobId.getProject() : getOptions().getProjectId(); + String projectId = + jobId.getProject() != null ? jobId.getProject() : getOptions().getProjectId(); QueryRequest content = requestInfo.toPb(); // Be careful when setting the location in JobId, if a location is specified in the JobId, // the job created by the query method will be in that location, even if the table to be diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java index 5a2ceb402..00a898363 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryRequestInfo.java @@ -62,7 +62,7 @@ boolean isFastQuerySupported(JobId jobId) { // Respect Job field value in JobId specified by user. // Specifying it will force the query to take the slower path. if (jobId != null) { - if(jobId.getJob() != null){ + if (jobId.getJob() != null) { return false; } }