Skip to content

Commit

Permalink
Update page (#1894)
Browse files Browse the repository at this point in the history
- Use GAX page interface
- Bump GAX version
  • Loading branch information
michaelbausor authored Apr 12, 2017
1 parent 4576cd6 commit e11154e
Show file tree
Hide file tree
Showing 124 changed files with 2,119 additions and 1,144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ nosetests.xml
.idea
.settings
.DS_Store
.classpath

# Built documentation
docs/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import static com.google.common.base.Preconditions.checkArgument;

import com.google.api.gax.core.Page;
import com.google.cloud.FieldSelector;
import com.google.cloud.FieldSelector.Helper;
import com.google.cloud.Page;
import com.google.cloud.Service;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.common.base.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.PageImpl;
import com.google.cloud.PageImpl.NextPageFetcher;
import com.google.cloud.RetryHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption;
import com.google.cloud.bigquery.BigQuery.DatasetOption;
import com.google.cloud.bigquery.BigQuery.TableListOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public String toString() {
.add("schema", schema)
.add("totalBytesProcessed", totalBytesProcessed)
.add("totalRows", totalRows)
.add("cursor", getNextPageCursor())
.add("cursor", getNextPageToken())
.toString();
}

Expand All @@ -167,7 +167,7 @@ public final boolean equals(Object obj) {
return false;
}
QueryResult response = (QueryResult) obj;
return Objects.equals(getNextPageCursor(), response.getNextPageCursor())
return Objects.equals(getNextPageToken(), response.getNextPageToken())
&& Objects.equals(getValues(), response.getValues())
&& Objects.equals(schema, response.schema)
&& totalRows == response.totalRows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.bigquery.BigQuery.JobOption;
import com.google.cloud.bigquery.BigQuery.TableDataListOption;
import com.google.cloud.bigquery.BigQuery.TableOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.core.RetrySettings;
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.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.ServiceOptions;
import com.google.cloud.WriteChannel;
import com.google.cloud.bigquery.InsertAllRequest.RowToInsert;
Expand Down Expand Up @@ -397,7 +396,7 @@ public void testListDatasets() {
EasyMock.expect(bigqueryRpcMock.listDatasets(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Dataset> page = bigquery.listDatasets();
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(
datasetList.toArray(), Iterables.toArray(page.getValues(), DatasetInfo.class));
}
Expand All @@ -415,7 +414,7 @@ public void testListDatasetsWithProjects() {
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Dataset> page = bigquery.listDatasets(OTHER_PROJECT);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(
datasetList.toArray(), Iterables.toArray(page.getValues(), DatasetInfo.class));
}
Expand All @@ -429,7 +428,7 @@ public void testListEmptyDatasets() {
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
Page<Dataset> page = bigquery.listDatasets();
assertNull(page.getNextPageCursor());
assertNull(page.getNextPageToken());
assertArrayEquals(
ImmutableList.of().toArray(), Iterables.toArray(page.getValues(), Dataset.class));
}
Expand All @@ -447,7 +446,7 @@ public void testListDatasetsWithOptions() {
EasyMock.replay(bigqueryRpcMock);
Page<Dataset> page =
bigquery.listDatasets(DATASET_LIST_ALL, DATASET_LIST_PAGE_TOKEN, DATASET_LIST_PAGE_SIZE);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(
datasetList.toArray(), Iterables.toArray(page.getValues(), DatasetInfo.class));
}
Expand Down Expand Up @@ -618,7 +617,7 @@ public void testListTables() {
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Table> page = bigquery.listTables(DATASET);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

Expand All @@ -635,7 +634,7 @@ public void testListTablesFromDatasetId() {
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Table> page = bigquery.listTables(DatasetId.of(DATASET));
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

Expand All @@ -651,7 +650,7 @@ public void testListTablesFromDatasetIdWithProject() {
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Table> page = bigquery.listTables(DatasetId.of(OTHER_PROJECT, DATASET));
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

Expand All @@ -668,7 +667,7 @@ public void testListTablesWithOptions() {
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Table> page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.getValues(), Table.class));
}

Expand Down Expand Up @@ -832,7 +831,7 @@ public void testListTableData() {
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
Page<List<FieldValue>> page = bigquery.listTableData(DATASET, TABLE);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class));
}

Expand All @@ -843,7 +842,7 @@ public void testListTableDataFromTableId() {
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
Page<List<FieldValue>> page = bigquery.listTableData(TableId.of(DATASET, TABLE));
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class));
}

