2

Option 1:

TableResult results = bigquery.query(queryConfig);
while(results.hasNextPage()) {
        results = results.getNextPage();
        for (FieldValueList row : results.getNextPage().getValues()) {
            //Print row
        }
}

Option 2:

TableResult results = bigquery.query(queryConfig);
for (FieldValueList row : results.iterateAll()) {
     //Print row
}

Which is better. I am not seeing any difference in the time taken. Is there any advantage of getValues() over iterateAll() ?

1stenjoydmoment
  • 229
  • 3
  • 14

1 Answers1

1

Many APIs implement list operation or queries using pagination. In an implementation, you need to know how to fetch the data from the current page and the next pages.

For example if you have a query that returns 45 rows and you only need to display 10 rows per page, you need to use “getValues()”, this will return the first 10 rows and stop. With “iterateAll” will return an extra iterator that will affect the performance making additional calls to the API, returning the 45 rows.

In conclusion, if you want to return all rows from a query you can use iterateAll, but it will affect the performance by making additional calls to the API. If you want the results immediately from the current page, you can use getValues.

You can see these example snippets.

Tim
  • 2,563
  • 1
  • 23
  • 31
Eduardo Ortiz
  • 715
  • 3
  • 14