Skip to content

Commit 4bf3796

Browse files
committed
Merge pull request #609 from mziccard/bigquery-hierachies
Make bigquery functional classes extend info classes
2 parents 2bb03eb + fbcbfb4 commit 4bf3796

26 files changed

+1637
-1064
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,30 @@ must [supply credentials](#authentication) and a project ID if running this snip
128128
import com.google.gcloud.bigquery.BigQuery;
129129
import com.google.gcloud.bigquery.BigQueryOptions;
130130
import com.google.gcloud.bigquery.Field;
131+
import com.google.gcloud.bigquery.Job;
131132
import com.google.gcloud.bigquery.JobStatus;
132133
import com.google.gcloud.bigquery.JobInfo;
133134
import com.google.gcloud.bigquery.LoadJobConfiguration;
134135
import com.google.gcloud.bigquery.Schema;
135136
import com.google.gcloud.bigquery.StandardTableDefinition;
137+
import com.google.gcloud.bigquery.Table;
136138
import com.google.gcloud.bigquery.TableId;
137139
import com.google.gcloud.bigquery.TableInfo;
138140
139141
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
140142
TableId tableId = TableId.of("dataset", "table");
141-
TableInfo info = bigquery.getTable(tableId);
142-
if (info == null) {
143+
Table table = bigquery.getTable(tableId);
144+
if (table == null) {
143145
System.out.println("Creating table " + tableId);
144146
Field integerField = Field.of("fieldName", Field.Type.integer());
145147
Schema schema = Schema.of(integerField);
146148
bigquery.create(TableInfo.of(tableId, StandardTableDefinition.of(schema)));
147149
} else {
148150
System.out.println("Loading data into table " + tableId);
149151
LoadJobConfiguration configuration = LoadJobConfiguration.of(tableId, "gs://bucket/path");
150-
JobInfo loadJob = JobInfo.of(configuration);
151-
loadJob = bigquery.create(loadJob);
152-
while (loadJob.status().state() != JobStatus.State.DONE) {
152+
Job loadJob = bigquery.create(JobInfo.of(configuration));
153+
while (!loadJob.isDone()) {
153154
Thread.sleep(1000L);
154-
loadJob = bigquery.getJob(loadJob.jobId());
155155
}
156156
if (loadJob.status().error() != null) {
157157
System.out.println("Job completed with errors");

gcloud-java-bigquery/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ with only one string field. Add the following imports at the top of your file:
114114
import com.google.gcloud.bigquery.Field;
115115
import com.google.gcloud.bigquery.Schema;
116116
import com.google.gcloud.bigquery.StandardTableDefinition;
117+
import com.google.gcloud.bigquery.Table;
117118
import com.google.gcloud.bigquery.TableId;
118119
import com.google.gcloud.bigquery.TableInfo;
119120
```
@@ -127,7 +128,7 @@ Field stringField = Field.of("StringField", Field.Type.string());
127128
Schema schema = Schema.of(stringField);
128129
// Create a table
129130
StandardTableDefinition tableDefinition = StandardTableDefinition.of(schema);
130-
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));
131+
Table createdTable = bigquery.create(TableInfo.of(tableId, tableDefinition));
131132
```
132133

133134
#### Loading data into a table
@@ -216,6 +217,7 @@ import com.google.gcloud.bigquery.QueryRequest;
216217
import com.google.gcloud.bigquery.QueryResponse;
217218
import com.google.gcloud.bigquery.Schema;
218219
import com.google.gcloud.bigquery.StandardTableDefinition;
220+
import com.google.gcloud.bigquery.Table;
219221
import com.google.gcloud.bigquery.TableId;
220222
import com.google.gcloud.bigquery.TableInfo;
221223

@@ -242,7 +244,7 @@ public class GcloudBigQueryExample {
242244
Schema schema = Schema.of(stringField);
243245
// Create a table
244246
StandardTableDefinition tableDefinition = StandardTableDefinition.of(schema);
245-
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));
247+
Table createdTable = bigquery.create(TableInfo.of(tableId, tableDefinition));
246248

247249
// Define rows to insert
248250
Map<String, Object> firstRow = new HashMap<>();

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Acl.java

+2
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ Access toPb() {
325325
*/
326326
public static final class View extends Entity {
327327

328+
private static final long serialVersionUID = -6851072781269419383L;
329+
328330
private final TableId id;
329331

330332
/**

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQuery.java

+26-31
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private DatasetOption(BigQueryRpc.Option option, Object value) {
206206
/**
207207
* Returns an option to specify the dataset's fields to be returned by the RPC call. If this
208208
* option is not provided all dataset's fields are returned. {@code DatasetOption.fields} can
209-
* be used to specify only the fields of interest. {@link DatasetInfo#datasetId()} is always
209+
* be used to specify only the fields of interest. {@link Dataset#datasetId()} is always
210210
* returned, even if not specified.
211211
*/
212212
public static DatasetOption fields(DatasetField... fields) {
@@ -275,8 +275,8 @@ private TableOption(BigQueryRpc.Option option, Object value) {
275275
/**
276276
* Returns an option to specify the table's fields to be returned by the RPC call. If this
277277
* option is not provided all table's fields are returned. {@code TableOption.fields} can be
278-
* used to specify only the fields of interest. {@link TableInfo#tableId()} and type (which is
279-
* part of {@link TableInfo#definition()}) are always returned, even if not specified.
278+
* used to specify only the fields of interest. {@link Table#tableId()} and type (which is part
279+
* of {@link Table#definition()}) are always returned, even if not specified.
280280
*/
281281
public static TableOption fields(TableField... fields) {
282282
return new TableOption(BigQueryRpc.Option.FIELDS, TableField.selector(fields));
@@ -369,7 +369,7 @@ public static JobListOption startPageToken(String pageToken) {
369369
/**
370370
* Returns an option to specify the job's fields to be returned by the RPC call. If this option
371371
* is not provided all job's fields are returned. {@code JobOption.fields()} can be used to
372-
* specify only the fields of interest. {@link JobInfo#jobId()}, {@link JobStatus#state()},
372+
* specify only the fields of interest. {@link Job#jobId()}, {@link JobStatus#state()},
373373
* {@link JobStatus#error()} as well as type-specific configuration (e.g.
374374
* {@link QueryJobConfiguration#query()} for Query Jobs) are always returned, even if not
375375
* specified. {@link JobField#SELF_LINK} and {@link JobField#ETAG} can not be selected when
@@ -397,7 +397,7 @@ private JobOption(BigQueryRpc.Option option, Object value) {
397397
/**
398398
* Returns an option to specify the job's fields to be returned by the RPC call. If this option
399399
* is not provided all job's fields are returned. {@code JobOption.fields()} can be used to
400-
* specify only the fields of interest. {@link JobInfo#jobId()} as well as type-specific
400+
* specify only the fields of interest. {@link Job#jobId()} as well as type-specific
401401
* configuration (e.g. {@link QueryJobConfiguration#query()} for Query Jobs) are always
402402
* returned, even if not specified.
403403
*/
@@ -457,46 +457,45 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
457457
*
458458
* @throws BigQueryException upon failure
459459
*/
460-
DatasetInfo create(DatasetInfo dataset, DatasetOption... options) throws BigQueryException;
460+
Dataset create(DatasetInfo dataset, DatasetOption... options) throws BigQueryException;
461461

462462
/**
463463
* Creates a new table.
464464
*
465465
* @throws BigQueryException upon failure
466466
*/
467-
TableInfo create(TableInfo table, TableOption... options) throws BigQueryException;
467+
Table create(TableInfo table, TableOption... options) throws BigQueryException;
468468

469469
/**
470470
* Creates a new job.
471471
*
472472
* @throws BigQueryException upon failure
473473
*/
474-
JobInfo create(JobInfo job, JobOption... options) throws BigQueryException;
474+
Job create(JobInfo job, JobOption... options) throws BigQueryException;
475475

476476
/**
477477
* Returns the requested dataset or {@code null} if not found.
478478
*
479479
* @throws BigQueryException upon failure
480480
*/
481-
DatasetInfo getDataset(String datasetId, DatasetOption... options) throws BigQueryException;
481+
Dataset getDataset(String datasetId, DatasetOption... options) throws BigQueryException;
482482

483483
/**
484484
* Returns the requested dataset or {@code null} if not found.
485485
*
486486
* @throws BigQueryException upon failure
487487
*/
488-
DatasetInfo getDataset(DatasetId datasetId, DatasetOption... options) throws BigQueryException;
488+
Dataset getDataset(DatasetId datasetId, DatasetOption... options) throws BigQueryException;
489489

490490
/**
491491
* Lists the project's datasets. This method returns partial information on each dataset
492-
* ({@link DatasetInfo#datasetId()}, {@link DatasetInfo#friendlyName()} and
493-
* {@link DatasetInfo#id()}). To get complete information use either
494-
* {@link #getDataset(String, DatasetOption...)} or
492+
* ({@link Dataset#datasetId()}, {@link Dataset#friendlyName()} and {@link Dataset#id()}). To get
493+
* complete information use either {@link #getDataset(String, DatasetOption...)} or
495494
* {@link #getDataset(DatasetId, DatasetOption...)}.
496495
*
497496
* @throws BigQueryException upon failure
498497
*/
499-
Page<DatasetInfo> listDatasets(DatasetListOption... options) throws BigQueryException;
498+
Page<Dataset> listDatasets(DatasetListOption... options) throws BigQueryException;
500499

501500
/**
502501
* Deletes the requested dataset.
@@ -535,54 +534,50 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
535534
*
536535
* @throws BigQueryException upon failure
537536
*/
538-
DatasetInfo update(DatasetInfo dataset, DatasetOption... options) throws BigQueryException;
537+
Dataset update(DatasetInfo dataset, DatasetOption... options) throws BigQueryException;
539538

540539
/**
541540
* Updates table information.
542541
*
543542
* @throws BigQueryException upon failure
544543
*/
545-
TableInfo update(TableInfo table, TableOption... options) throws BigQueryException;
544+
Table update(TableInfo table, TableOption... options) throws BigQueryException;
546545

547546
/**
548547
* Returns the requested table or {@code null} if not found.
549548
*
550549
* @throws BigQueryException upon failure
551550
*/
552-
TableInfo getTable(String datasetId, String tableId, TableOption... options)
553-
throws BigQueryException;
551+
Table getTable(String datasetId, String tableId, TableOption... options) throws BigQueryException;
554552

555553
/**
556554
* Returns the requested table or {@code null} if not found.
557555
*
558556
* @throws BigQueryException upon failure
559557
*/
560-
TableInfo getTable(TableId tableId, TableOption... options)
561-
throws BigQueryException;
558+
Table getTable(TableId tableId, TableOption... options) throws BigQueryException;
562559

563560
/**
564561
* Lists the tables in the dataset. This method returns partial information on each table
565-
* ({@link TableInfo#tableId()}, {@link TableInfo#friendlyName()}, {@link TableInfo#id()} and
566-
* type, which is part of {@link TableInfo#definition()}). To get complete information use either
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
567564
* {@link #getTable(TableId, TableOption...)} or
568565
* {@link #getTable(String, String, TableOption...)}.
569566
*
570567
* @throws BigQueryException upon failure
571568
*/
572-
Page<TableInfo> listTables(String datasetId, TableListOption... options)
573-
throws BigQueryException;
569+
Page<Table> listTables(String datasetId, TableListOption... options) throws BigQueryException;
574570

575571
/**
576572
* Lists the tables in the dataset. This method returns partial information on each table
577-
* ({@link TableInfo#tableId()}, {@link TableInfo#friendlyName()}, {@link TableInfo#id()} and
578-
* type, which is part of {@link TableInfo#definition()}). To get complete information use either
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
579575
* {@link #getTable(TableId, TableOption...)} or
580576
* {@link #getTable(String, String, TableOption...)}.
581577
*
582578
* @throws BigQueryException upon failure
583579
*/
584-
Page<TableInfo> listTables(DatasetId datasetId, TableListOption... options)
585-
throws BigQueryException;
580+
Page<Table> listTables(DatasetId datasetId, TableListOption... options) throws BigQueryException;
586581

587582
/**
588583
* Sends an insert all request.
@@ -612,21 +607,21 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
612607
*
613608
* @throws BigQueryException upon failure
614609
*/
615-
JobInfo getJob(String jobId, JobOption... options) throws BigQueryException;
610+
Job getJob(String jobId, JobOption... options) throws BigQueryException;
616611

617612
/**
618613
* Returns the requested job or {@code null} if not found.
619614
*
620615
* @throws BigQueryException upon failure
621616
*/
622-
JobInfo getJob(JobId jobId, JobOption... options) throws BigQueryException;
617+
Job getJob(JobId jobId, JobOption... options) throws BigQueryException;
623618

624619
/**
625620
* Lists the jobs.
626621
*
627622
* @throws BigQueryException upon failure
628623
*/
629-
Page<JobInfo> listJobs(JobListOption... options) throws BigQueryException;
624+
Page<Job> listJobs(JobListOption... options) throws BigQueryException;
630625

631626
/**
632627
* Sends a job cancel request. This call will return immediately. The job status can then be

0 commit comments

Comments
 (0)