Expand All @@ -855,7 +854,7 @@ public void testListTableDataFromTableIdWithProject() {
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
Page<List<FieldValue>> page = bigquery.listTableData(tableId);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class));
}

Expand All @@ -872,7 +871,7 @@ public void testListTableDataWithOptions() {
TABLE_DATA_LIST_PAGE_SIZE,
TABLE_DATA_LIST_PAGE_TOKEN,
TABLE_DATA_LIST_START_INDEX);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(TABLE_DATA.toArray(), Iterables.toArray(page.getValues(), List.class));
}

Expand Down Expand Up @@ -1016,7 +1015,7 @@ public com.google.api.services.bigquery.model.Job apply(Job job) {
EasyMock.expect(bigqueryRpcMock.listJobs(PROJECT, EMPTY_RPC_OPTIONS)).andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Job> page = bigquery.listJobs();
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class));
}

Expand All @@ -1043,7 +1042,7 @@ public com.google.api.services.bigquery.model.Job apply(Job job) {
Page<Job> page =
bigquery.listJobs(
JOB_LIST_ALL_USERS, JOB_LIST_STATE_FILTER, JOB_LIST_PAGE_TOKEN, JOB_LIST_PAGE_SIZE);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class));
}

Expand All @@ -1070,7 +1069,7 @@ public com.google.api.services.bigquery.model.Job apply(Job job) {
.andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Job> page = bigquery.listJobs(JOB_LIST_OPTION_FIELD);
assertEquals(CURSOR, page.getNextPageCursor());
assertEquals(CURSOR, page.getNextPageToken());
assertArrayEquals(jobList.toArray(), Iterables.toArray(page.getValues(), Job.class));
String selector = (String) capturedOptions.getValue().get(JOB_OPTION_FIELDS.getRpcOption());
assertTrue(selector.contains("nextPageToken,jobs("));
Expand Down Expand Up @@ -1157,7 +1156,7 @@ public void testQueryRequestCompleted() {
assertEquals(false, row.get(0).getBooleanValue());
assertEquals(1L, row.get(1).getLongValue());
}
assertEquals(CURSOR, response.getResult().getNextPageCursor());
assertEquals(CURSOR, response.getResult().getNextPageToken());
}

@Test
Expand Down Expand Up @@ -1191,7 +1190,7 @@ public void testGetQueryResults() {
assertEquals(false, row.get(0).getBooleanValue());
assertEquals(1L, row.get(1).getLongValue());
}
assertEquals(CURSOR, response.getResult().getNextPageCursor());
assertEquals(CURSOR, response.getResult().getNextPageToken());
}

@Test
Expand Down Expand Up @@ -1225,7 +1224,7 @@ public void testGetQueryResultsWithProject() {
assertEquals(false, row.get(0).getBooleanValue());
assertEquals(1L, row.get(1).getLongValue());
}
assertEquals(CURSOR, response.getResult().getNextPageCursor());
assertEquals(CURSOR, response.getResult().getNextPageToken());
}

@Test
Expand Down Expand Up @@ -1263,7 +1262,7 @@ public void testGetQueryResultsWithOptions() {
assertEquals(false, row.get(0).getBooleanValue());
assertEquals(1L, row.get(1).getLongValue());
}
assertEquals(CURSOR, response.getResult().getNextPageCursor());
assertEquals(CURSOR, response.getResult().getNextPageToken());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.PageImpl;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -253,7 +253,7 @@ public void testList() throws Exception {
Page<Table> tablePage = dataset.list();
assertArrayEquals(tableResults.toArray(),
Iterables.toArray(tablePage.getValues(), Table.class));
assertEquals(expectedPage.getNextPageCursor(), tablePage.getNextPageCursor());
assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken());
}

