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

Add support for BigQuery resumable uploads via a write channel #540

Merged
merged 1 commit into from
Jan 19, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -662,4 +662,12 @@ Page<List<FieldValue>> listTableData(TableId tableId, TableDataListOption... opt
* @throws BigQueryException upon failure
*/
QueryResponse getQueryResults(JobId job, QueryResultsOption... options) throws BigQueryException;

/**
* Returns a channel to write data to be inserted into a BigQuery table. Data format and other
* options can be configured using the {@link LoadConfiguration} parameter.
*
* @throws BigQueryException upon failure
*/
TableDataWriteChannel writer(LoadConfiguration loadConfiguration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ private static QueryResult.Builder transformQueryResults(JobId jobId, List<Table
.results(transformTableData(rowsPb));
}

public TableDataWriteChannel writer(LoadConfiguration loadConfiguration) {
return new TableDataWriteChannel(options(), setProjectId(loadConfiguration));
}

private Map<BigQueryRpc.Option, ?> optionMap(Option... options) {
Map<BigQueryRpc.Option, Object> optionMap = Maps.newEnumMap(BigQueryRpc.Option.class);
for (Option option : options) {
Expand Down Expand Up @@ -698,8 +702,7 @@ public TableId apply(TableId tableId) {
if (job instanceof LoadJobInfo) {
LoadJobInfo loadJob = (LoadJobInfo) job;
LoadJobInfo.Builder loadBuilder = loadJob.toBuilder();
loadBuilder.destinationTable(setProjectId(loadJob.destinationTable()));
return loadBuilder.build();
return loadBuilder.configuration(setProjectId(loadJob.configuration())).build();
}
return job;
}
Expand All @@ -711,4 +714,10 @@ private QueryRequest setProjectId(QueryRequest request) {
}
return builder.build();
}

private LoadConfiguration setProjectId(LoadConfiguration configuration) {
LoadConfiguration.Builder builder = configuration.toBuilder();
builder.destinationTable(setProjectId(configuration.destinationTable()));
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public Builder destinationTable(TableId destinationTable) {
/**
* Sets whether the job is allowed to create new tables.
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.link">
* Jobs: Link Configuration</a>
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.createDisposition">
* Create Disposition</a>
*/
public Builder createDisposition(CreateDisposition createDisposition) {
this.createDisposition = createDisposition;
Expand All @@ -106,8 +106,8 @@ public Builder createDisposition(CreateDisposition createDisposition) {
/**
* Sets the action that should occur if the destination table already exists.
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.link">
* Jobs: Link Configuration</a>
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.writeDisposition">
* Write Disposition</a>
*/
public Builder writeDisposition(WriteDisposition writeDisposition) {
this.writeDisposition = writeDisposition;
Expand Down Expand Up @@ -145,8 +145,8 @@ public TableId destinationTable() {
/**
* Returns whether the job is allowed to create new tables.
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy">
* Jobs: Copy Configuration</a>
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.createDisposition">
* Create Disposition</a>
*/
public CreateDisposition createDisposition() {
return this.createDisposition;
Expand All @@ -155,8 +155,8 @@ public CreateDisposition createDisposition() {
/**
* Returns the action that should occur if the destination table already exists.
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy">
* Jobs: Copy Configuration</a>
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.copy.writeDisposition">
* Write Disposition</a>
*/
public WriteDisposition writeDisposition() {
return writeDisposition;
Expand Down
Loading