Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make BigQuery get/create/updated Table and Job methods generic #500

Merged
merged 1 commit into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gcloud-java-bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Field stringField = Field.of("StringField", Field.Type.string());
// Table schema definition
Schema schema = Schema.of(stringField);
// Create a table
BaseTableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, schema));
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, schema));
```

#### Loading data into a table
Expand Down Expand Up @@ -232,7 +232,7 @@ public class GcloudBigQueryExample {
// Table schema definition
Schema schema = Schema.of(stringField);
// Create a table
BaseTableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, schema));
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, schema));

// Define rows to insert
Map<String, Object> firstRow = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,14 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
*
* @throws BigQueryException upon failure
*/
BaseTableInfo create(BaseTableInfo table, TableOption... options) throws BigQueryException;
<T extends BaseTableInfo> T create(T table, TableOption... options) throws BigQueryException;

/**
* Creates a new job.
*
* @throws BigQueryException upon failure
*/
JobInfo create(JobInfo job, JobOption... options) throws BigQueryException;
<T extends JobInfo> T create(T job, JobOption... options) throws BigQueryException;

/**
* Returns the requested dataset or {@code null} if not found.
Expand Down Expand Up @@ -541,22 +541,23 @@ public static QueryResultsOption maxWaitTime(long maxWaitTime) {
*
* @throws BigQueryException upon failure
*/
BaseTableInfo update(BaseTableInfo table, TableOption... options) throws BigQueryException;
<T extends BaseTableInfo> T update(T table, TableOption... options) throws BigQueryException;

/**
* Returns the requested table or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
BaseTableInfo getTable(String datasetId, String tableId, TableOption... options)
<T extends BaseTableInfo> T getTable(String datasetId, String tableId, TableOption... options)
throws BigQueryException;

/**
* Returns the requested table or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
BaseTableInfo getTable(TableId tableId, TableOption... options) throws BigQueryException;
<T extends BaseTableInfo> T getTable(TableId tableId, TableOption... options)
throws BigQueryException;

/**
* Lists the tables in the dataset. This method returns partial information on each table
Expand Down Expand Up @@ -610,14 +611,14 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
*
* @throws BigQueryException upon failure
*/
JobInfo getJob(String jobId, JobOption... options) throws BigQueryException;
<T extends JobInfo> T getJob(String jobId, JobOption... options) throws BigQueryException;

/**
* Returns the requested job or {@code null} if not found.
*
* @throws BigQueryException upon failure
*/
JobInfo getJob(JobId jobId, JobOption... options) throws BigQueryException;
<T extends JobInfo> T getJob(JobId jobId, JobOption... options) throws BigQueryException;

/**
* Lists the jobs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public Dataset call() {
}

@Override
public BaseTableInfo create(BaseTableInfo table, TableOption... options)
public <T extends BaseTableInfo> T create(T table, TableOption... options)
throws BigQueryException {
final Table tablePb = setProjectId(table).toPb();
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
Expand All @@ -216,7 +216,7 @@ public Table call() {
}

@Override
public JobInfo create(JobInfo job, JobOption... options) throws BigQueryException {
public <T extends JobInfo> T create(T job, JobOption... options) throws BigQueryException {
final Job jobPb = setProjectId(job).toPb();
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
Expand Down Expand Up @@ -335,7 +335,7 @@ public Dataset call() {
}

@Override
public BaseTableInfo update(BaseTableInfo table, TableOption... options)
public <T extends BaseTableInfo> T update(T table, TableOption... options)
throws BigQueryException {
final Table tablePb = setProjectId(table).toPb();
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
Expand All @@ -352,13 +352,13 @@ public Table call() {
}

@Override
public BaseTableInfo getTable(final String datasetId, final String tableId,
public <T extends BaseTableInfo> T getTable(final String datasetId, final String tableId,
TableOption... options) throws BigQueryException {
return getTable(TableId.of(datasetId, tableId), options);
}

@Override
public BaseTableInfo getTable(final TableId tableId, TableOption... options)
public <T extends BaseTableInfo> T getTable(final TableId tableId, TableOption... options)
throws BigQueryException {
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
Expand All @@ -368,7 +368,7 @@ public Table call() {
return bigQueryRpc.getTable(tableId.dataset(), tableId.table(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : BaseTableInfo.fromPb(answer);
return answer == null ? null : BaseTableInfo.<T>fromPb(answer);
} catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
Expand Down Expand Up @@ -466,12 +466,13 @@ public List<FieldValue> apply(TableRow rowPb) {
}

@Override
public JobInfo getJob(String jobId, JobOption... options) throws BigQueryException {
public <T extends JobInfo> T getJob(String jobId, JobOption... options) throws BigQueryException {
return getJob(JobId.of(jobId), options);
}

@Override
public JobInfo getJob(final JobId jobId, JobOption... options) throws BigQueryException {
public <T extends JobInfo> T getJob(final JobId jobId, JobOption... options)
throws BigQueryException {
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
Job answer = runWithRetries(new Callable<Job>() {
Expand All @@ -480,7 +481,7 @@ public Job call() {
return bigQueryRpc.getJob(jobId.job(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : JobInfo.fromPb(answer);
return answer == null ? null : JobInfo.<T>fromPb(answer);
} catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
Expand Down
Loading