Skip to content

Commit

Permalink
Merge pull request #745 from mziccard/rename-max-results
Browse files Browse the repository at this point in the history
Rename maxResults to pageSize
  • Loading branch information
mderka committed Mar 14, 2016
2 parents ddd02aa + d97c188 commit 9e5c173
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion gcloud-java-bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Then add the following code to run the query and wait for the result:
QueryRequest queryRequest =
QueryRequest.builder("SELECT * FROM my_dataset_id.my_table_id")
.maxWaitTime(60000L)
.maxResults(1000L)
.pageSize(1000L)
.build();
// Request query to be executed and wait for results
QueryResponse queryResponse = bigquery.query(queryRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ private DatasetListOption(BigQueryRpc.Option option, Object value) {
}

/**
* Returns an option to specify the maximum number of datasets to be returned.
* Returns an option to specify the maximum number of datasets returned per page.
*/
public static DatasetListOption maxResults(long maxResults) {
return new DatasetListOption(BigQueryRpc.Option.MAX_RESULTS, maxResults);
public static DatasetListOption pageSize(long pageSize) {
return new DatasetListOption(BigQueryRpc.Option.MAX_RESULTS, pageSize);
}

/**
Expand Down Expand Up @@ -246,11 +246,11 @@ private TableListOption(BigQueryRpc.Option option, Object value) {
}

/**
* Returns an option to specify the maximum number of tables to be returned.
* Returns an option to specify the maximum number of tables returned per page.
*/
public static TableListOption maxResults(long maxResults) {
checkArgument(maxResults >= 0);
return new TableListOption(BigQueryRpc.Option.MAX_RESULTS, maxResults);
public static TableListOption pageSize(long pageSize) {
checkArgument(pageSize >= 0);
return new TableListOption(BigQueryRpc.Option.MAX_RESULTS, pageSize);
}

/**
Expand Down Expand Up @@ -295,11 +295,11 @@ private TableDataListOption(BigQueryRpc.Option option, Object value) {
}

/**
* Returns an option to specify the maximum number of rows to be returned.
* Returns an option to specify the maximum number of rows returned per page.
*/
public static TableDataListOption maxResults(long maxResults) {
checkArgument(maxResults >= 0);
return new TableDataListOption(BigQueryRpc.Option.MAX_RESULTS, maxResults);
public static TableDataListOption pageSize(long pageSize) {
checkArgument(pageSize >= 0);
return new TableDataListOption(BigQueryRpc.Option.MAX_RESULTS, pageSize);
}

/**
Expand Down Expand Up @@ -352,11 +352,11 @@ public String apply(JobStatus.State state) {
}

/**
* Returns an option to specify the maximum number of jobs to be returned.
* Returns an option to specify the maximum number of jobs returned per page.
*/
public static JobListOption maxResults(long maxResults) {
checkArgument(maxResults >= 0);
return new JobListOption(BigQueryRpc.Option.MAX_RESULTS, maxResults);
public static JobListOption pageSize(long pageSize) {
checkArgument(pageSize >= 0);
return new JobListOption(BigQueryRpc.Option.MAX_RESULTS, pageSize);
}

/**
Expand Down Expand Up @@ -418,11 +418,11 @@ private QueryResultsOption(BigQueryRpc.Option option, Object value) {
}

/**
* Returns an option to specify the maximum number of rows to be returned.
* Returns an option to specify the maximum number of rows returned per page.
*/
public static QueryResultsOption maxResults(long maxResults) {
checkArgument(maxResults >= 0);
return new QueryResultsOption(BigQueryRpc.Option.MAX_RESULTS, maxResults);
public static QueryResultsOption pageSize(long pageSize) {
checkArgument(pageSize >= 0);
return new QueryResultsOption(BigQueryRpc.Option.MAX_RESULTS, pageSize);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* QueryRequest request = QueryRequest.builder("SELECT field FROM table")
* .defaultDataset(DatasetId.of("dataset"))
* .maxWaitTime(60000L)
* .maxResults(1000L)
* .pageSize(1000L)
* .build();
* QueryResponse response = bigquery.query(request);
* while (!response.jobCompleted()) {
Expand All @@ -65,7 +65,7 @@ public class QueryRequest implements Serializable {
private static final long serialVersionUID = -8727328332415880852L;

private final String query;
private final Long maxResults;
private final Long pageSize;
private final DatasetId defaultDataset;
private final Long maxWaitTime;
private final Boolean dryRun;
Expand All @@ -74,7 +74,7 @@ public class QueryRequest implements Serializable {
public static final class Builder {

private String query;
private Long maxResults;
private Long pageSize;
private DatasetId defaultDataset;
private Long maxWaitTime;
private Boolean dryRun;
Expand All @@ -96,8 +96,8 @@ public Builder query(String query) {
* query result set is large. In addition to this limit, responses are also limited to 10 MB.
* By default, there is no maximum row count, and only the byte limit applies.
*/
public Builder maxResults(Long maxResults) {
this.maxResults = maxResults;
public Builder pageSize(Long pageSize) {
this.pageSize = pageSize;
return this;
}

Expand Down Expand Up @@ -157,7 +157,7 @@ public QueryRequest build() {

private QueryRequest(Builder builder) {
query = builder.query;
maxResults = builder.maxResults;
pageSize = builder.pageSize;
defaultDataset = builder.defaultDataset;
maxWaitTime = builder.maxWaitTime;
dryRun = builder.dryRun;
Expand All @@ -174,8 +174,8 @@ public String query() {
/**
* Returns the maximum number of rows of data to return per page of results.
*/
public Long maxResults() {
return maxResults;
public Long pageSize() {
return pageSize;
}

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ public Boolean useQueryCache() {
public Builder toBuilder() {
return new Builder()
.query(query)
.maxResults(maxResults)
.pageSize(pageSize)
.defaultDataset(defaultDataset)
.maxWaitTime(maxWaitTime)
.dryRun(dryRun)
Expand All @@ -235,7 +235,7 @@ public Builder toBuilder() {
public String toString() {
return MoreObjects.toStringHelper(this)
.add("query", query)
.add("maxResults", maxResults)
.add("pageSize", pageSize)
.add("defaultDataset", defaultDataset)
.add("maxWaitTime", maxWaitTime)
.add("dryRun", dryRun)
Expand All @@ -245,7 +245,7 @@ public String toString() {

@Override
public int hashCode() {
return Objects.hash(query, maxResults, defaultDataset, maxWaitTime, dryRun, useQueryCache);
return Objects.hash(query, pageSize, defaultDataset, maxWaitTime, dryRun, useQueryCache);
}

@Override
Expand All @@ -264,8 +264,8 @@ QueryRequest setProjectId(String projectId) {
com.google.api.services.bigquery.model.QueryRequest toPb() {
com.google.api.services.bigquery.model.QueryRequest queryRequestPb =
new com.google.api.services.bigquery.model.QueryRequest().setQuery(query);
if (maxResults != null) {
queryRequestPb.setMaxResults(maxResults);
if (pageSize != null) {
queryRequestPb.setMaxResults(pageSize);
}
if (defaultDataset != null) {
queryRequestPb.setDefaultDataset(defaultDataset.toPb());
Expand Down Expand Up @@ -299,7 +299,7 @@ public static QueryRequest of(String query) {
static QueryRequest fromPb(com.google.api.services.bigquery.model.QueryRequest queryRequestPb) {
Builder builder = builder(queryRequestPb.getQuery());
if (queryRequestPb.getMaxResults() != null) {
builder.maxResults(queryRequestPb.getMaxResults());
builder.pageSize(queryRequestPb.getMaxResults());
}
if (queryRequestPb.getDefaultDataset() != null) {
builder.defaultDataset(DatasetId.fromPb(queryRequestPb.getDefaultDataset()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ public class BigQueryImplTest {
private static final TableRow TABLE_ROW =
new TableRow().setF(ImmutableList.of(BOOLEAN_FIELD, INTEGER_FIELD));
private static final QueryRequest QUERY_REQUEST = QueryRequest.builder("SQL")
.maxResults(42L)
.pageSize(42L)
.useQueryCache(false)
.defaultDataset(DatasetId.of(DATASET))
.build();
private static final QueryRequest QUERY_REQUEST_WITH_PROJECT = QueryRequest.builder("SQL")
.maxResults(42L)
.pageSize(42L)
.useQueryCache(false)
.defaultDataset(DatasetId.of(PROJECT, DATASET))
.build();
Expand All @@ -170,8 +170,8 @@ public class BigQueryImplTest {
BigQuery.DatasetListOption.all();
private static final BigQuery.DatasetListOption DATASET_LIST_PAGE_TOKEN =
BigQuery.DatasetListOption.startPageToken("cursor");
private static final BigQuery.DatasetListOption DATASET_LIST_MAX_RESULTS =
BigQuery.DatasetListOption.maxResults(42L);
private static final BigQuery.DatasetListOption DATASET_LIST_PAGE_SIZE =
BigQuery.DatasetListOption.pageSize(42L);
private static final Map<BigQueryRpc.Option, ?> DATASET_LIST_OPTIONS = ImmutableMap.of(
BigQueryRpc.Option.ALL_DATASETS, true,
BigQueryRpc.Option.PAGE_TOKEN, "cursor",
Expand All @@ -188,17 +188,17 @@ public class BigQueryImplTest {
BigQuery.TableOption.fields(BigQuery.TableField.SCHEMA, BigQuery.TableField.ETAG);

// Table list options
private static final BigQuery.TableListOption TABLE_LIST_MAX_RESULTS =
BigQuery.TableListOption.maxResults(42L);
private static final BigQuery.TableListOption TABLE_LIST_PAGE_SIZE =
BigQuery.TableListOption.pageSize(42L);
private static final BigQuery.TableListOption TABLE_LIST_PAGE_TOKEN =
BigQuery.TableListOption.startPageToken("cursor");
private static final Map<BigQueryRpc.Option, ?> TABLE_LIST_OPTIONS = ImmutableMap.of(
BigQueryRpc.Option.MAX_RESULTS, 42L,
BigQueryRpc.Option.PAGE_TOKEN, "cursor");

// TableData list options
private static final BigQuery.TableDataListOption TABLE_DATA_LIST_MAX_RESULTS =
BigQuery.TableDataListOption.maxResults(42L);
private static final BigQuery.TableDataListOption TABLE_DATA_LIST_PAGE_SIZE =
BigQuery.TableDataListOption.pageSize(42L);
private static final BigQuery.TableDataListOption TABLE_DATA_LIST_PAGE_TOKEN =
BigQuery.TableDataListOption.startPageToken("cursor");
private static final BigQuery.TableDataListOption TABLE_DATA_LIST_START_INDEX =
Expand All @@ -221,8 +221,8 @@ public class BigQueryImplTest {
BigQuery.JobListOption.stateFilter(JobStatus.State.DONE, JobStatus.State.PENDING);
private static final BigQuery.JobListOption JOB_LIST_PAGE_TOKEN =
BigQuery.JobListOption.startPageToken("cursor");
private static final BigQuery.JobListOption JOB_LIST_MAX_RESULTS =
BigQuery.JobListOption.maxResults(42L);
private static final BigQuery.JobListOption JOB_LIST_PAGE_SIZE =
BigQuery.JobListOption.pageSize(42L);
private static final Map<BigQueryRpc.Option, ?> JOB_LIST_OPTIONS = ImmutableMap.of(
BigQueryRpc.Option.ALL_USERS, true,
BigQueryRpc.Option.STATE_FILTER, ImmutableList.of("done", "pending"),
Expand All @@ -236,8 +236,8 @@ public class BigQueryImplTest {
BigQuery.QueryResultsOption.startIndex(1024L);
private static final BigQuery.QueryResultsOption QUERY_RESULTS_OPTION_PAGE_TOKEN =
BigQuery.QueryResultsOption.startPageToken("cursor");
private static final BigQuery.QueryResultsOption QUERY_RESULTS_OPTION_MAX_RESULTS =
BigQuery.QueryResultsOption.maxResults(0L);
private static final BigQuery.QueryResultsOption QUERY_RESULTS_OPTION_PAGE_SIZE =
BigQuery.QueryResultsOption.pageSize(0L);
private static final Map<BigQueryRpc.Option, ?> QUERY_RESULTS_OPTIONS = ImmutableMap.of(
BigQueryRpc.Option.TIMEOUT, 42L,
BigQueryRpc.Option.START_INDEX, 1024L,
Expand Down Expand Up @@ -388,7 +388,7 @@ public void testListDatasetsWithOptions() {
EasyMock.expect(bigqueryRpcMock.listDatasets(DATASET_LIST_OPTIONS)).andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Dataset> page = bigquery.listDatasets(DATASET_LIST_ALL, DATASET_LIST_PAGE_TOKEN,
DATASET_LIST_MAX_RESULTS);
DATASET_LIST_PAGE_SIZE);
assertEquals(cursor, page.nextPageCursor());
assertArrayEquals(datasetList.toArray(), Iterables.toArray(page.values(), DatasetInfo.class));
}
Expand Down Expand Up @@ -560,7 +560,7 @@ public void testListTablesWithOptions() {
Tuple.of(cursor, Iterables.transform(tableList, TableInfo.TO_PB_FUNCTION));
EasyMock.expect(bigqueryRpcMock.listTables(DATASET, TABLE_LIST_OPTIONS)).andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Table> page = bigquery.listTables(DATASET, TABLE_LIST_MAX_RESULTS, TABLE_LIST_PAGE_TOKEN);
Page<Table> page = bigquery.listTables(DATASET, TABLE_LIST_PAGE_SIZE, TABLE_LIST_PAGE_TOKEN);
assertEquals(cursor, page.nextPageCursor());
assertArrayEquals(tableList.toArray(), Iterables.toArray(page.values(), Table.class));
}
Expand Down Expand Up @@ -733,7 +733,7 @@ public void testListTableDataWithOptions() {
EasyMock.replay(bigqueryRpcMock);
bigquery = options.service();
Page<List<FieldValue>> page = bigquery.listTableData(DATASET, TABLE,
TABLE_DATA_LIST_MAX_RESULTS, TABLE_DATA_LIST_PAGE_TOKEN, TABLE_DATA_LIST_START_INDEX);
TABLE_DATA_LIST_PAGE_SIZE, TABLE_DATA_LIST_PAGE_TOKEN, TABLE_DATA_LIST_START_INDEX);
assertEquals(cursor, page.nextPageCursor());
assertArrayEquals(tableData.toArray(), Iterables.toArray(page.values(), List.class));
}
Expand Down Expand Up @@ -859,7 +859,7 @@ public com.google.api.services.bigquery.model.Job apply(Job job) {
EasyMock.expect(bigqueryRpcMock.listJobs(JOB_LIST_OPTIONS)).andReturn(result);
EasyMock.replay(bigqueryRpcMock);
Page<Job> page = bigquery.listJobs(JOB_LIST_ALL_USERS, JOB_LIST_STATE_FILTER,
JOB_LIST_PAGE_TOKEN, JOB_LIST_MAX_RESULTS);
JOB_LIST_PAGE_TOKEN, JOB_LIST_PAGE_SIZE);
assertEquals(cursor, page.nextPageCursor());
assertArrayEquals(jobList.toArray(), Iterables.toArray(page.values(), Job.class));
}
Expand Down Expand Up @@ -1012,7 +1012,7 @@ public void testGetQueryResultsWithOptions() {
EasyMock.replay(bigqueryRpcMock);
bigquery = options.service();
QueryResponse response = bigquery.getQueryResults(queryJob, QUERY_RESULTS_OPTION_TIME,
QUERY_RESULTS_OPTION_INDEX, QUERY_RESULTS_OPTION_MAX_RESULTS,
QUERY_RESULTS_OPTION_INDEX, QUERY_RESULTS_OPTION_PAGE_SIZE,
QUERY_RESULTS_OPTION_PAGE_TOKEN);
assertEquals(queryJob, response.jobId());
assertEquals(true, response.jobCompleted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ public void testListWithOptions() throws Exception {
new Table(serviceMockReturnsOptions, new Table.BuilderImpl(TABLE_INFO3)));
PageImpl<Table> expectedPage = new PageImpl<>(null, "c", tableResults);
expect(bigquery.options()).andReturn(mockOptions);
expect(bigquery.listTables(DATASET_INFO.datasetId(), BigQuery.TableListOption.maxResults(10L)))
expect(bigquery.listTables(DATASET_INFO.datasetId(), BigQuery.TableListOption.pageSize(10L)))
.andReturn(expectedPage);
replay(bigquery);
initializeDataset();
Page<Table> tablePage = dataset.list(BigQuery.TableListOption.maxResults(10L));
Page<Table> tablePage = dataset.list(BigQuery.TableListOption.pageSize(10L));
assertArrayEquals(tableResults.toArray(), Iterables.toArray(tablePage.values(), Table.class));
assertEquals(expectedPage.nextPageCursor(), tablePage.nextPageCursor());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class QueryRequestTest {
private static final DatasetId DATASET_ID = DatasetId.of("dataset");
private static final Boolean USE_QUERY_CACHE = true;
private static final Boolean DRY_RUN = false;
private static final Long MAX_RESULTS = 42L;
private static final Long PAGE_SIZE = 42L;
private static final Long MAX_WAIT_TIME = 42000L;
private static final QueryRequest QUERY_REQUEST = QueryRequest.builder(QUERY)
.useQueryCache(USE_QUERY_CACHE)
.defaultDataset(DATASET_ID)
.dryRun(DRY_RUN)
.maxResults(MAX_RESULTS)
.pageSize(PAGE_SIZE)
.maxWaitTime(MAX_WAIT_TIME)
.build();

Expand Down Expand Up @@ -65,7 +65,7 @@ public void testBuilder() {
assertEquals(USE_QUERY_CACHE, QUERY_REQUEST.useQueryCache());
assertEquals(DATASET_ID, QUERY_REQUEST.defaultDataset());
assertEquals(DRY_RUN, QUERY_REQUEST.dryRun());
assertEquals(MAX_RESULTS, QUERY_REQUEST.maxResults());
assertEquals(PAGE_SIZE, QUERY_REQUEST.pageSize());
assertEquals(MAX_WAIT_TIME, QUERY_REQUEST.maxWaitTime());
thrown.expect(NullPointerException.class);
QueryRequest.builder(null);
Expand All @@ -78,7 +78,7 @@ public void testOf() {
assertNull(request.useQueryCache());
assertNull(request.defaultDataset());
assertNull(request.dryRun());
assertNull(request.maxResults());
assertNull(request.pageSize());
assertNull(request.maxWaitTime());
thrown.expect(NullPointerException.class);
QueryRequest.of(null);
Expand All @@ -102,7 +102,7 @@ private void compareQueryRequest(QueryRequest expected, QueryRequest value) {
assertEquals(expected.useQueryCache(), value.useQueryCache());
assertEquals(expected.defaultDataset(), value.defaultDataset());
assertEquals(expected.dryRun(), value.dryRun());
assertEquals(expected.maxResults(), value.maxResults());
assertEquals(expected.pageSize(), value.pageSize());
assertEquals(expected.maxWaitTime(), value.maxWaitTime());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public class SerializationTest {
.useQueryCache(true)
.defaultDataset(DATASET_ID)
.dryRun(false)
.maxResults(42L)
.pageSize(42L)
.maxWaitTime(10L)
.build();
private static final QueryResult QUERY_RESULT = QueryResult.builder()
Expand Down Expand Up @@ -261,7 +261,7 @@ public void testModelAndRequests() throws Exception {
INSERT_ALL_RESPONSE, FIELD_VALUE, QUERY_REQUEST, QUERY_RESPONSE,
BigQuery.DatasetOption.fields(), BigQuery.DatasetDeleteOption.deleteContents(),
BigQuery.DatasetListOption.all(), BigQuery.TableOption.fields(),
BigQuery.TableListOption.maxResults(42L), BigQuery.JobOption.fields(),
BigQuery.TableListOption.pageSize(42L), BigQuery.JobOption.fields(),
BigQuery.JobListOption.allUsers(), DATASET, TABLE, JOB};
for (Serializable obj : objects) {
Object copy = serializeAndDeserialize(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ public void testListWithOptions() throws Exception {
initializeExpectedTable(1);
expect(bigquery.options()).andReturn(mockOptions);
PageImpl<List<FieldValue>> tableDataPage = new PageImpl<>(null, "c", ROWS);
expect(bigquery.listTableData(TABLE_ID1, BigQuery.TableDataListOption.maxResults(10L)))
expect(bigquery.listTableData(TABLE_ID1, BigQuery.TableDataListOption.pageSize(10L)))
.andReturn(tableDataPage);
replay(bigquery);
initializeTable();
Page<List<FieldValue>> dataPage = table.list(BigQuery.TableDataListOption.maxResults(10L));
Page<List<FieldValue>> dataPage = table.list(BigQuery.TableDataListOption.pageSize(10L));
Iterator<List<FieldValue>> tableDataIterator = tableDataPage.values().iterator();
Iterator<List<FieldValue>> dataIterator = dataPage.values().iterator();
assertTrue(Iterators.elementsEqual(tableDataIterator, dataIterator));
Expand Down
Loading

0 comments on commit 9e5c173

Please sign in to comment.