1919import static com .google .common .base .Preconditions .checkArgument ;
2020
2121import com .google .common .base .Function ;
22- import com .google .common .base .Joiner ;
2322import com .google .common .collect .ImmutableList ;
2423import com .google .common .collect .Lists ;
25- import com .google .common .collect .Sets ;
24+ import com .google .gcloud .FieldSelector ;
25+ import com .google .gcloud .FieldSelector .Helper ;
2626import com .google .gcloud .Page ;
2727import com .google .gcloud .Service ;
2828import com .google .gcloud .bigquery .spi .BigQueryRpc ;
2929
3030import java .util .List ;
31- import java .util .Set ;
3231
3332/**
3433 * An interface for Google Cloud BigQuery.
@@ -43,7 +42,7 @@ public interface BigQuery extends Service<BigQueryOptions> {
4342 * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/datasets#resource">Dataset
4443 * Resource</a>
4544 */
46- enum DatasetField {
45+ enum DatasetField implements FieldSelector {
4746 ACCESS ("access" ),
4847 CREATION_TIME ("creationTime" ),
4948 DATASET_REFERENCE ("datasetReference" ),
@@ -56,24 +55,19 @@ enum DatasetField {
5655 LOCATION ("location" ),
5756 SELF_LINK ("selfLink" );
5857
58+ static final List <? extends FieldSelector > REQUIRED_FIELDS =
59+ ImmutableList .of (DATASET_REFERENCE );
60+
5961 private final String selector ;
6062
6163 DatasetField (String selector ) {
6264 this .selector = selector ;
6365 }
6466
67+ @ Override
6568 public String selector () {
6669 return selector ;
6770 }
68-
69- static String selector (DatasetField ... fields ) {
70- Set <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 1 );
71- fieldStrings .add (DATASET_REFERENCE .selector ());
72- for (DatasetField field : fields ) {
73- fieldStrings .add (field .selector ());
74- }
75- return Joiner .on (',' ).join (fieldStrings );
76- }
7771 }
7872
7973 /**
@@ -82,7 +76,7 @@ static String selector(DatasetField... fields) {
8276 * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables#resource">Table
8377 * Resource</a>
8478 */
85- enum TableField {
79+ enum TableField implements FieldSelector {
8680 CREATION_TIME ("creationTime" ),
8781 DESCRIPTION ("description" ),
8882 ETAG ("etag" ),
@@ -101,25 +95,19 @@ enum TableField {
10195 TYPE ("type" ),
10296 VIEW ("view" );
10397
98+ static final List <? extends FieldSelector > REQUIRED_FIELDS =
99+ ImmutableList .of (TABLE_REFERENCE , TYPE );
100+
104101 private final String selector ;
105102
106103 TableField (String selector ) {
107104 this .selector = selector ;
108105 }
109106
107+ @ Override
110108 public String selector () {
111109 return selector ;
112110 }
113-
114- static String selector (TableField ... fields ) {
115- Set <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 2 );
116- fieldStrings .add (TABLE_REFERENCE .selector ());
117- fieldStrings .add (TYPE .selector ());
118- for (TableField field : fields ) {
119- fieldStrings .add (field .selector ());
120- }
121- return Joiner .on (',' ).join (fieldStrings );
122- }
123111 }
124112
125113 /**
@@ -128,7 +116,7 @@ static String selector(TableField... fields) {
128116 * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#resource">Job Resource
129117 * </a>
130118 */
131- enum JobField {
119+ enum JobField implements FieldSelector {
132120 CONFIGURATION ("configuration" ),
133121 ETAG ("etag" ),
134122 ID ("id" ),
@@ -138,25 +126,19 @@ enum JobField {
138126 STATUS ("status" ),
139127 USER_EMAIL ("user_email" );
140128
129+ static final List <? extends FieldSelector > REQUIRED_FIELDS =
130+ ImmutableList .of (JOB_REFERENCE , CONFIGURATION );
131+
141132 private final String selector ;
142133
143134 JobField (String selector ) {
144135 this .selector = selector ;
145136 }
146137
138+ @ Override
147139 public String selector () {
148140 return selector ;
149141 }
150-
151- static String selector (JobField ... fields ) {
152- Set <String > fieldStrings = Sets .newHashSetWithExpectedSize (fields .length + 2 );
153- fieldStrings .add (JOB_REFERENCE .selector ());
154- fieldStrings .add (CONFIGURATION .selector ());
155- for (JobField field : fields ) {
156- fieldStrings .add (field .selector ());
157- }
158- return Joiner .on (',' ).join (fieldStrings );
159- }
160142 }
161143
162144 /**
@@ -210,7 +192,8 @@ private DatasetOption(BigQueryRpc.Option option, Object value) {
210192 * returned, even if not specified.
211193 */
212194 public static DatasetOption fields (DatasetField ... fields ) {
213- return new DatasetOption (BigQueryRpc .Option .FIELDS , DatasetField .selector (fields ));
195+ return new DatasetOption (BigQueryRpc .Option .FIELDS ,
196+ Helper .selector (DatasetField .REQUIRED_FIELDS , fields ));
214197 }
215198 }
216199
@@ -279,7 +262,8 @@ private TableOption(BigQueryRpc.Option option, Object value) {
279262 * of {@link Table#definition()}) are always returned, even if not specified.
280263 */
281264 public static TableOption fields (TableField ... fields ) {
282- return new TableOption (BigQueryRpc .Option .FIELDS , TableField .selector (fields ));
265+ return new TableOption (BigQueryRpc .Option .FIELDS ,
266+ Helper .selector (TableField .REQUIRED_FIELDS , fields ));
283267 }
284268 }
285269
@@ -376,10 +360,8 @@ public static JobListOption pageToken(String pageToken) {
376360 * listing jobs.
377361 */
378362 public static JobListOption fields (JobField ... fields ) {
379- String selector = JobField .selector (fields );
380- StringBuilder builder = new StringBuilder ();
381- builder .append ("etag,jobs(" ).append (selector ).append (",state,errorResult),nextPageToken" );
382- return new JobListOption (BigQueryRpc .Option .FIELDS , builder .toString ());
363+ return new JobListOption (BigQueryRpc .Option .FIELDS ,
364+ Helper .listSelector ("jobs" , JobField .REQUIRED_FIELDS , fields , "state" , "errorResult" ));
383365 }
384366 }
385367
@@ -402,7 +384,8 @@ private JobOption(BigQueryRpc.Option option, Object value) {
402384 * returned, even if not specified.
403385 */
404386 public static JobOption fields (JobField ... fields ) {
405- return new JobOption (BigQueryRpc .Option .FIELDS , JobField .selector (fields ));
387+ return new JobOption (BigQueryRpc .Option .FIELDS ,
388+ Helper .selector (JobField .REQUIRED_FIELDS , fields ));
406389 }
407390 }
408391
@@ -488,9 +471,10 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
488471 Dataset getDataset (DatasetId datasetId , DatasetOption ... options );
489472
490473 /**
491- * Lists the project's datasets. This method returns partial information on each dataset
492- * ({@link Dataset#datasetId()}, {@link Dataset#friendlyName()} and {@link Dataset#id()}). To get
493- * complete information use either {@link #getDataset(String, DatasetOption...)} or
474+ * Lists the project's datasets. This method returns partial information on each dataset:
475+ * ({@link Dataset#datasetId()}, {@link Dataset#friendlyName()} and
476+ * {@link Dataset#generatedId()}). To get complete information use either
477+ * {@link #getDataset(String, DatasetOption...)} or
494478 * {@link #getDataset(DatasetId, DatasetOption...)}.
495479 *
496480 * @throws BigQueryException upon failure
@@ -558,9 +542,9 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
558542 Table getTable (TableId tableId , TableOption ... options );
559543
560544 /**
561- * Lists the tables in the dataset. This method returns partial information on each table
562- * ({@link Table#tableId()}, {@link Table#friendlyName()}, {@link Table#id ()} and type, which
563- * is part of {@link Table#definition()}). To get complete information use either
545+ * Lists the tables in the dataset. This method returns partial information on each table:
546+ * ({@link Table#tableId()}, {@link Table#friendlyName()}, {@link Table#generatedId ()} and type,
547+ * which is part of {@link Table#definition()}). To get complete information use either
564548 * {@link #getTable(TableId, TableOption...)} or
565549 * {@link #getTable(String, String, TableOption...)}.
566550 *
@@ -569,9 +553,9 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
569553 Page <Table > listTables (String datasetId , TableListOption ... options );
570554
571555 /**
572- * Lists the tables in the dataset. This method returns partial information on each table
573- * ({@link Table#tableId()}, {@link Table#friendlyName()}, {@link Table#id ()} and type, which
574- * is part of {@link Table#definition()}). To get complete information use either
556+ * Lists the tables in the dataset. This method returns partial information on each table:
557+ * ({@link Table#tableId()}, {@link Table#friendlyName()}, {@link Table#generatedId ()} and type,
558+ * which is part of {@link Table#definition()}). To get complete information use either
575559 * {@link #getTable(TableId, TableOption...)} or
576560 * {@link #getTable(String, String, TableOption...)}.
577561 *
0 commit comments