diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 084b07b25..96a9f3066 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -62,6 +62,7 @@ javadoc) integration) mvn -B ${INTEGRATION_TEST_ARGS} \ -ntp \ + -Dprotobuf.version=4.29.4 \ -Penable-integration-tests \ -DtrimStackTrace=false \ -Dclirr.skip=true \ diff --git a/.kokoro/continuous/graalvm-native-a.cfg b/.kokoro/continuous/graalvm-native-a.cfg index 3350e3778..35d360c34 100644 --- a/.kokoro/continuous/graalvm-native-a.cfg +++ b/.kokoro/continuous/graalvm-native-a.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: "false" } \ No newline at end of file diff --git a/.kokoro/continuous/graalvm-native-b.cfg b/.kokoro/continuous/graalvm-native-b.cfg index 96ec9ba71..ccd8afcdc 100644 --- a/.kokoro/continuous/graalvm-native-b.cfg +++ b/.kokoro/continuous/graalvm-native-b.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: "false" } \ No newline at end of file diff --git a/.kokoro/continuous/graalvm-native-c.cfg b/.kokoro/continuous/graalvm-native-c.cfg index c8ed10da9..73d09b700 100644 --- a/.kokoro/continuous/graalvm-native-c.cfg +++ b/.kokoro/continuous/graalvm-native-c.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: "false" } \ No newline at end of file diff --git a/.kokoro/presubmit/graalvm-native-a.cfg b/.kokoro/presubmit/graalvm-native-a.cfg index 3350e3778..35d360c34 100644 --- a/.kokoro/presubmit/graalvm-native-a.cfg +++ b/.kokoro/presubmit/graalvm-native-a.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: "false" } \ No newline at end of file diff --git a/.kokoro/presubmit/graalvm-native-b.cfg b/.kokoro/presubmit/graalvm-native-b.cfg index 96ec9ba71..ccd8afcdc 100644 --- a/.kokoro/presubmit/graalvm-native-b.cfg +++ b/.kokoro/presubmit/graalvm-native-b.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: "false" } \ No newline at end of file diff --git a/.kokoro/presubmit/graalvm-native-c.cfg b/.kokoro/presubmit/graalvm-native-c.cfg index c8ed10da9..73d09b700 100644 --- a/.kokoro/presubmit/graalvm-native-c.cfg +++ b/.kokoro/presubmit/graalvm-native-c.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: "false" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 875117270..201284f14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## [2.50.1](https://github.com/googleapis/java-bigquery/compare/v2.50.0...v2.50.1) (2025-05-16) + + +### Dependencies + +* Update dependency com.google.cloud:sdk-platform-java-config to v3.48.0 ([#3790](https://github.com/googleapis/java-bigquery/issues/3790)) ([206f06d](https://github.com/googleapis/java-bigquery/commit/206f06de115ead53b26f09a5f4781efd279b5a73)) +* Update netty.version to v4.2.1.final ([#3780](https://github.com/googleapis/java-bigquery/issues/3780)) ([6dcd858](https://github.com/googleapis/java-bigquery/commit/6dcd858eca788a8cb571368e12b4925993e380c4)) + + +### Documentation + +* **bigquery:** Update TableResult.getTotalRows() docstring ([#3785](https://github.com/googleapis/java-bigquery/issues/3785)) ([6483588](https://github.com/googleapis/java-bigquery/commit/6483588a3c5785b95ea841f21aa38f50ecf4226d)) + ## [2.50.0](https://github.com/googleapis/java-bigquery/compare/v2.49.2...v2.50.0) (2025-05-06) diff --git a/benchmark/pom.xml b/benchmark/pom.xml index ec8c002e9..8aec7658e 100644 --- a/benchmark/pom.xml +++ b/benchmark/pom.xml @@ -6,7 +6,7 @@ google-cloud-bigquery-parent com.google.cloud - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT diff --git a/google-cloud-bigquery-bom/pom.xml b/google-cloud-bigquery-bom/pom.xml index 3039f6cc1..b231a29d5 100644 --- a/google-cloud-bigquery-bom/pom.xml +++ b/google-cloud-bigquery-bom/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-bigquery-bom - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT pom com.google.cloud @@ -54,7 +54,7 @@ com.google.cloud google-cloud-bigquery - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT diff --git a/google-cloud-bigquery/pom.xml b/google-cloud-bigquery/pom.xml index 94daf260a..aefc3f1f9 100644 --- a/google-cloud-bigquery/pom.xml +++ b/google-cloud-bigquery/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-bigquery - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT jar BigQuery https://github.com/googleapis/java-bigquery @@ -11,11 +11,11 @@ com.google.cloud google-cloud-bigquery-parent - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT google-cloud-bigquery - 4.2.1.Final + 4.1.119.Final diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java index 2a7d498c0..2e0747f6b 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java @@ -77,6 +77,42 @@ public String getSelector() { } } + enum DatasetView { + DATASET_VIEW_UNSPECIFIED("DATASET_VIEW_UNSPECIFIED"), + FULL("FULL"), + METADATA("METADATA"), + ACL("ACL"); + + private final String view; + + DatasetView(String view) { + this.view = view; + } + + @Override + public String toString() { + return view; + } + } + + enum DatasetUpdateMode { + UPDATE_MODE_UNSPECIFIED("UPDATE_MODE_UNSPECIFIED"), + UPDATE_FULL("UPDATE_FULL"), + UPDATE_METADATA("UPDATE_METADATA"), + UPDATE_ACL("UPDATE_ACL"); + + private final String updateMode; + + DatasetUpdateMode(String updateMode) { + this.updateMode = updateMode; + } + + @Override + public String toString() { + return updateMode; + } + } + /** * Fields of a BigQuery Table resource. * @@ -307,6 +343,22 @@ public static DatasetOption fields(DatasetField... fields) { public static DatasetOption accessPolicyVersion(Integer accessPolicyVersion) { return new DatasetOption(BigQueryRpc.Option.ACCESS_POLICY_VERSION, accessPolicyVersion); } + + /** + * Returns an option to specify the view that determines which dataset information is returned. + * By default, metadata and ACL information are returned. + */ + public static DatasetOption datasetView(DatasetView datasetView) { + return new DatasetOption(BigQueryRpc.Option.DATASET_VIEW, datasetView); + } + + /** + * Returns an option to specify the fields of dataset that update/patch operation is targeting. + * By default, both metadata and ACL fields are updated. + */ + public static DatasetOption updateMode(DatasetUpdateMode updateMode) { + return new DatasetOption(BigQueryRpc.Option.DATASET_UPDATE_MODE, updateMode); + } } /** Class for specifying dataset delete options. */ 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 8f8e45ad3..9ede02838 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 @@ -40,7 +40,6 @@ import com.google.cloud.Tuple; import com.google.cloud.bigquery.BigQueryRetryHelper.BigQueryRetryHelperException; import com.google.cloud.bigquery.InsertAllRequest.RowToInsert; -import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode; import com.google.cloud.bigquery.spi.v2.BigQueryRpc; import com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc; import com.google.common.annotations.VisibleForTesting; @@ -442,9 +441,6 @@ public com.google.api.services.bigquery.model.Job call() throws IOException { && createException.getCause() != null && createException.getCause().getMessage() != null) { - /*GoogleJsonResponseException createExceptionCause = - (GoogleJsonResponseException) createException.getCause();*/ - Pattern pattern = Pattern.compile(".*Already.*Exists:.*Job.*", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(createException.getCause().getMessage()); @@ -1407,12 +1403,10 @@ public TableResult query(QueryJobConfiguration configuration, JobOption... optio throws InterruptedException, JobException { Job.checkNotDryRun(configuration, "query"); - if (getOptions().isQueryPreviewEnabled()) { - configuration = - configuration.toBuilder() - .setJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL) - .build(); - } + configuration = + configuration.toBuilder() + .setJobCreationMode(getOptions().getDefaultJobCreationMode()) + .build(); // If all parameters passed in configuration are supported by the query() method on the backend, // put on fast path diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java index ca34a2d2d..a1dacc4cf 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java @@ -20,10 +20,10 @@ import com.google.cloud.ServiceOptions; import com.google.cloud.ServiceRpc; import com.google.cloud.TransportOptions; +import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode; import com.google.cloud.bigquery.spi.BigQueryRpcFactory; import com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc; import com.google.cloud.http.HttpTransportOptions; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableSet; import java.util.Set; @@ -38,7 +38,7 @@ public class BigQueryOptions extends ServiceOptions { // set the option ThrowNotFound when you want to throw the exception when the value not found private boolean setThrowNotFound; private boolean useInt64Timestamps; - private String queryPreviewEnabled = System.getenv("QUERY_PREVIEW_ENABLED"); + private JobCreationMode defaultJobCreationMode = JobCreationMode.JOB_CREATION_MODE_UNSPECIFIED; public static class DefaultBigQueryFactory implements BigQueryFactory { @@ -139,8 +139,9 @@ public String getLocation() { return location; } + @Deprecated public boolean isQueryPreviewEnabled() { - return queryPreviewEnabled != null && queryPreviewEnabled.equalsIgnoreCase("TRUE"); + return false; } public void setThrowNotFound(boolean setThrowNotFound) { @@ -151,9 +152,11 @@ public void setUseInt64Timestamps(boolean useInt64Timestamps) { this.useInt64Timestamps = useInt64Timestamps; } - @VisibleForTesting - public void setQueryPreviewEnabled(String queryPreviewEnabled) { - this.queryPreviewEnabled = queryPreviewEnabled; + @Deprecated + public void setQueryPreviewEnabled(String queryPreviewEnabled) {} + + public void setDefaultJobCreationMode(JobCreationMode jobCreationMode) { + this.defaultJobCreationMode = jobCreationMode; } public boolean getThrowNotFound() { @@ -164,6 +167,10 @@ public boolean getUseInt64Timestamps() { return useInt64Timestamps; } + public JobCreationMode getDefaultJobCreationMode() { + return defaultJobCreationMode; + } + @SuppressWarnings("unchecked") @Override public Builder toBuilder() { diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java index b460b6121..a62fbb500 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/QueryJobConfiguration.java @@ -97,7 +97,7 @@ public enum Priority { } /** Job Creation Mode provides different options on job creation. */ - enum JobCreationMode { + public enum JobCreationMode { /** Unspecified JobCreationMode, defaults to JOB_CREATION_REQUIRED. */ JOB_CREATION_MODE_UNSPECIFIED, /** Default. Job creation is always required. */ @@ -187,7 +187,7 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur this(); JobConfigurationQuery queryConfigurationPb = configurationPb.getQuery(); this.query = queryConfigurationPb.getQuery(); - // Allows to get undeclaredqueryparameters in jobstatistics2 + // Allows to get undeclared query parameters in jobstatistics if (queryConfigurationPb.getQueryParameters() == null && queryConfigurationPb.getParameterMode() != null) { parameterMode = queryConfigurationPb.getParameterMode(); @@ -683,7 +683,7 @@ public Builder setMaxResults(Long maxResults) { * Provides different options on job creation. If not specified the job creation mode is assumed * to be {@link JobCreationMode#JOB_CREATION_REQUIRED}. */ - Builder setJobCreationMode(JobCreationMode jobCreationMode) { + public Builder setJobCreationMode(JobCreationMode jobCreationMode) { this.jobCreationMode = jobCreationMode; return this; } @@ -959,7 +959,7 @@ public Long getMaxResults() { } /** Returns the job creation mode. */ - JobCreationMode getJobCreationMode() { + public JobCreationMode getJobCreationMode() { return jobCreationMode; } 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 7eebfea96..588b7cae8 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 @@ -86,7 +86,8 @@ boolean isFastQuerySupported(JobId jobId) { && config.getTableDefinitions() == null && config.getTimePartitioning() == null && config.getUserDefinedFunctions() == null - && config.getWriteDisposition() == null; + && config.getWriteDisposition() == null + && config.getJobCreationMode() != JobCreationMode.JOB_CREATION_REQUIRED; } QueryRequest toPb() { diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/BigQueryRpc.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/BigQueryRpc.java index bbde70dc5..65fd45d02 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/BigQueryRpc.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/BigQueryRpc.java @@ -60,7 +60,9 @@ enum Option { TABLE_METADATA_VIEW("view"), RETRY_OPTIONS("retryOptions"), BIGQUERY_RETRY_CONFIG("bigQueryRetryConfig"), - ACCESS_POLICY_VERSION("accessPolicyVersion"); + ACCESS_POLICY_VERSION("accessPolicyVersion"), + DATASET_VIEW("datasetView"), + DATASET_UPDATE_MODE("datasetUpdateMode"); private final String value; diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java index ebb8f2644..03e1fb586 100644 --- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java +++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java @@ -149,10 +149,11 @@ public Dataset getDatasetSkipExceptionTranslation( .get(projectId, datasetId) .setFields(Option.FIELDS.getString(options)) .setPrettyPrint(false); - for (Map.Entry entry : options.entrySet()) { - if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) { - bqGetRequest.setAccessPolicyVersion((Integer) entry.getValue()); - } + if (options.containsKey(Option.ACCESS_POLICY_VERSION)) { + bqGetRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION)); + } + if (options.containsKey(Option.DATASET_VIEW)) { + bqGetRequest.setDatasetView(options.get(Option.DATASET_VIEW).toString()); } return bqGetRequest.execute(); } @@ -207,10 +208,8 @@ public Dataset createSkipExceptionTranslation(Dataset dataset, Map op .insert(dataset.getDatasetReference().getProjectId(), dataset) .setPrettyPrint(false) .setFields(Option.FIELDS.getString(options)); - for (Map.Entry entry : options.entrySet()) { - if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) { - bqCreateRequest.setAccessPolicyVersion((Integer) entry.getValue()); - } + if (options.containsKey(Option.ACCESS_POLICY_VERSION)) { + bqCreateRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION)); } return bqCreateRequest.execute(); } @@ -350,10 +349,11 @@ public Dataset patchSkipExceptionTranslation(Dataset dataset, Map opt .patch(reference.getProjectId(), reference.getDatasetId(), dataset) .setPrettyPrint(false) .setFields(Option.FIELDS.getString(options)); - for (Map.Entry entry : options.entrySet()) { - if (entry.getKey() == Option.ACCESS_POLICY_VERSION && entry.getValue() != null) { - bqPatchRequest.setAccessPolicyVersion((Integer) entry.getValue()); - } + if (options.containsKey(Option.ACCESS_POLICY_VERSION)) { + bqPatchRequest.setAccessPolicyVersion((Integer) options.get(Option.ACCESS_POLICY_VERSION)); + } + if (options.containsKey(Option.DATASET_UPDATE_MODE)) { + bqPatchRequest.setUpdateMode(options.get(Option.DATASET_UPDATE_MODE).toString()); } return bqPatchRequest.execute(); } 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 a28cb20ba..bd17b14fc 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 @@ -48,6 +48,8 @@ import com.google.cloud.bigquery.BigQuery.DatasetField; import com.google.cloud.bigquery.BigQuery.DatasetListOption; import com.google.cloud.bigquery.BigQuery.DatasetOption; +import com.google.cloud.bigquery.BigQuery.DatasetUpdateMode; +import com.google.cloud.bigquery.BigQuery.DatasetView; import com.google.cloud.bigquery.BigQuery.JobField; import com.google.cloud.bigquery.BigQuery.JobListOption; import com.google.cloud.bigquery.BigQuery.JobOption; @@ -111,6 +113,7 @@ import com.google.cloud.bigquery.PolicyTags; import com.google.cloud.bigquery.PrimaryKey; import com.google.cloud.bigquery.QueryJobConfiguration; +import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode; import com.google.cloud.bigquery.QueryJobConfiguration.Priority; import com.google.cloud.bigquery.QueryParameterValue; import com.google.cloud.bigquery.Range; @@ -1235,7 +1238,8 @@ public void testGetDatasetWithAccessPolicyVersion() throws IOException { "requests after the year 2024", "location"); Acl acl = Acl.of(user, role, condition); - DatasetOption datasetOption = DatasetOption.accessPolicyVersion(3); + DatasetOption accessPolicyOption = DatasetOption.accessPolicyVersion(3); + DatasetOption viewOption = DatasetOption.datasetView(DatasetView.FULL); Dataset dataset = bigquery.create( @@ -1243,10 +1247,11 @@ public void testGetDatasetWithAccessPolicyVersion() throws IOException { .setDescription("Some Description") .setAcl(ImmutableList.of(acl)) .build(), - datasetOption); + accessPolicyOption); assertThat(dataset).isNotNull(); - Dataset remoteDataset = bigquery.getDataset(accessPolicyDataset, datasetOption); + Dataset remoteDataset = + bigquery.getDataset(accessPolicyDataset, accessPolicyOption, viewOption); assertNotNull(remoteDataset); assertEquals(dataset.getDescription(), remoteDataset.getDescription()); assertNotNull(remoteDataset.getCreationTime()); @@ -1329,7 +1334,7 @@ public void testUpdateDatasetWithSelectedFields() { } @Test - public void testUpdateDatabaseWithAccessPolicyVersion() throws IOException { + public void testUpdateDatasetWithAccessPolicyVersion() throws IOException { String accessPolicyDataset = RemoteBigQueryHelper.generateDatasetName(); ServiceAccountCredentials credentials = (ServiceAccountCredentials) GoogleCredentials.getApplicationDefault(); @@ -1355,6 +1360,7 @@ public void testUpdateDatabaseWithAccessPolicyVersion() throws IOException { acls.add(acl); DatasetOption datasetOption = DatasetOption.accessPolicyVersion(3); + DatasetOption updateModeOption = DatasetOption.updateMode(DatasetUpdateMode.UPDATE_FULL); Dataset updatedDataset = bigquery.update( dataset.toBuilder() @@ -1362,7 +1368,8 @@ public void testUpdateDatabaseWithAccessPolicyVersion() throws IOException { .setLabels(null) .setAcl(acls) .build(), - datasetOption); + datasetOption, + updateModeOption); assertNotNull(updatedDataset); assertEquals(updatedDataset.getDescription(), "Updated Description"); assertThat(updatedDataset.getLabels().isEmpty()); @@ -1820,7 +1827,7 @@ public void testCreateDatasetWithAccessPolicyVersion() throws IOException { } @Test(expected = BigQueryException.class) - public void testCreateDatabaseWithInvalidAccessPolicyVersion() throws IOException { + public void testCreateDatasetWithInvalidAccessPolicyVersion() throws IOException { String accessPolicyDataset = RemoteBigQueryHelper.generateDatasetName(); ServiceAccountCredentials credentials = (ServiceAccountCredentials) GoogleCredentials.getApplicationDefault(); @@ -3483,6 +3490,7 @@ public void testExecuteSelectWithReadApi() throws SQLException { final int rowLimit = 5000; final String QUERY = "SELECT * FROM bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017 LIMIT %s"; + bigquery.getOptions().setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_REQUIRED); // Job timeout is somewhat arbitrary - just ensures that fast query is not used. // min result size and page row count ratio ensure that the ReadAPI is used. ConnectionSettings connectionSettingsReadAPIEnabledFastQueryDisabled = @@ -4032,8 +4040,7 @@ public void testBQResultSetPagination() throws SQLException { assertEquals(300000, cnt); // total 300000 rows should be read } - // @Test - Temporarily disabling till https://github.com/googleapis/gax-java/issues/1712 or - // b/235591056 are resolved + @Test public void testReadAPIIterationAndOrder() throws SQLException { // use read API to read 300K records and check the order String query = @@ -4232,8 +4239,7 @@ public void testCreateDefaultConnection() throws BigQuerySQLException { assertTrue(connection.close()); } - // @Test - Temporarily disabling till https://github.com/googleapis/gax-java/issues/1712 or - // b/235591056 are resolved + @Test public void testReadAPIConnectionMultiClose() throws SQLException { // use read API to read 300K records, then closes the connection. This test @@ -7084,26 +7090,19 @@ public void testStatelessQueries() throws InterruptedException { RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); BigQuery bigQuery = bigqueryHelper.getOptions().getService(); - // Simulate setting the QUERY_PREVIEW_ENABLED environment variable. - bigQuery.getOptions().setQueryPreviewEnabled("TRUE"); + // Stateless query should have no job id. + bigQuery.getOptions().setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL); TableResult tableResult = executeSimpleQuery(bigQuery); assertNotNull(tableResult.getQueryId()); assertNull(tableResult.getJobId()); - // The flag should be case-insensitive. - bigQuery.getOptions().setQueryPreviewEnabled("tRuE"); - tableResult = executeSimpleQuery(bigQuery); - assertNotNull(tableResult.getQueryId()); - assertNull(tableResult.getJobId()); - - // Any other values won't enable optional job creation mode. - bigQuery.getOptions().setQueryPreviewEnabled("test_value"); + // Job creation takes over, no query id is created. + bigQuery.getOptions().setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_REQUIRED); tableResult = executeSimpleQuery(bigQuery); - assertNotNull(tableResult.getQueryId()); + assertNull(tableResult.getQueryId()); assertNotNull(tableResult.getJobId()); - // Reset the flag. - bigQuery.getOptions().setQueryPreviewEnabled(null); + bigQuery.getOptions().setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_MODE_UNSPECIFIED); tableResult = executeSimpleQuery(bigQuery); assertNotNull(tableResult.getQueryId()); assertNotNull(tableResult.getJobId()); @@ -7128,8 +7127,8 @@ public void testTableResultJobIdAndQueryId() throws InterruptedException { // Create local BigQuery for test scenario 1 to not contaminate global test parameters. RemoteBigQueryHelper bigqueryHelper = RemoteBigQueryHelper.create(); BigQuery bigQuery = bigqueryHelper.getOptions().getService(); - // Simulate setting the QUERY_PREVIEW_ENABLED environment variable. - bigQuery.getOptions().setQueryPreviewEnabled("TRUE"); + // Allow queries to be stateless. + bigQuery.getOptions().setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL); String query = "SELECT 1 as one"; QueryJobConfiguration configStateless = QueryJobConfiguration.newBuilder(query).build(); TableResult result = bigQuery.query(configStateless); @@ -7181,7 +7180,7 @@ public void testStatelessQueriesWithLocation() throws Exception { table.getTableId().getTable()); // Test stateless query when BigQueryOption location matches dataset location. - bigQuery.getOptions().setQueryPreviewEnabled("TRUE"); + bigQuery.getOptions().setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL); TableResult tb = bigQuery.query(QueryJobConfiguration.of(query)); assertNull(tb.getJobId()); @@ -7189,7 +7188,9 @@ public void testStatelessQueriesWithLocation() throws Exception { try { BigQuery bigQueryWrongLocation = bigqueryHelper.getOptions().toBuilder().setLocation(wrongLocation).build().getService(); - bigQueryWrongLocation.getOptions().setQueryPreviewEnabled("TRUE"); + bigQueryWrongLocation + .getOptions() + .setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL); bigQueryWrongLocation.query(QueryJobConfiguration.of(query)); fail("querying a table with wrong location shouldn't work"); } catch (BigQueryException e) { diff --git a/pom.xml b/pom.xml index 7a49e7c8d..6d8f73a80 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-bigquery-parent pom - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT BigQuery Parent https://github.com/googleapis/java-bigquery @@ -54,7 +54,7 @@ UTF-8 github google-cloud-bigquery-parent - v2-rev20250427-2.0.0 + v2-rev20250511-2.0.0 @@ -79,7 +79,7 @@ com.google.cloud google-cloud-datacatalog-bom - 1.66.0 + 1.69.0 pom import @@ -93,7 +93,7 @@ com.google.cloud google-cloud-bigquery - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT @@ -143,13 +143,13 @@ com.google.cloud google-cloud-bigqueryconnection - 2.62.0 + 2.65.0 test com.google.api.grpc proto-google-cloud-bigqueryconnection-v1 - 2.63.0 + 2.65.0 test diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index da1da5e8c..0719a5045 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -63,13 +63,13 @@ com.google.cloud google-cloud-bigtable - 2.58.2 + 2.59.0 test com.google.cloud google-cloud-bigqueryconnection - 2.62.0 + 2.65.0 test diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index e89ec11a5..72d363949 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -44,7 +44,7 @@ com.google.cloud google-cloud-bigquery - 2.50.1-SNAPSHOT + 2.50.2-SNAPSHOT @@ -61,13 +61,13 @@ com.google.cloud google-cloud-bigtable - 2.58.2 + 2.59.0 test com.google.cloud google-cloud-bigqueryconnection - 2.62.0 + 2.65.0 test diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 0eb860c79..9ddab8dc9 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -79,13 +79,13 @@ com.google.cloud google-cloud-bigtable - 2.58.2 + 2.59.0 test com.google.cloud google-cloud-bigqueryconnection - 2.62.0 + 2.65.0 test diff --git a/samples/snippets/src/main/java/com/example/bigquery/QueryShortMode.java b/samples/snippets/src/main/java/com/example/bigquery/QueryJobOptional.java similarity index 78% rename from samples/snippets/src/main/java/com/example/bigquery/QueryShortMode.java rename to samples/snippets/src/main/java/com/example/bigquery/QueryJobOptional.java index b07f65f92..1abf58067 100644 --- a/samples/snippets/src/main/java/com/example/bigquery/QueryShortMode.java +++ b/samples/snippets/src/main/java/com/example/bigquery/QueryJobOptional.java @@ -16,34 +16,37 @@ package com.example.bigquery; -// [START bigquery_query_shortquery] +// [START bigquery_query_job_optional] import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQueryException; import com.google.cloud.bigquery.BigQueryOptions; import com.google.cloud.bigquery.JobId; import com.google.cloud.bigquery.QueryJobConfiguration; +import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode; import com.google.cloud.bigquery.TableResult; // Sample demonstrating short mode query execution. // -// While this feature is still in preview, it is controlled by -// setting the environment variable QUERY_PREVIEW_ENABLED=TRUE -// to request short mode execution. -public class QueryShortMode { +// This feature is controlled by setting the defaultJobCreationMode +// field in the BigQueryOptions used for the client. JOB_CREATION_OPTIONAL +// allows for the execution of queries without creating a job. +public class QueryJobOptional { public static void main(String[] args) { String query = "SELECT name, gender, SUM(number) AS total FROM " + "bigquery-public-data.usa_names.usa_1910_2013 GROUP BY " + "name, gender ORDER BY total DESC LIMIT 10"; - queryShortMode(query); + queryJobOptional(query); } - public static void queryShortMode(String query) { + public static void queryJobOptional(String query) { try { // Initialize client that will be used to send requests. This client only needs // to be created once, and can be reused for multiple requests. - BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); + BigQueryOptions options = BigQueryOptions.getDefaultInstance(); + options.setDefaultJobCreationMode(JobCreationMode.JOB_CREATION_OPTIONAL); + BigQuery bigquery = options.getService(); // Execute the query. The returned TableResult provides access information // about the query execution as well as query results. @@ -72,4 +75,4 @@ public static void queryShortMode(String query) { } } } -// [END bigquery_query_shortquery] +// [END bigquery_query_job_optional] diff --git a/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java b/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java index 11b1215ff..d8655a9d5 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/GrantViewAccessIT.java @@ -94,6 +94,7 @@ public void tearDown() { DeleteTable.deleteTable(viewDatasetName, viewName); DeleteTable.deleteTable(viewDatasetName, tableName); DeleteDataset.deleteDataset(PROJECT_ID, datasetName); + DeleteDataset.deleteDataset(PROJECT_ID, viewDatasetName); // restores print statements in the original method System.out.flush(); System.setOut(originalPrintStream); diff --git a/samples/snippets/src/test/java/com/example/bigquery/QueryShortModeIT.java b/samples/snippets/src/test/java/com/example/bigquery/QueryJobOptionalIT.java similarity index 95% rename from samples/snippets/src/test/java/com/example/bigquery/QueryShortModeIT.java rename to samples/snippets/src/test/java/com/example/bigquery/QueryJobOptionalIT.java index 6500de782..8e3e97909 100644 --- a/samples/snippets/src/test/java/com/example/bigquery/QueryShortModeIT.java +++ b/samples/snippets/src/test/java/com/example/bigquery/QueryJobOptionalIT.java @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Test; -public class QueryShortModeIT { +public class QueryJobOptionalIT { private final Logger log = Logger.getLogger(this.getClass().getName()); private ByteArrayOutputStream bout; @@ -56,7 +56,7 @@ public void testQueryBatch() { + "bigquery-public-data.usa_names.usa_1910_2013 GROUP BY " + "name, gender ORDER BY total DESC LIMIT 10"; - QueryShortMode.queryShortMode(query); + QueryJobOptional.queryJobOptional(query); assertThat(bout.toString()).contains("Query was run"); } } diff --git a/versions.txt b/versions.txt index 62a1992cb..00a01cc53 100644 --- a/versions.txt +++ b/versions.txt @@ -1,4 +1,4 @@ # Format: # module:released-version:current-version -google-cloud-bigquery:2.50.0:2.50.1-SNAPSHOT \ No newline at end of file +google-cloud-bigquery:2.50.1:2.50.2-SNAPSHOT \ No newline at end of file