1414 * limitations under the License.
1515 */
1616
17- package com .google .cloud .bigquery .spi ;
17+ package com .google .cloud .bigquery .spi . v2 ;
1818
19- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .ALL_DATASETS ;
20- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .ALL_USERS ;
21- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .DELETE_CONTENTS ;
22- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .FIELDS ;
23- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .MAX_RESULTS ;
24- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .PAGE_TOKEN ;
25- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .START_INDEX ;
26- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .STATE_FILTER ;
27- import static com .google .cloud .bigquery .spi .BigQueryRpc .Option .TIMEOUT ;
2819import static java .net .HttpURLConnection .HTTP_CREATED ;
2920import static java .net .HttpURLConnection .HTTP_NOT_FOUND ;
3021import static java .net .HttpURLConnection .HTTP_OK ;
6960import java .util .List ;
7061import java .util .Map ;
7162
72- public class DefaultBigQueryRpc implements BigQueryRpc {
63+ public class HttpBigQueryRpc implements BigQueryRpc {
7364
7465 public static final String DEFAULT_PROJECTION = "full" ;
7566 private static final String BASE_RESUMABLE_URI =
@@ -79,7 +70,7 @@ public class DefaultBigQueryRpc implements BigQueryRpc {
7970 private final BigQueryOptions options ;
8071 private final Bigquery bigquery ;
8172
82- public DefaultBigQueryRpc (BigQueryOptions options ) {
73+ public HttpBigQueryRpc (BigQueryOptions options ) {
8374 HttpTransportOptions transportOptions = (HttpTransportOptions ) options .getTransportOptions ();
8475 HttpTransport transport = transportOptions .getHttpTransportFactory ().create ();
8576 HttpRequestInitializer initializer = transportOptions .getHttpRequestInitializer (options );
@@ -99,7 +90,7 @@ public Dataset getDataset(String projectId, String datasetId, Map<Option, ?> opt
9990 try {
10091 return bigquery .datasets ()
10192 .get (projectId , datasetId )
102- .setFields (FIELDS .getString (options ))
93+ .setFields (Option . FIELDS .getString (options ))
10394 .execute ();
10495 } catch (IOException ex ) {
10596 BigQueryException serviceException = translate (ex );
@@ -115,10 +106,10 @@ public Tuple<String, Iterable<Dataset>> listDatasets(String projectId, Map<Optio
115106 try {
116107 DatasetList datasetsList = bigquery .datasets ()
117108 .list (projectId )
118- .setAll (ALL_DATASETS .getBoolean (options ))
119- .setMaxResults (MAX_RESULTS .getLong (options ))
120- .setPageToken (PAGE_TOKEN .getString (options ))
121- .setPageToken (PAGE_TOKEN .getString (options ))
109+ .setAll (Option . ALL_DATASETS .getBoolean (options ))
110+ .setMaxResults (Option . MAX_RESULTS .getLong (options ))
111+ .setPageToken (Option . PAGE_TOKEN .getString (options ))
112+ .setPageToken (Option . PAGE_TOKEN .getString (options ))
122113 .execute ();
123114 Iterable <DatasetList .Datasets > datasets = datasetsList .getDatasets ();
124115 return Tuple .of (datasetsList .getNextPageToken (),
@@ -143,7 +134,7 @@ public Dataset apply(DatasetList.Datasets datasetPb) {
143134 public Dataset create (Dataset dataset , Map <Option , ?> options ) {
144135 try {
145136 return bigquery .datasets ().insert (dataset .getDatasetReference ().getProjectId (), dataset )
146- .setFields (FIELDS .getString (options ))
137+ .setFields (Option . FIELDS .getString (options ))
147138 .execute ();
148139 } catch (IOException ex ) {
149140 throw translate (ex );
@@ -158,7 +149,7 @@ public Table create(Table table, Map<Option, ?> options) {
158149 TableReference reference = table .getTableReference ();
159150 return bigquery .tables ()
160151 .insert (reference .getProjectId (), reference .getDatasetId (), table )
161- .setFields (FIELDS .getString (options ))
152+ .setFields (Option . FIELDS .getString (options ))
162153 .execute ();
163154 } catch (IOException ex ) {
164155 throw translate (ex );
@@ -172,7 +163,7 @@ public Job create(Job job, Map<Option, ?> options) {
172163 ? job .getJobReference ().getProjectId () : this .options .getProjectId ();
173164 return bigquery .jobs ()
174165 .insert (projectId , job )
175- .setFields (FIELDS .getString (options ))
166+ .setFields (Option . FIELDS .getString (options ))
176167 .execute ();
177168 } catch (IOException ex ) {
178169 throw translate (ex );
@@ -183,7 +174,7 @@ public Job create(Job job, Map<Option, ?> options) {
183174 public boolean deleteDataset (String projectId , String datasetId , Map <Option , ?> options ) {
184175 try {
185176 bigquery .datasets ().delete (projectId , datasetId )
186- .setDeleteContents (DELETE_CONTENTS .getBoolean (options ))
177+ .setDeleteContents (Option . DELETE_CONTENTS .getBoolean (options ))
187178 .execute ();
188179 return true ;
189180 } catch (IOException ex ) {
@@ -201,7 +192,7 @@ public Dataset patch(Dataset dataset, Map<Option, ?> options) {
201192 DatasetReference reference = dataset .getDatasetReference ();
202193 return bigquery .datasets ()
203194 .patch (reference .getProjectId (), reference .getDatasetId (), dataset )
204- .setFields (FIELDS .getString (options ))
195+ .setFields (Option . FIELDS .getString (options ))
205196 .execute ();
206197 } catch (IOException ex ) {
207198 throw translate (ex );
@@ -216,7 +207,7 @@ public Table patch(Table table, Map<Option, ?> options) {
216207 TableReference reference = table .getTableReference ();
217208 return bigquery .tables ()
218209 .patch (reference .getProjectId (), reference .getDatasetId (), reference .getTableId (), table )
219- .setFields (FIELDS .getString (options ))
210+ .setFields (Option . FIELDS .getString (options ))
220211 .execute ();
221212 } catch (IOException ex ) {
222213 throw translate (ex );
@@ -229,7 +220,7 @@ public Table getTable(String projectId, String datasetId, String tableId,
229220 try {
230221 return bigquery .tables ()
231222 .get (projectId , datasetId , tableId )
232- .setFields (FIELDS .getString (options ))
223+ .setFields (Option . FIELDS .getString (options ))
233224 .execute ();
234225 } catch (IOException ex ) {
235226 BigQueryException serviceException = translate (ex );
@@ -246,8 +237,8 @@ public Tuple<String, Iterable<Table>> listTables(String projectId, String datase
246237 try {
247238 TableList tableList = bigquery .tables ()
248239 .list (projectId , datasetId )
249- .setMaxResults (MAX_RESULTS .getLong (options ))
250- .setPageToken (PAGE_TOKEN .getString (options ))
240+ .setMaxResults (Option . MAX_RESULTS .getLong (options ))
241+ .setPageToken (Option . PAGE_TOKEN .getString (options ))
251242 .execute ();
252243 Iterable <TableList .Tables > tables = tableList .getTables ();
253244 return Tuple .of (tableList .getNextPageToken (),
@@ -298,10 +289,10 @@ public Tuple<String, Iterable<TableRow>> listTableData(String projectId, String
298289 try {
299290 TableDataList tableDataList = bigquery .tabledata ()
300291 .list (projectId , datasetId , tableId )
301- .setMaxResults (MAX_RESULTS .getLong (options ))
302- .setPageToken (PAGE_TOKEN .getString (options ))
303- .setStartIndex (START_INDEX .getLong (options ) != null
304- ? BigInteger .valueOf (START_INDEX .getLong (options )) : null )
292+ .setMaxResults (Option . MAX_RESULTS .getLong (options ))
293+ .setPageToken (Option . PAGE_TOKEN .getString (options ))
294+ .setStartIndex (Option . START_INDEX .getLong (options ) != null
295+ ? BigInteger .valueOf (Option . START_INDEX .getLong (options )) : null )
305296 .execute ();
306297 return Tuple .<String , Iterable <TableRow >>of (tableDataList .getPageToken (),
307298 tableDataList .getRows ());
@@ -315,7 +306,7 @@ public Job getJob(String projectId, String jobId, Map<Option, ?> options) {
315306 try {
316307 return bigquery .jobs ()
317308 .get (projectId , jobId )
318- .setFields (FIELDS .getString (options ))
309+ .setFields (Option . FIELDS .getString (options ))
319310 .execute ();
320311 } catch (IOException ex ) {
321312 BigQueryException serviceException = translate (ex );
@@ -331,11 +322,11 @@ public Tuple<String, Iterable<Job>> listJobs(String projectId, Map<Option, ?> op
331322 try {
332323 JobList jobsList = bigquery .jobs ()
333324 .list (projectId )
334- .setAllUsers (ALL_USERS .getBoolean (options ))
335- .setFields (FIELDS .getString (options ))
336- .setStateFilter (STATE_FILTER .<List <String >>get (options ))
337- .setMaxResults (MAX_RESULTS .getLong (options ))
338- .setPageToken (PAGE_TOKEN .getString (options ))
325+ .setAllUsers (Option . ALL_USERS .getBoolean (options ))
326+ .setFields (Option . FIELDS .getString (options ))
327+ .setStateFilter (Option . STATE_FILTER .<List <String >>get (options ))
328+ .setMaxResults (Option . MAX_RESULTS .getLong (options ))
329+ .setPageToken (Option . PAGE_TOKEN .getString (options ))
339330 .setProjection (DEFAULT_PROJECTION )
340331 .execute ();
341332 Iterable <JobList .Jobs > jobs = jobsList .getJobs ();
@@ -386,11 +377,11 @@ public GetQueryResultsResponse getQueryResults(String projectId, String jobId,
386377 Map <Option , ?> options ) {
387378 try {
388379 return bigquery .jobs ().getQueryResults (projectId , jobId )
389- .setMaxResults (MAX_RESULTS .getLong (options ))
390- .setPageToken (PAGE_TOKEN .getString (options ))
391- .setStartIndex (START_INDEX .getLong (options ) != null
392- ? BigInteger .valueOf (START_INDEX .getLong (options )) : null )
393- .setTimeoutMs (TIMEOUT .getLong (options ))
380+ .setMaxResults (Option . MAX_RESULTS .getLong (options ))
381+ .setPageToken (Option . PAGE_TOKEN .getString (options ))
382+ .setStartIndex (Option . START_INDEX .getLong (options ) != null
383+ ? BigInteger .valueOf (Option . START_INDEX .getLong (options )) : null )
384+ .setTimeoutMs (Option . TIMEOUT .getLong (options ))
394385 .execute ();
395386 } catch (IOException ex ) {
396387 BigQueryException serviceException = translate (ex );
0 commit comments