Skip to content

Commit 75a2660

Browse files
committed
---
yaml --- r: 1877 b: refs/heads/pubsub-alpha c: 3b70b20 h: refs/heads/master i: 1875: 77e9070
1 parent d79ea8a commit 75a2660

3 files changed

Lines changed: 106 additions & 99 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 36c7406f979840271cefe2cf1b06509df7ea2a33
6+
refs/heads/pubsub-alpha: 3b70b20e36fa78f742d5bb4ce9a6cb126f53bd3f
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/spi/BigQueryRpc.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
import com.google.api.services.bigquery.model.Dataset;
2020
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
2121
import com.google.api.services.bigquery.model.Job;
22-
import com.google.api.services.bigquery.model.JobReference;
2322
import com.google.api.services.bigquery.model.QueryRequest;
2423
import com.google.api.services.bigquery.model.QueryResponse;
2524
import com.google.api.services.bigquery.model.Table;
2625
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
2726
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
28-
import com.google.api.services.bigquery.model.TableReference;
2927
import com.google.api.services.bigquery.model.TableRow;
3028
import com.google.gcloud.bigquery.BigQueryException;
3129

@@ -113,6 +111,10 @@ public Y y() {
113111

114112
Dataset create(Dataset dataset, Map<Option, ?> options) throws BigQueryException;
115113

114+
Table create(Table table, Map<Option, ?> options) throws BigQueryException;
115+
116+
Job create(Job job, Map<Option, ?> options) throws BigQueryException;
117+
116118
/**
117119
* Delete the requested dataset.
118120
*
@@ -123,6 +125,8 @@ public Y y() {
123125

124126
Dataset patch(Dataset dataset, Map<Option, ?> options) throws BigQueryException;
125127

128+
Table patch(Table table, Map<Option, ?> options) throws BigQueryException;
129+
126130
/**
127131
* Returns the requested table or {@code null} if not found.
128132
*
@@ -139,21 +143,16 @@ public Y y() {
139143
Tuple<String, Iterable<Table>> listTables(String dataset, Map<Option, ?> options)
140144
throws BigQueryException;
141145

142-
Table create(Table table, Map<Option, ?> options) throws BigQueryException;
143-
144146
/**
145147
* Delete the requested table.
146148
*
147149
* @return {@code true} if table was deleted, {@code false} if it was not found
148150
* @throws BigQueryException upon failure
149151
*/
150-
boolean deleteTable(String datasetId, String tableId, Map<Option, ?> options)
151-
throws BigQueryException;
152+
boolean deleteTable(String datasetId, String tableId) throws BigQueryException;
152153

153-
Table patch(Table table, Map<Option, ?> options) throws BigQueryException;
154-
155-
TableDataInsertAllResponse insertAll(TableReference table, TableDataInsertAllRequest request,
156-
Map<Option, ?> options) throws BigQueryException;
154+
TableDataInsertAllResponse insertAll(String datasetId, String tableId,
155+
TableDataInsertAllRequest request) throws BigQueryException;
157156

158157
Tuple<String, Iterable<TableRow>> listTableData(String datasetId, String tableId,
159158
Map<Option, ?> options) throws BigQueryException;
@@ -172,12 +171,18 @@ Tuple<String, Iterable<TableRow>> listTableData(String datasetId, String tableId
172171
*/
173172
Tuple<String, Iterable<Job>> listJobs(Map<Option, ?> options) throws BigQueryException;
174173

175-
Job create(Job job, Map<Option, ?> options) throws BigQueryException;
176-
177-
boolean cancel(String jobId, Map<Option, ?> options) throws BigQueryException;
174+
/**
175+
* Sends a job cancel request. This call will return immediately, and the client will need to poll
176+
* for the job status to see if the cancel completed successfully.
177+
*
178+
* @return {@code true} if cancel was requested successfully, {@code false} if the job was not
179+
* found
180+
* @throws BigQueryException upon failure
181+
*/
182+
boolean cancel(String jobId) throws BigQueryException;
178183

179-
GetQueryResultsResponse getQueryResults(JobReference job, Map<Option, ?> options)
184+
GetQueryResultsResponse getQueryResults(String jobId, Map<Option, ?> options)
180185
throws BigQueryException;
181186

182-
QueryResponse query(QueryRequest request, Map<Option, ?> options) throws BigQueryException;
187+
QueryResponse query(QueryRequest request) throws BigQueryException;
183188
}

branches/pubsub-alpha/gcloud-java-bigquery/src/main/java/com/google/gcloud/spi/DefaultBigQueryRpc.java

Lines changed: 85 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import static com.google.gcloud.spi.BigQueryRpc.Option.DELETE_CONTENTS;
1818
import static com.google.gcloud.spi.BigQueryRpc.Option.FIELDS;
19+
import static com.google.gcloud.spi.BigQueryRpc.Option.MAX_RESULTS;
20+
import static com.google.gcloud.spi.BigQueryRpc.Option.PAGE_TOKEN;
1921
import static com.google.gcloud.spi.BigQueryRpc.Option.START_INDEX;
2022
import static com.google.gcloud.spi.BigQueryRpc.Option.TIMEOUT;
2123
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
@@ -32,7 +34,6 @@
3234
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
3335
import com.google.api.services.bigquery.model.Job;
3436
import com.google.api.services.bigquery.model.JobList;
35-
import com.google.api.services.bigquery.model.JobReference;
3637
import com.google.api.services.bigquery.model.JobStatus;
3738
import com.google.api.services.bigquery.model.QueryRequest;
3839
import com.google.api.services.bigquery.model.QueryResponse;
@@ -48,9 +49,6 @@
4849
import com.google.common.collect.ImmutableSet;
4950
import com.google.common.collect.Iterables;
5051

51-
import static com.google.gcloud.spi.BigQueryRpc.Option.MAX_RESULTS;
52-
import static com.google.gcloud.spi.BigQueryRpc.Option.PAGE_TOKEN;
53-
5452
import com.google.gcloud.bigquery.BigQueryException;
5553
import com.google.gcloud.bigquery.BigQueryOptions;
5654

@@ -103,7 +101,7 @@ public Dataset getDataset(String datasetId, Map<Option, ?> options) throws BigQu
103101
.get(this.options.projectId(), datasetId)
104102
.setFields(FIELDS.getString(options))
105103
.execute();
106-
} catch(IOException ex) {
104+
} catch (IOException ex) {
107105
BigQueryException serviceException = translate(ex);
108106
if (serviceException.code() == HTTP_NOT_FOUND) {
109107
return null;
@@ -124,15 +122,16 @@ public Tuple<String, Iterable<Dataset>> listDatasets(Map<Option, ?> options)
124122
.execute();
125123
Iterable<DatasetList.Datasets> datasets = datasetsList.getDatasets();
126124
return Tuple.of(datasetsList.getNextPageToken(),
127-
Iterables.transform(datasets != null ? datasets : ImmutableList.<DatasetList.Datasets>of(),
125+
Iterables.transform(datasets != null ? datasets :
126+
ImmutableList.<DatasetList.Datasets>of(),
128127
new Function<DatasetList.Datasets, Dataset>() {
129128
@Override
130-
public Dataset apply(DatasetList.Datasets f) {
129+
public Dataset apply(DatasetList.Datasets datasetPb) {
131130
return new Dataset()
132-
.setDatasetReference(f.getDatasetReference())
133-
.setFriendlyName(f.getFriendlyName())
134-
.setId(f.getId())
135-
.setKind(f.getKind());
131+
.setDatasetReference(datasetPb.getDatasetReference())
132+
.setFriendlyName(datasetPb.getFriendlyName())
133+
.setId(datasetPb.getId())
134+
.setKind(datasetPb.getKind());
136135
}
137136
}));
138137
} catch (IOException ex) {
@@ -151,6 +150,33 @@ public Dataset create(Dataset dataset, Map<Option, ?> options) throws BigQueryEx
151150
}
152151
}
153152

153+
@Override
154+
public Table create(Table table, Map<Option, ?> options)
155+
throws BigQueryException {
156+
try {
157+
// unset the type, as it is output only
158+
table.setType(null);
159+
return bigquery.tables()
160+
.insert(this.options.projectId(), table.getTableReference().getDatasetId(), table)
161+
.setFields(FIELDS.getString(options))
162+
.execute();
163+
} catch (IOException ex) {
164+
throw translate(ex);
165+
}
166+
}
167+
168+
@Override
169+
public Job create(Job job, Map<Option, ?> options) throws BigQueryException {
170+
try {
171+
return bigquery.jobs()
172+
.insert(this.options.projectId(), job)
173+
.setFields(FIELDS.getString(options))
174+
.execute();
175+
} catch (IOException ex) {
176+
throw translate(ex);
177+
}
178+
}
179+
154180
@Override
155181
public boolean deleteDataset(String datasetId, Map<Option, ?> options) throws BigQueryException {
156182
try {
@@ -180,6 +206,21 @@ public Dataset patch(Dataset dataset, Map<Option, ?> options) throws BigQueryExc
180206
}
181207
}
182208

209+
@Override
210+
public Table patch(Table table, Map<Option, ?> options) throws BigQueryException {
211+
try {
212+
// unset the type, as it is output only
213+
table.setType(null);
214+
TableReference reference = table.getTableReference();
215+
return bigquery.tables()
216+
.patch(this.options.projectId(), reference.getDatasetId(), reference.getTableId(), table)
217+
.setFields(FIELDS.getString(options))
218+
.execute();
219+
} catch (IOException ex) {
220+
throw translate(ex);
221+
}
222+
}
223+
183224
@Override
184225
public Table getTable(String datasetId, String tableId, Map<Option, ?> options)
185226
throws BigQueryException {
@@ -188,7 +229,7 @@ public Table getTable(String datasetId, String tableId, Map<Option, ?> options)
188229
.get(this.options.projectId(), datasetId, tableId)
189230
.setFields(FIELDS.getString(options))
190231
.execute();
191-
} catch(IOException ex) {
232+
} catch (IOException ex) {
192233
BigQueryException serviceException = translate(ex);
193234
if (serviceException.code() == HTTP_NOT_FOUND) {
194235
return null;
@@ -211,13 +252,13 @@ public Tuple<String, Iterable<Table>> listTables(String datasetId, Map<Option, ?
211252
Iterables.transform(tables != null ? tables : ImmutableList.<TableList.Tables>of(),
212253
new Function<TableList.Tables, Table>() {
213254
@Override
214-
public Table apply(TableList.Tables f) {
255+
public Table apply(TableList.Tables tablePb) {
215256
return new Table()
216-
.setFriendlyName(f.getFriendlyName())
217-
.setId(f.getId())
218-
.setKind(f.getKind())
219-
.setTableReference(f.getTableReference())
220-
.setType(f.getType());
257+
.setFriendlyName(tablePb.getFriendlyName())
258+
.setId(tablePb.getId())
259+
.setKind(tablePb.getKind())
260+
.setTableReference(tablePb.getTableReference())
261+
.setType(tablePb.getType());
221262
}
222263
}));
223264
} catch (IOException ex) {
@@ -226,21 +267,7 @@ public Table apply(TableList.Tables f) {
226267
}
227268

228269
@Override
229-
public Table create(Table table, Map<Option, ?> options)
230-
throws BigQueryException {
231-
try {
232-
return bigquery.tables()
233-
.insert(this.options.projectId(), table.getTableReference().getDatasetId(), table)
234-
.setFields(FIELDS.getString(options))
235-
.execute();
236-
} catch (IOException ex) {
237-
throw translate(ex);
238-
}
239-
}
240-
241-
@Override
242-
public boolean deleteTable(String datasetId, String tableId, Map<Option, ?> options)
243-
throws BigQueryException {
270+
public boolean deleteTable(String datasetId, String tableId) throws BigQueryException {
244271
try {
245272
bigquery.tables().delete(this.options.projectId(), datasetId, tableId).execute();
246273
return true;
@@ -254,24 +281,11 @@ public boolean deleteTable(String datasetId, String tableId, Map<Option, ?> opti
254281
}
255282

256283
@Override
257-
public Table patch(Table table, Map<Option, ?> options) throws BigQueryException {
258-
try {
259-
TableReference reference = table.getTableReference();
260-
return bigquery.tables()
261-
.patch(this.options.projectId(), reference.getDatasetId(), reference.getTableId(), table)
262-
.setFields(FIELDS.getString(options))
263-
.execute();
264-
} catch (IOException ex) {
265-
throw translate(ex);
266-
}
267-
}
268-
269-
@Override
270-
public TableDataInsertAllResponse insertAll(TableReference table,
271-
TableDataInsertAllRequest request, Map<Option, ?> options) throws BigQueryException {
284+
public TableDataInsertAllResponse insertAll(String datasetId, String tableId,
285+
TableDataInsertAllRequest request) throws BigQueryException {
272286
try {
273287
return bigquery.tabledata()
274-
.insertAll(this.options.projectId(), table.getDatasetId(), table.getTableId(), request)
288+
.insertAll(this.options.projectId(), datasetId, tableId, request)
275289
.execute();
276290
} catch (IOException ex) {
277291
throw translate(ex);
@@ -286,8 +300,8 @@ public Tuple<String, Iterable<TableRow>> listTableData(String datasetId, String
286300
.list(this.options.projectId(), datasetId, tableId)
287301
.setMaxResults(MAX_RESULTS.getLong(options))
288302
.setPageToken(PAGE_TOKEN.getString(options))
289-
.setStartIndex(START_INDEX.getLong(options) != null ?
290-
BigInteger.valueOf(START_INDEX.getLong(options)) : null)
303+
.setStartIndex(START_INDEX.getLong(options) != null
304+
? BigInteger.valueOf(START_INDEX.getLong(options)) : null)
291305
.execute();
292306
return Tuple.<String, Iterable<TableRow>>of(tableDataList.getPageToken(),
293307
tableDataList.getRows());
@@ -303,7 +317,7 @@ public Job getJob(String jobId, Map<Option, ?> options) throws BigQueryException
303317
.get(this.options.projectId(), jobId)
304318
.setFields(FIELDS.getString(options))
305319
.execute();
306-
} catch(IOException ex) {
320+
} catch (IOException ex) {
307321
BigQueryException serviceException = translate(ex);
308322
if (serviceException.code() == HTTP_NOT_FOUND) {
309323
return null;
@@ -329,22 +343,23 @@ public Tuple<String, Iterable<Job>> listJobs(Map<Option, ?> options) throws BigQ
329343
Iterables.transform(jobs != null ? jobs : ImmutableList.<JobList.Jobs>of(),
330344
new Function<JobList.Jobs, Job>() {
331345
@Override
332-
public Job apply(JobList.Jobs f) {
333-
JobStatus statusPb = f.getStatus() != null ? f.getStatus() : new JobStatus();
346+
public Job apply(JobList.Jobs jobPb) {
347+
JobStatus statusPb = jobPb.getStatus() != null
348+
? jobPb.getStatus() : new JobStatus();
334349
if (statusPb.getState() == null) {
335-
statusPb.setState(f.getState());
350+
statusPb.setState(jobPb.getState());
336351
}
337352
if (statusPb.getErrorResult() == null) {
338-
statusPb.setErrorResult(f.getErrorResult());
353+
statusPb.setErrorResult(jobPb.getErrorResult());
339354
}
340355
return new Job()
341-
.setConfiguration(f.getConfiguration())
342-
.setId(f.getId())
343-
.setJobReference(f.getJobReference())
344-
.setKind(f.getKind())
345-
.setStatistics(f.getStatistics())
346-
.setStatus(f.getStatus())
347-
.setUserEmail(f.getUserEmail());
356+
.setConfiguration(jobPb.getConfiguration())
357+
.setId(jobPb.getId())
358+
.setJobReference(jobPb.getJobReference())
359+
.setKind(jobPb.getKind())
360+
.setStatistics(jobPb.getStatistics())
361+
.setStatus(statusPb)
362+
.setUserEmail(jobPb.getUserEmail());
348363
}
349364
}));
350365
} catch (IOException ex) {
@@ -353,19 +368,7 @@ public Job apply(JobList.Jobs f) {
353368
}
354369

355370
@Override
356-
public Job create(Job job, Map<Option, ?> options) throws BigQueryException {
357-
try {
358-
return bigquery.jobs()
359-
.insert(this.options.projectId(), job)
360-
.setFields(FIELDS.getString(options))
361-
.execute();
362-
} catch (IOException ex) {
363-
throw translate(ex);
364-
}
365-
}
366-
367-
@Override
368-
public boolean cancel(String jobId, Map<Option, ?> options) throws BigQueryException {
371+
public boolean cancel(String jobId) throws BigQueryException {
369372
try {
370373
bigquery.jobs().cancel(this.options.projectId(), jobId).execute();
371374
return true;
@@ -379,17 +382,17 @@ public boolean cancel(String jobId, Map<Option, ?> options) throws BigQueryExcep
379382
}
380383

381384
@Override
382-
public GetQueryResultsResponse getQueryResults(JobReference job, Map<Option, ?> options)
385+
public GetQueryResultsResponse getQueryResults(String jobId, Map<Option, ?> options)
383386
throws BigQueryException {
384387
try {
385-
return bigquery.jobs().getQueryResults(this.options.projectId(), job.getJobId())
388+
return bigquery.jobs().getQueryResults(this.options.projectId(), jobId)
386389
.setMaxResults(MAX_RESULTS.getLong(options))
387390
.setPageToken(PAGE_TOKEN.getString(options))
388-
.setStartIndex(START_INDEX.getLong(options) != null ?
389-
BigInteger.valueOf(START_INDEX.getLong(options)) : null)
391+
.setStartIndex(START_INDEX.getLong(options) != null
392+
? BigInteger.valueOf(START_INDEX.getLong(options)) : null)
390393
.setTimeoutMs(TIMEOUT.getLong(options))
391394
.execute();
392-
} catch(IOException ex) {
395+
} catch (IOException ex) {
393396
BigQueryException serviceException = translate(ex);
394397
if (serviceException.code() == HTTP_NOT_FOUND) {
395398
return null;
@@ -399,8 +402,7 @@ public GetQueryResultsResponse getQueryResults(JobReference job, Map<Option, ?>
399402
}
400403

401404
@Override
402-
public QueryResponse query(QueryRequest request, Map<Option, ?> options)
403-
throws BigQueryException {
405+
public QueryResponse query(QueryRequest request) throws BigQueryException {
404406
try {
405407
return bigquery.jobs().query(this.options.projectId(), request).execute();
406408
} catch (IOException ex) {

0 commit comments

Comments
 (0)