|
17 | 17 | package com.google.cloud.bigquery;
|
18 | 18 |
|
19 | 19 | import com.google.api.core.BetaApi;
|
| 20 | +import com.google.common.util.concurrent.ListenableFuture; |
20 | 21 | import java.util.List;
|
21 | 22 | import java.util.Map;
|
22 | 23 |
|
@@ -89,4 +90,103 @@ public interface Connection {
|
89 | 90 | BigQueryResult executeSelect(
|
90 | 91 | String sql, List<Parameter> parameters, Map<String, String>... labels)
|
91 | 92 | throws BigQuerySQLException;
|
| 93 | + |
| 94 | + /** |
| 95 | + * Execute a SQL statement that returns a single ResultSet and returns a ListenableFuture to |
| 96 | + * process the response asynchronously. |
| 97 | + * |
| 98 | + * <p>Example of running a query. |
| 99 | + * |
| 100 | + * <pre> |
| 101 | + * { |
| 102 | + * @code |
| 103 | + * ConnectionSettings connectionSettings = |
| 104 | + * ConnectionSettings.newBuilder() |
| 105 | + * .setUseReadAPI(true) |
| 106 | + * .build(); |
| 107 | + * Connection connection = bigquery.createConnection(connectionSettings); |
| 108 | + * String selectQuery = "SELECT corpus FROM `bigquery-public-data.samples.shakespeare` GROUP BY corpus;"; |
| 109 | + * ListenableFuture<ExecuteSelectResponse> executeSelectFuture = connection.executeSelectAsync(selectQuery); |
| 110 | + * ExecuteSelectResponse executeSelectRes = executeSelectFuture.get(); |
| 111 | + * |
| 112 | + * if(!executeSelectRes.getIsSuccessful()){ |
| 113 | + * throw executeSelectRes.getBigQuerySQLException(); |
| 114 | + * } |
| 115 | + * |
| 116 | + * BigQueryResult bigQueryResult = executeSelectRes.getBigQueryResult(); |
| 117 | + * ResultSet rs = bigQueryResult.getResultSet(); |
| 118 | + * while (rs.next()) { |
| 119 | + * System.out.println(rs.getString(1)); |
| 120 | + * } |
| 121 | + * |
| 122 | + * </pre> |
| 123 | + * |
| 124 | + * @param sql a static SQL SELECT statement |
| 125 | + * @return a ListenableFuture that is used to get the data produced by the query |
| 126 | + * @throws BigQuerySQLException upon failure |
| 127 | + */ |
| 128 | + @BetaApi |
| 129 | + ListenableFuture<ExecuteSelectResponse> executeSelectAsync(String sql) |
| 130 | + throws BigQuerySQLException; |
| 131 | + |
| 132 | + /** |
| 133 | + * Execute a SQL statement that returns a single ResultSet and returns a ListenableFuture to |
| 134 | + * process the response asynchronously. |
| 135 | + * |
| 136 | + * <p>Example of running a query. |
| 137 | + * |
| 138 | + * <pre> |
| 139 | + * { |
| 140 | + * @code |
| 141 | + * ConnectionSettings connectionSettings = |
| 142 | + * ConnectionSettings.newBuilder() |
| 143 | + * ..setUseReadAPI(true) |
| 144 | + * .build(); |
| 145 | + * Connection connection = bigquery.createConnection(connectionSettings); |
| 146 | + * String selectQuery = |
| 147 | + * "SELECT TimestampField, StringField, BooleanField FROM " |
| 148 | + * + MY_TABLE |
| 149 | + * + " WHERE StringField = @stringParam" |
| 150 | + * + " AND IntegerField IN UNNEST(@integerList)"; |
| 151 | + * QueryParameterValue stringParameter = QueryParameterValue.string("stringValue"); |
| 152 | + * QueryParameterValue intArrayParameter = |
| 153 | + * QueryParameterValue.array(new Integer[] {3, 4}, Integer.class); |
| 154 | + * Parameter stringParam = |
| 155 | + * Parameter.newBuilder().setName("stringParam").setValue(stringParameter).build(); |
| 156 | + * Parameter intArrayParam = |
| 157 | + * Parameter.newBuilder().setName("integerList").setValue(intArrayParameter).build(); |
| 158 | + * List<Parameter> parameters = ImmutableList.of(stringParam, intArrayParam); |
| 159 | + * |
| 160 | + * ListenableFuture<ExecuteSelectResponse> executeSelectFut = |
| 161 | + * connection.executeSelectAsync(selectQuery, parameters); |
| 162 | + * ExecuteSelectResponse executeSelectRes = executeSelectFuture.get(); |
| 163 | + * |
| 164 | + * if(!executeSelectRes.getIsSuccessful()){ |
| 165 | + * throw executeSelectRes.getBigQuerySQLException(); |
| 166 | + * } |
| 167 | + * |
| 168 | + * BigQueryResult bigQueryResult = executeSelectRes.getBigQueryResult(); |
| 169 | + * ResultSet rs = bigQueryResult.getResultSet(); |
| 170 | + * while (rs.next()) { |
| 171 | + * System.out.println(rs.getString(1)); |
| 172 | + * } |
| 173 | + * |
| 174 | + * </pre> |
| 175 | + * |
| 176 | + * @param sql SQL SELECT query |
| 177 | + * @param parameters named or positional parameters. The set of query parameters must either be |
| 178 | + * all positional or all named parameters. |
| 179 | + * @param labels (optional) the labels associated with this query. You can use these to organize |
| 180 | + * and group your query jobs. Label keys and values can be no longer than 63 characters, can |
| 181 | + * only contain lowercase letters, numeric characters, underscores and dashes. International |
| 182 | + * characters are allowed. Label values are optional and Label is a Varargs. You should pass |
| 183 | + * all the Labels in a single Map .Label keys must start with a letter and each label in the |
| 184 | + * list must have a different key. |
| 185 | + * @return a ListenableFuture that is used to get the data produced by the query |
| 186 | + * @throws BigQuerySQLException upon failure |
| 187 | + */ |
| 188 | + @BetaApi |
| 189 | + ListenableFuture<ExecuteSelectResponse> executeSelectAsync( |
| 190 | + String sql, List<Parameter> parameters, Map<String, String>... labels) |
| 191 | + throws BigQuerySQLException; |
92 | 192 | }
|
0 commit comments