@Test
Expand All @@ -272,7 +272,7 @@ public void testListWithOptions() throws Exception {
Page<Table> tablePage = dataset.list(BigQuery.TableListOption.pageSize(10L));
assertArrayEquals(tableResults.toArray(),
Iterables.toArray(tablePage.getValues(), Table.class));
assertEquals(expectedPage.getNextPageCursor(), tablePage.getNextPageCursor());
assertEquals(expectedPage.getNextPageToken(), tablePage.getNextPageToken());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public void testBuilder() {
assertEquals(TOTAL_ROWS, QUERY_RESULT.getTotalRows());
assertEquals(TOTAL_BYTES_PROCESSED, QUERY_RESULT.getTotalBytesProcessed());
assertEquals(CACHE_HIT, QUERY_RESULT.cacheHit());
assertEquals(CURSOR, QUERY_RESULT.getNextPageCursor());
assertEquals(CURSOR, QUERY_RESULT.getNextPageToken());
assertEquals(null, QUERY_RESULT.getNextPage());
assertEquals(null, QUERY_RESULT_INCOMPLETE.getSchema());
assertEquals(0L, QUERY_RESULT_INCOMPLETE.getTotalRows());
assertEquals(TOTAL_BYTES_PROCESSED, QUERY_RESULT_INCOMPLETE.getTotalBytesProcessed());
assertEquals(false, QUERY_RESULT_INCOMPLETE.cacheHit());
assertEquals(null, QUERY_RESULT_INCOMPLETE.getNextPageCursor());
assertEquals(null, QUERY_RESULT_INCOMPLETE.getNextPageToken());
assertEquals(null, QUERY_RESULT_INCOMPLETE.getNextPage());
}

Expand All @@ -84,7 +84,7 @@ public void testEquals() {
private void compareQueryResult(QueryResult expected, QueryResult value) {
assertEquals(expected, value);
assertEquals(expected.getNextPage(), value.getNextPage());
assertEquals(expected.getNextPageCursor(), value.getNextPageCursor());
assertEquals(expected.getNextPageToken(), value.getNextPageToken());
assertEquals(expected.getValues(), value.getValues());
assertEquals(expected.getSchema(), value.getSchema());
assertEquals(expected.getTotalRows(), value.getTotalRows());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.PageImpl;
import com.google.cloud.bigquery.InsertAllRequest.RowToInsert;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.WaitForOption;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQuery.DatasetField;
Expand Down Expand Up @@ -249,7 +249,7 @@ public static void afterClass() throws ExecutionException, InterruptedException
@Test
public void testListDatasets() {
Page<Dataset> datasets = bigquery.listDatasets("bigquery-public-data");
Iterator<Dataset> iterator = datasets.iterateAll();
Iterator<Dataset> iterator = datasets.iterateAll().iterator();
Set<String> datasetNames = new HashSet<>();
while (iterator.hasNext()) {
datasetNames.add(iterator.next().getDatasetId().getDataset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.google.cloud.FieldSelector;
import com.google.cloud.FieldSelector.Helper;
import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.Service;
import com.google.cloud.compute.AttachedDisk.PersistentDiskConfiguration;
import com.google.cloud.compute.NetworkInterface.AccessConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static com.google.common.base.Preconditions.checkArgument;

import com.google.cloud.BaseService;
import com.google.cloud.Page;
import com.google.api.gax.core.Page;
import com.google.cloud.PageImpl;
import com.google.cloud.PageImpl.NextPageFetcher;
import com.google.cloud.RetryHelper;
Expand Down
Loading

0 comments on commit e11154e

Please sign in to comment.