[go: up one dir, main page]

Skip to content

Commit

Permalink
feat: Add executeSelectAsync and Refactor (#2294)
Browse files Browse the repository at this point in the history
* Add executeSelectAsync

* Add executeSelectAsync

* Add ExecuteSelectResponse

* Add executeSelectAsync(...) methods

* feat: Add executeSelectAsync

* implemented ExecuteSelectResponse Builder

* Refactored executeSelect. Added getExecuteSelectResponse

* marked getExecuteSelectFuture private

* marked getExecuteSelectFuture private

* Add UT for Async methods

* Added IT for async methods

* Removed testFastQueryNullSchema as it is no longer needed

* removed dryRun calls as now we wait till the job is complete

* Added testExecuteSelectAsyncTimeout

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* updated getExecuteSelectFuture

* lint

* Add getters and setters for BigQuerySQLException

* Add javadoc for overloaded executeSelectAsync and refactored getExecuteSelectFuture to handle BigQuerySQLException

* Marked ResultSet and BQSQLException optional

* minor refactor: getExecuteSelectFuture

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* update getExecuteSelectFuture

* update javadoc

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
prash-mi and gcf-owl-bot[bot] committed Oct 12, 2022
1 parent 827e5e7 commit 80fa478
Show file tree
Hide file tree
Showing 6 changed files with 613 additions and 93 deletions.
12 changes: 11 additions & 1 deletion google-cloud-bigquery/clirr-ignored-differences.xml
Expand Up @@ -24,4 +24,14 @@
<className>com/google/cloud/bigquery/RoutineInfo*</className>
<method>*RemoteFunctionOptions(*)</method>
</difference>
</differences>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/bigquery/Connection</className>
<method>com.google.common.util.concurrent.ListenableFuture executeSelectAsync(java.lang.String)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/bigquery/Connection</className>
<method>com.google.common.util.concurrent.ListenableFuture executeSelectAsync(java.lang.String, java.util.List, java.util.Map[])</method>
</difference>
</differences>
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.bigquery;

import com.google.api.core.BetaApi;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -89,4 +90,103 @@ public interface Connection {
BigQueryResult executeSelect(
String sql, List<Parameter> parameters, Map<String, String>... labels)
throws BigQuerySQLException;

/**
* Execute a SQL statement that returns a single ResultSet and returns a ListenableFuture to
* process the response asynchronously.
*
* <p>Example of running a query.
*
* <pre>
* {
* &#64;code
* ConnectionSettings connectionSettings =
* ConnectionSettings.newBuilder()
* .setUseReadAPI(true)
* .build();
* Connection connection = bigquery.createConnection(connectionSettings);
* String selectQuery = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;";
* ListenableFuture<ExecuteSelectResponse> executeSelectFuture = connection.executeSelectAsync(selectQuery);
* ExecuteSelectResponse executeSelectRes = executeSelectFuture.get();
*
* if(!executeSelectRes.getIsSuccessful()){
* throw executeSelectRes.getBigQuerySQLException();
* }
*
* BigQueryResult bigQueryResult = executeSelectRes.getBigQueryResult();
* ResultSet rs = bigQueryResult.getResultSet();
* while (rs.next()) {
* System.out.println(rs.getString(1));
* }
*
* </pre>
*
* @param sql a static SQL SELECT statement
* @return a ListenableFuture that is used to get the data produced by the query
* @throws BigQuerySQLException upon failure
*/
@BetaApi
ListenableFuture<ExecuteSelectResponse> executeSelectAsync(String sql)
throws BigQuerySQLException;

/**
* Execute a SQL statement that returns a single ResultSet and returns a ListenableFuture to
* process the response asynchronously.
*
* <p>Example of running a query.
*
* <pre>
* {
* &#64;code
* ConnectionSettings connectionSettings =
* ConnectionSettings.newBuilder()
* ..setUseReadAPI(true)
* .build();
* Connection connection = bigquery.createConnection(connectionSettings);
* String selectQuery =
* "SELECT TimestampField, StringField, BooleanField FROM "
* + MY_TABLE
* + " WHERE StringField = @stringParam"
* + " AND IntegerField IN UNNEST(@integerList)";
* QueryParameterValue stringParameter = QueryParameterValue.string("stringValue");
* QueryParameterValue intArrayParameter =
* QueryParameterValue.array(new Integer[] {3, 4}, Integer.class);
* Parameter stringParam =
* Parameter.newBuilder().setName("stringParam").setValue(stringParameter).build();
* Parameter intArrayParam =
* Parameter.newBuilder().setName("integerList").setValue(intArrayParameter).build();
* List<Parameter> parameters = ImmutableList.of(stringParam, intArrayParam);
*
* ListenableFuture<ExecuteSelectResponse> executeSelectFut =
* connection.executeSelectAsync(selectQuery, parameters);
* ExecuteSelectResponse executeSelectRes = executeSelectFuture.get();
*
* if(!executeSelectRes.getIsSuccessful()){
* throw executeSelectRes.getBigQuerySQLException();
* }
*
* BigQueryResult bigQueryResult = executeSelectRes.getBigQueryResult();
* ResultSet rs = bigQueryResult.getResultSet();
* while (rs.next()) {
* System.out.println(rs.getString(1));
* }
*
* </pre>
*
* @param sql SQL SELECT query
* @param parameters named or positional parameters. The set of query parameters must either be
* all positional or all named parameters.
* @param labels (optional) the labels associated with this query. You can use these to organize
* and group your query jobs. Label keys and values can be no longer than 63 characters, can
* only contain lowercase letters, numeric characters, underscores and dashes. International
* characters are allowed. Label values are optional and Label is a Varargs. You should pass
* all the Labels in a single Map .Label keys must start with a letter and each label in the
* list must have a different key.
* @return a ListenableFuture that is used to get the data produced by the query
* @throws BigQuerySQLException upon failure
*/
@BetaApi
ListenableFuture<ExecuteSelectResponse> executeSelectAsync(
String sql, List<Parameter> parameters, Map<String, String>... labels)
throws BigQuerySQLException;
}

0 comments on commit 80fa478

Please sign in to comment.