16
16
17
17
package com .google .gcloud .bigquery ;
18
18
19
+ import static com .google .common .base .Preconditions .checkArgument ;
20
+
19
21
import com .google .common .base .Function ;
22
+ import com .google .common .base .Joiner ;
20
23
import com .google .common .collect .ImmutableList ;
21
24
import com .google .common .collect .Lists ;
22
25
import com .google .common .collect .Sets ;
26
29
27
30
import java .util .HashSet ;
28
31
import java .util .List ;
32
+ import java .util .Set ;
29
33
30
34
/**
31
35
* An interface for Google Cloud BigQuery.
34
38
*/
35
39
public interface BigQuery extends Service <BigQueryOptions > {
36
40
41
+ /**
42
+ * Fields of a BigQuery Dataset resource.
43
+ *
44
+ * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/datasets#resource">Dataset
45
+ * Resource</a>
46
+ */
37
47
enum DatasetField {
38
48
ACCESS ("access" ),
39
49
CREATION_TIME ("creationTime" ),
40
50
DATASET_REFERENCE ("datasetReference" ),
41
- DEFAULT_TABLE_EXPIRATION_MS ("defaultTableLifetime " ),
51
+ DEFAULT_TABLE_EXPIRATION_MS ("defaultTableExpirationMsS " ),
42
52
DESCRIPTION ("description" ),
43
53
ETAG ("etag" ),
44
54
FRIENDLY_NAME ("friendlyName" ),
@@ -58,15 +68,21 @@ public String selector() {
58
68
}
59
69
60
70
static String selector (DatasetField ... fields ) {
61
- HashSet <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 1 );
71
+ Set <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 1 );
62
72
fieldStrings .add (DATASET_REFERENCE .selector ());
63
73
for (DatasetField field : fields ) {
64
74
fieldStrings .add (field .selector ());
65
75
}
66
- return com . google . common . base . Joiner .on (',' ).join (fieldStrings );
76
+ return Joiner .on (',' ).join (fieldStrings );
67
77
}
68
78
}
69
79
80
+ /**
81
+ * Fields of a BigQuery Table resource.
82
+ *
83
+ * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables#resource">Table
84
+ * Resource</a>
85
+ */
70
86
enum TableField {
71
87
CREATION_TIME ("creationTime" ),
72
88
DESCRIPTION ("description" ),
@@ -97,16 +113,22 @@ public String selector() {
97
113
}
98
114
99
115
static String selector (TableField ... fields ) {
100
- HashSet <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 2 );
116
+ Set <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 2 );
101
117
fieldStrings .add (TABLE_REFERENCE .selector ());
102
118
fieldStrings .add (TYPE .selector ());
103
119
for (TableField field : fields ) {
104
120
fieldStrings .add (field .selector ());
105
121
}
106
- return com . google . common . base . Joiner .on (',' ).join (fieldStrings );
122
+ return Joiner .on (',' ).join (fieldStrings );
107
123
}
108
124
}
109
125
126
+ /**
127
+ * Fields of a BigQuery Job resource.
128
+ *
129
+ * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#resource">Job Resource
130
+ * </a>
131
+ */
110
132
enum JobField {
111
133
CONFIGURATION ("configuration" ),
112
134
ETAG ("etag" ),
@@ -134,7 +156,7 @@ static String selector(JobField... fields) {
134
156
for (JobField field : fields ) {
135
157
fieldStrings .add (field .selector ());
136
158
}
137
- return com . google . common . base . Joiner .on (',' ).join (fieldStrings );
159
+ return Joiner .on (',' ).join (fieldStrings );
138
160
}
139
161
}
140
162
@@ -184,7 +206,7 @@ private DatasetOption(BigQueryRpc.Option option, Object value) {
184
206
185
207
/**
186
208
* Returns an option to specify the dataset's fields to be returned by the RPC call. If this
187
- * option is not provided all dataset's fields are returned. {@code DatasetOption.fields}) can
209
+ * option is not provided all dataset's fields are returned. {@code DatasetOption.fields} can
188
210
* be used to specify only the fields of interest. {@link DatasetInfo#datasetId()} is always
189
211
* returned, even if not specified.
190
212
*/
@@ -228,6 +250,7 @@ private TableListOption(BigQueryRpc.Option option, Object value) {
228
250
* Returns an option to specify the maximum number of tables to be returned.
229
251
*/
230
252
public static TableListOption maxResults (long maxResults ) {
253
+ checkArgument (maxResults >= 0 );
231
254
return new TableListOption (BigQueryRpc .Option .MAX_RESULTS , maxResults );
232
255
}
233
256
@@ -252,7 +275,7 @@ private TableOption(BigQueryRpc.Option option, Object value) {
252
275
253
276
/**
254
277
* Returns an option to specify the table's fields to be returned by the RPC call. If this
255
- * option is not provided all table's fields are returned. {@code TableOption.fields}) can be
278
+ * option is not provided all table's fields are returned. {@code TableOption.fields} can be
256
279
* used to specify only the fields of interest. {@link BaseTableInfo#tableId()} and
257
280
* {@link BaseTableInfo#type()} are always returned, even if not specified.
258
281
*/
@@ -276,6 +299,7 @@ private TableDataListOption(BigQueryRpc.Option option, Object value) {
276
299
* Returns an option to specify the maximum number of rows to be returned.
277
300
*/
278
301
public static TableDataListOption maxResults (long maxResults ) {
302
+ checkArgument (maxResults >= 0 );
279
303
return new TableDataListOption (BigQueryRpc .Option .MAX_RESULTS , maxResults );
280
304
}
281
305
@@ -291,6 +315,7 @@ public static TableDataListOption startPageToken(String pageToken) {
291
315
* data.
292
316
*/
293
317
public static TableDataListOption startIndex (long index ) {
318
+ checkArgument (index >= 0 );
294
319
return new TableDataListOption (BigQueryRpc .Option .START_INDEX , index );
295
320
}
296
321
}
@@ -314,14 +339,14 @@ public static JobListOption allUsers() {
314
339
}
315
340
316
341
/**
317
- * Returns an option to list only jobs that match the provided filters.
342
+ * Returns an option to list only jobs that match the provided state filters.
318
343
*/
319
344
public static JobListOption stateFilter (JobStatus .State ... stateFilters ) {
320
345
List <String > stringFilters = Lists .transform (ImmutableList .copyOf (stateFilters ),
321
346
new Function <JobStatus .State , String >() {
322
347
@ Override
323
348
public String apply (JobStatus .State state ) {
324
- return state .toString ().toLowerCase ();
349
+ return state .name ().toLowerCase ();
325
350
}
326
351
});
327
352
return new JobListOption (BigQueryRpc .Option .STATE_FILTER , stringFilters );
@@ -331,6 +356,7 @@ public String apply(JobStatus.State state) {
331
356
* Returns an option to specify the maximum number of jobs to be returned.
332
357
*/
333
358
public static JobListOption maxResults (long maxResults ) {
359
+ checkArgument (maxResults >= 0 );
334
360
return new JobListOption (BigQueryRpc .Option .MAX_RESULTS , maxResults );
335
361
}
336
362
@@ -343,7 +369,7 @@ public static JobListOption startPageToken(String pageToken) {
343
369
344
370
/**
345
371
* Returns an option to specify the job's fields to be returned by the RPC call. If this option
346
- * is not provided all job's fields are returned. {@code JobOption.fields()}) can be used to
372
+ * is not provided all job's fields are returned. {@code JobOption.fields()} can be used to
347
373
* specify only the fields of interest. {@link JobInfo#jobId()}, {@link JobStatus#state()},
348
374
* {@link JobStatus#error()} as well as type-specific configuration (e.g.
349
375
* {@link QueryJobInfo#query()} for Query Jobs) are always returned, even if not specified.
@@ -370,7 +396,7 @@ private JobOption(BigQueryRpc.Option option, Object value) {
370
396
371
397
/**
372
398
* Returns an option to specify the job's fields to be returned by the RPC call. If this option
373
- * is not provided all job's fields are returned. {@code JobOption.fields}) can be used to
399
+ * is not provided all job's fields are returned. {@code JobOption.fields()} can be used to
374
400
* specify only the fields of interest. {@link JobInfo#jobId()} as well as type-specific
375
401
* configuration (e.g. {@link QueryJobInfo#query()} for Query Jobs) are always returned, even if
376
402
* not specified.
@@ -395,21 +421,23 @@ private QueryResultsOption(BigQueryRpc.Option option, Object value) {
395
421
* Returns an option to specify the maximum number of rows to be returned.
396
422
*/
397
423
public static QueryResultsOption maxResults (long maxResults ) {
424
+ checkArgument (maxResults >= 0 );
398
425
return new QueryResultsOption (BigQueryRpc .Option .MAX_RESULTS , maxResults );
399
426
}
400
427
401
428
/**
402
- * Returns an option to specify the page token from which to start listing query results.
429
+ * Returns an option to specify the page token from which to start getting query results.
403
430
*/
404
431
public static QueryResultsOption startPageToken (String pageToken ) {
405
432
return new QueryResultsOption (BigQueryRpc .Option .PAGE_TOKEN , pageToken );
406
433
}
407
434
408
435
/**
409
- * Returns an option that sets the zero-based index of the row from which to start listing query
436
+ * Returns an option that sets the zero-based index of the row from which to start getting query
410
437
* results.
411
438
*/
412
- public static QueryResultsOption startIndex (Long startIndex ) {
439
+ public static QueryResultsOption startIndex (long startIndex ) {
440
+ checkArgument (startIndex >= 0 );
413
441
return new QueryResultsOption (BigQueryRpc .Option .START_INDEX , startIndex );
414
442
}
415
443
@@ -418,7 +446,8 @@ public static QueryResultsOption startIndex(Long startIndex) {
418
446
* before returning. Default is 10 seconds. If the timeout passes before the job completes,
419
447
* {@link QueryResponse#jobComplete()} will be {@code false}.
420
448
*/
421
- public static QueryResultsOption maxWaitTime (Long maxWaitTime ) {
449
+ public static QueryResultsOption maxWaitTime (long maxWaitTime ) {
450
+ checkArgument (maxWaitTime >= 0 );
422
451
return new QueryResultsOption (BigQueryRpc .Option .TIMEOUT , maxWaitTime );
423
452
}
424
453
}
@@ -460,7 +489,7 @@ public static QueryResultsOption maxWaitTime(Long maxWaitTime) {
460
489
461
490
/**
462
491
* Lists the project's datasets. This method returns partial information on each dataset
463
- * ({@link DatasetInfo#datasetId()} ()} , {@link DatasetInfo#friendlyName()} and
492
+ * ({@link DatasetInfo#datasetId()}, {@link DatasetInfo#friendlyName()} and
464
493
* {@link DatasetInfo#id()}). To get complete information use either
465
494
* {@link #getDataset(String, DatasetOption...)} or
466
495
* {@link #getDataset(DatasetId, DatasetOption...)}.
@@ -592,15 +621,16 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
592
621
JobInfo getJob (JobId jobId , JobOption ... options ) throws BigQueryException ;
593
622
594
623
/**
595
- * Lists the dataset's tables .
624
+ * Lists the jobs .
596
625
*
597
626
* @throws BigQueryException upon failure
598
627
*/
599
628
Page <JobInfo > listJobs (JobListOption ... options ) throws BigQueryException ;
600
629
601
630
/**
602
- * Sends a job cancel request. This call will return immediately, and the client will need to poll
603
- * for the job status to see if the cancel completed successfully.
631
+ * Sends a job cancel request. This call will return immediately. The job status can then be
632
+ * checked using either {@link #getJob(JobId, JobOption...)} or
633
+ * {@link #getJob(String, JobOption...)}).
604
634
*
605
635
* @return {@code true} if cancel was requested successfully, {@code false} if the job was not
606
636
* found
@@ -609,9 +639,9 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
609
639
boolean cancel (String jobId ) throws BigQueryException ;
610
640
611
641
/**
612
- * Sends a job cancel request. This call will return immediately. The client will need to poll
613
- * for the job status using either {@link #getJob(JobId, JobOption...)} or
614
- * {@link #getJob(String, JobOption...)}) to see if the cancel operation completed successfully .
642
+ * Sends a job cancel request. This call will return immediately. The job status can then be
643
+ * checked using either {@link #getJob(JobId, JobOption...)} or
644
+ * {@link #getJob(String, JobOption...)}).
615
645
*
616
646
* @return {@code true} if cancel was requested successfully, {@code false} if the job was not
617
647
* found
@@ -620,14 +650,14 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
620
650
boolean cancel (JobId tableId ) throws BigQueryException ;
621
651
622
652
/**
623
- * Runs the query associated to the request.
653
+ * Runs the query associated with the request.
624
654
*
625
655
* @throws BigQueryException upon failure
626
656
*/
627
657
QueryResponse query (QueryRequest request ) throws BigQueryException ;
628
658
629
659
/**
630
- * Returns results of the query associated to the provided job.
660
+ * Returns results of the query associated with the provided job.
631
661
*
632
662
* @throws BigQueryException upon failure
633
663
*/
0 commit comments