Skip to content

Commit

Permalink
Merge branch 'master' of github.com:GoogleCloudPlatform/google-cloud-…
Browse files Browse the repository at this point in the history
…java into docs
  • Loading branch information
shinfan committed Apr 25, 2017
2 parents 7c29209 + c3d18ff commit a390c9e
Show file tree
Hide file tree
Showing 28 changed files with 540 additions and 504 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import static com.google.cloud.RetryHelper.runWithRetries;
import static com.google.common.base.Preconditions.checkArgument;

import com.google.api.gax.paging.Page;
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest.Rows;
import com.google.api.services.bigquery.model.TableRow;
import com.google.cloud.BaseService;
import com.google.api.gax.paging.Page;
import com.google.cloud.PageImpl;
import com.google.cloud.PageImpl.NextPageFetcher;
import com.google.cloud.RetryHelper;
import com.google.cloud.Tuple;
import com.google.cloud.bigquery.InsertAllRequest.RowToInsert;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.common.base.Function;
Expand All @@ -36,7 +37,6 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -247,21 +247,30 @@ public Page<Dataset> listDatasets(String projectId, DatasetListOption... options
return listDatasets(projectId, getOptions(), optionMap(options));
}

private static Page<Dataset> listDatasets(final String projectId,
final BigQueryOptions serviceOptions, final Map<BigQueryRpc.Option, ?> optionsMap) {
private static Page<Dataset> listDatasets(
final String projectId,
final BigQueryOptions serviceOptions,
final Map<BigQueryRpc.Option, ?> optionsMap) {
try {
BigQueryRpc.Tuple<String, Iterable<com.google.api.services.bigquery.model.Dataset>> result =
runWithRetries(new Callable<BigQueryRpc.Tuple<String,
Iterable<com.google.api.services.bigquery.model.Dataset>>>() {
Tuple<String, Iterable<com.google.api.services.bigquery.model.Dataset>> result =
runWithRetries(
new Callable<
Tuple<String, Iterable<com.google.api.services.bigquery.model.Dataset>>>() {
@Override
public BigQueryRpc.Tuple<String,
Iterable<com.google.api.services.bigquery.model.Dataset>> call() {
public Tuple<String, Iterable<com.google.api.services.bigquery.model.Dataset>>
call() {
return serviceOptions.getBigQueryRpcV2().listDatasets(projectId, optionsMap);
}
}, serviceOptions.getRetrySettings(), EXCEPTION_HANDLER, serviceOptions.getClock());
},
serviceOptions.getRetrySettings(),
EXCEPTION_HANDLER,
serviceOptions.getClock());
String cursor = result.x();
return new PageImpl<>(new DatasetPageFetcher(projectId, serviceOptions, cursor, optionsMap),
cursor, Iterables.transform(result.y(),
return new PageImpl<>(
new DatasetPageFetcher(projectId, serviceOptions, cursor, optionsMap),
cursor,
Iterables.transform(
result.y(),
new Function<com.google.api.services.bigquery.model.Dataset, Dataset>() {
@Override
public Dataset apply(com.google.api.services.bigquery.model.Dataset dataset) {
Expand Down Expand Up @@ -391,11 +400,11 @@ public Page<Table> listTables(DatasetId datasetId, TableListOption... options) {
private static Page<Table> listTables(final DatasetId datasetId,
final BigQueryOptions serviceOptions, final Map<BigQueryRpc.Option, ?> optionsMap) {
try {
BigQueryRpc.Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result =
runWithRetries(new Callable<BigQueryRpc.Tuple<String,
Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>> result =
runWithRetries(new Callable<Tuple<String,
Iterable<com.google.api.services.bigquery.model.Table>>>() {
@Override
public BigQueryRpc.Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>>
public Tuple<String, Iterable<com.google.api.services.bigquery.model.Table>>
call() {
return serviceOptions.getBigQueryRpcV2().listTables(
datasetId.getProject(), datasetId.getDataset(), optionsMap);
Expand Down Expand Up @@ -450,10 +459,10 @@ private static Page<List<FieldValue>> listTableData(final TableId tableId,
final BigQueryOptions serviceOptions, final Map<BigQueryRpc.Option, ?> optionsMap) {
try {
final TableId completeTableId = tableId.setProjectId(serviceOptions.getProjectId());
BigQueryRpc.Tuple<String, Iterable<TableRow>> result =
runWithRetries(new Callable<BigQueryRpc.Tuple<String, Iterable<TableRow>>>() {
Tuple<String, Iterable<TableRow>> result =
runWithRetries(new Callable<Tuple<String, Iterable<TableRow>>>() {
@Override
public BigQueryRpc.Tuple<String, Iterable<TableRow>> call() {
public Tuple<String, Iterable<TableRow>> call() {
return serviceOptions.getBigQueryRpcV2()
.listTableData(completeTableId.getProject(), completeTableId.getDataset(),
completeTableId.getTable(), optionsMap);
Expand Down Expand Up @@ -509,11 +518,11 @@ public Page<Job> listJobs(JobListOption... options) {

private static Page<Job> listJobs(final BigQueryOptions serviceOptions,
final Map<BigQueryRpc.Option, ?> optionsMap) {
BigQueryRpc.Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> result =
runWithRetries(new Callable<BigQueryRpc.Tuple<String,
Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>> result =
runWithRetries(new Callable<Tuple<String,
Iterable<com.google.api.services.bigquery.model.Job>>>() {
@Override
public BigQueryRpc.Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>>
public Tuple<String, Iterable<com.google.api.services.bigquery.model.Job>>
call() {
return serviceOptions.getBigQueryRpcV2().listJobs(serviceOptions.getProjectId(), optionsMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
import com.google.api.services.bigquery.model.TableRow;
import com.google.cloud.ServiceRpc;
import com.google.cloud.Tuple;
import com.google.cloud.bigquery.BigQueryException;

import java.util.Map;

public interface BigQueryRpc extends ServiceRpc {
Expand Down Expand Up @@ -73,29 +73,6 @@ Boolean getBoolean(Map<Option, ?> options) {
}
}

class Tuple<X, Y> {

private final X x;
private final Y y;

private Tuple(X x, Y y) {
this.x = x;
this.y = y;
}

public static <X, Y> Tuple<X, Y> of(X x, Y y) {
return new Tuple<>(x, y);
}

public X x() {
return x;
}

public Y y() {
return y;
}
}

/**
* Returns the requested dataset or {@code null} if not found.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.google.api.services.bigquery.model.TableList;
import com.google.api.services.bigquery.model.TableReference;
import com.google.api.services.bigquery.model.TableRow;
import com.google.cloud.Tuple;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.http.HttpTransportOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.paging.Page;
import com.google.api.services.bigquery.model.ErrorProto;
import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.api.services.bigquery.model.TableCell;
import com.google.api.services.bigquery.model.TableDataInsertAllRequest;
import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
import com.google.api.services.bigquery.model.TableRow;
import com.google.api.gax.paging.Page;
import com.google.cloud.ServiceOptions;
import com.google.cloud.Tuple;
import com.google.cloud.WriteChannel;
import com.google.cloud.bigquery.InsertAllRequest.RowToInsert;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc.Tuple;
import com.google.cloud.bigquery.spi.BigQueryRpcFactory;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down
Loading

0 comments on commit a390c9e

Please sign in to comment.